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