apply pundit for stories

This commit is contained in:
2023-01-15 22:00:26 +02:00
parent b8e14fe6b5
commit 459cea35e1
9 changed files with 75 additions and 4 deletions

View File

@ -0,0 +1,53 @@
# frozen_string_literal: true
class ApplicationPolicy
attr_reader :member, :record
def initialize(member, record)
@member = member
@record = record
end
def index?
false
end
def show?
false
end
def create?
false
end
def new?
create?
end
def update?
false
end
def edit?
update?
end
def destroy?
false
end
class Scope
def initialize(member, scope)
@member = member
@scope = scope
end
def resolve
raise NotImplementedError, "You must define #resolve in #{self.class}"
end
private
attr_reader :member, :scope
end
end

View File

@ -0,0 +1,9 @@
class StoryPolicy < ApplicationPolicy
def edit?
(member == record.member) or member.admin?
end
alias :update? :edit?
alias :destroy? :edit?
end