Commit 1f4a2130 authored by hellekin's avatar hellekin

Add auhtorization policies (refs #7)

parent 3a7ea8ff
# frozen_string_literal: true
class AddressPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
end
# frozen_string_literal: true
class CategoryPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
end
# frozen_string_literal: true
class EmailPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
end
# frozen_string_literal: true
class LinkPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
end
# frozen_string_literal: true
class LocationPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
end
# frozen_string_literal: true
class NilClassPolicy < ApplicationPolicy
class Scope < Scope
def resolve
raise Pundit::NotDefinedError, 'Cannot scope NilClass'
end
end
def show?
true # false # Nobody can see nothing
end
end
# frozen_string_literal: true
class PhonePolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
end
# frozen_string_literal: true
class ResourceAddressPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
end
# frozen_string_literal: true
class ResourceCollectionPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
end
# frozen_string_literal: true
class ResourceEmailPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
end
# frozen_string_literal: true
class ResourceLinkPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
end
# frozen_string_literal: true
class ResourcePhonePolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
end
......@@ -2,7 +2,7 @@
class ResourcePolicy < ApplicationPolicy
def index?
record_public?
true
end
def show?
......@@ -23,7 +23,11 @@ class ResourcePolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
if user.authenticated? == true
scope.where(agent_id: user.uuid).or(scope.where(public: true))
else
scope.where(public: true)
end
end
end
end
# frozen_string_literal: true
class RolePolicy < ApplicationPolicy
def index?
user&.leader?
end
def show?
user&.leader? || @record.user == user&.user
end
def create?
false
end
def update?
false
end
def destroy?
false
end
class Scope < Scope
def resolve
if user&.leader? == true
if user&.is_incommon? == true
scope.all
else
scope.where(agent_id: user.uuid)
end
else
scope.where(user_id: user.user.uuid)
end
scope.all
end
end
end
# frozen_string_literal: true
class SectionPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
end
# frozen_string_literal: true
class TaxonomyPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
end
# frozen_string_literal: true
class UserEmailPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment