Module: PunditOverwrite
- Includes:
- PunditAssociations, PunditSelectors
- Included in:
- Pundit
- Defined in:
- lib/pundit_roles/pundit.rb
Overview
Contains the overwritten #authorize method
Instance Method Summary collapse
-
#authorize!(resource, opts = {query: nil, associations: []}) ⇒ Object, Hash
A modified version of Pundit’s default authorization.
-
#policy_scope!(resource, opts = {query: nil, associations: []}) ⇒ Object, ActiveRecord::Association
Returns the permitted scope or raises exception.
- #raise_not_authorized(record) ⇒ Object
Methods included from PunditSelectors
#association_create_associations, #association_create_attributes, #association_permissions, #association_show_associations, #association_show_attributes, #association_update_associations, #association_update_attributes, #attribute_permissions, #permissions, #permitted_associations, #permitted_create_associations, #permitted_create_attributes, #permitted_show_associations, #permitted_show_attributes, #permitted_update_associations, #permitted_update_attributes, #primary_create_associations, #primary_create_attributes, #primary_show_associations, #primary_show_attributes, #primary_update_associations, #primary_update_attributes
Methods included from PunditAssociations
Instance Method Details
#authorize!(resource, opts = {query: nil, associations: []}) ⇒ Object, Hash
A modified version of Pundit’s default authorization. Returns a hash of permitted attributes or raises exception it the user is not authorized
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pundit_roles/pundit.rb', line 19 def (resource, opts = {query: nil, associations: []}) opts[:query] ||= params[:action].to_s + '?' @_pundit_policy_authorized = true @pundit_current_options = { primary_resource: resource.is_a?(Class) ? resource : resource.class, current_query: opts[:query] } policy = policy(resource) = policy.resolve_query(opts[:query]) unless (resource) end if .is_a? TrueClass return resource end @pundit_primary_permissions = primary_resource_identifier = @pundit_current_options[:primary_resource].name.underscore.to_sym @pundit_attribute_lists = { show: {primary_resource_identifier => primary_show_attributes}, create: [*primary_create_attributes], update: [*primary_update_attributes] } @pundit_permission_table = {} @pundit_permitted_associations = {show: [], create: [], update: []} if opts[:associations].present? (opts) end return @pundit_primary_permissions end |
#policy_scope!(resource, opts = {query: nil, associations: []}) ⇒ Object, ActiveRecord::Association
Returns the permitted scope or raises exception
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/pundit_roles/pundit.rb', line 67 def policy_scope!(resource, opts= {query: nil, associations: []}) opts[:query] ||= params[:action].to_s + '?' @_pundit_policy_scoped = true @pundit_current_options = { primary_resource: resource.is_a?(Class) ? resource : resource.class, current_query: opts[:query] } policy = policy(resource) permitted_scope = policy.resolve_scope(opts[:query]) unless permitted_scope (resource) end if permitted_scope.is_a? TrueClass return resource end return permitted_scope end |
#raise_not_authorized(record) ⇒ Object
91 92 93 94 95 |
# File 'lib/pundit_roles/pundit.rb', line 91 def (record) raise Pundit::NotAuthorizedError, query: @pundit_current_options[:current_query], record: record end |