Skip to content
Snippets Groups Projects
Commit 4e777262 authored by Marcela Ribeiro de Oliveira's avatar Marcela Ribeiro de Oliveira
Browse files

add policy_scope in contacts index

parent 6869ac12
No related branches found
No related tags found
No related merge requests found
......@@ -22,13 +22,13 @@ class V1::ContactsController < ApplicationController
before_action :authenticate_user!, except: [:create]
before_action :set_contact, only: [:show, :update, :destroy]
before_action :authorize!, except: [:index, :create]
before_action :set_new_contact, only: :index
before_action :authorize!, except: [:create]
# GET v1/contacts
def index
authorize :contact, :index?
contacts = paginate Contact
render json: contacts
contacts = paginate policy_scope(Contact)
render json: contacts
end
# GET v1/contacts/1
......@@ -78,4 +78,8 @@ class V1::ContactsController < ApplicationController
def authorize!
authorize @contact
end
def set_new_contact
@contact ||= Contact.new
end
end
......@@ -18,6 +18,14 @@
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
class ContactPolicy < ApplicationPolicy
class Scope < Scope
def resolve
if user_can_edit?
scope.all
end
end
end
def index?
record if user_can_edit?
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