Skip to content
Snippets Groups Projects
Commit 75373932 authored by Giovanne Marcelo's avatar Giovanne Marcelo
Browse files

Adding institutions, complaints and users policies

parent 422f608f
No related branches found
No related tags found
No related merge requests found
class ComplaintsController < ApplicationController
include Pundit
before_action :authorize_action
before_action :authenticate_user!
def create
......@@ -20,4 +23,10 @@ class ComplaintsController < ApplicationController
def complaint_params
params.require(:complaint).permit(:complaintable_id, :complaintable_type, :complaint_reason_id, :description)
end
def authorize_action
@complaint ||= Complaint.new(complaint_params)
authorize @complaint
end
end
class InstitutionsController < ApplicationController
include Pundit
before_action :set_institution, only: [:show, :edit, :update, :destroy, :like, :users]
before_action :authorize_action
# GET /institutions
# GET /institutions.json
......@@ -72,4 +75,9 @@ class InstitutionsController < ApplicationController
params[:institution_object]
end
def authorize_action
@institution ||= Institution.new
authorize @institution
end
end
class ReviewsController < ApplicationController
include Pundit
before_action :authenticate_user!, except: [:show, :list]
before_action :set_review, only: [:show, :destroy]
before_action :authorize_action
def list
if !params[:learning_object_id].blank?
......@@ -81,4 +85,10 @@ class ReviewsController < ApplicationController
when 'false' then false
end
end
def authorize_action
@review||= Review.new
authorize @review
end
end
......@@ -35,5 +35,4 @@ class CollectionPolicy < ApplicationPolicy
def owner
record.owner
end
end
class ComplaintPolicy < ApplicationPolicy
def create?
record if user_exists?
end
end
class InstitutionPolicy < ApplicationPolicy
def create?
record if user.is_admin?
end
def update?
record if user.is_admin?
end
def index?
record if user.is_admin?
end
def destroy?
record if user.is_admin?
end
end
class ReviewPolicy < ApplicationPolicy
def create?
record if user_exists?
end
def update?
record if owns?
end
def destroy?
record if owns?
end
def rate?
record if user_exists?
end
def owner
record.users
end
end
class UserPolicy < ApplicationPolicy
def show?
record if user_exists?
end
def list?
record
end
def follow?
record if user_exists?
end
def unfollow?
record if user_exists?
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment