Skip to content

Commit

Permalink
[api] Introduce attrib type pundit policy
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Schnitzer committed Mar 8, 2017
1 parent 2958d80 commit 64b5a04
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/api/app/policies/attrib_type_policy.rb
@@ -0,0 +1,27 @@
class AttribTypePolicy < ApplicationPolicy
def create?
@user.is_admin? || access_to_type? || access_to_namespace?
end

def update?
create?
end

def destroy?
create?
end

private

def access_to_type?
@record.attrib_type_modifiable_bies.any? do |rule|
rule.user == @user || @user.is_in_group?(rule.group)
end
end

def access_to_namespace?
@record.attrib_namespace.attrib_namespace_modifiable_bies.any? do |rule|
rule.user == @user || @user.is_in_group?(rule.group)
end
end
end

0 comments on commit 64b5a04

Please sign in to comment.