Skip to content

Commit

Permalink
Policy updates
Browse files Browse the repository at this point in the history
  • Loading branch information
zwolf committed Nov 29, 2023
1 parent 1a7ef04 commit 2dccd27
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
4 changes: 4 additions & 0 deletions app/policies/application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def has_role?(role)
true
end

def confirmed?
!!user.confirmed_at
end

def of_posting_age?
return true unless ENV['POSTING_AGE_REQUIREMENT']

Expand Down
8 changes: 4 additions & 4 deletions app/policies/comment_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ def show?

def create?
if Array.wrap(record).compact.any? { |c| c.discussion.board.section == 'zooniverse' }
logged_in? && !locked? && writable? && of_posting_age?
logged_in? && !locked? && writable? && confirmed? && of_posting_age?
else
logged_in? && !locked? && writable?
logged_in? && !locked? && writable? && confirmed?
end
end

def update?
owner? && !deleted? && !locked? && writable?
owner? && !deleted? && !locked? && writable? && confirmed?
end

def destroy?
owner? && !deleted? && !locked? && writable?
owner? && !deleted? && !locked? && writable? && confirmed?
end

def move?
Expand Down
8 changes: 4 additions & 4 deletions app/policies/conversation_policy.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
class ConversationPolicy < ApplicationPolicy
def index?
logged_in?
logged_in? && confirmed?
end

def show?
moderator? || admin? || participant?
(moderator? || admin? || participant?) && confirmed?
end

def create?
logged_in?
logged_in? && confirmed?
end

def update?
false
end

def destroy?
participant?
participant? && confirmed?
end

class Scope < Scope
Expand Down
4 changes: 2 additions & 2 deletions app/policies/discussion_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def show?

def create?
if Array.wrap(record).compact.any? { |d| d.board.section == 'zooniverse' }
writable? && of_posting_age?
writable? && confirmed? && of_posting_age?
else
writable?
writable? && confirmed?
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/policies/message_policy.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class MessagePolicy < ApplicationPolicy
def index?
logged_in?
logged_in? && confirmed?
end

def show?
moderator? || admin? || participant?
(moderator? || admin? || participant?) && confirmed?
end

def create?
participant?
participant? && confirmed?
end

def update?
Expand Down

0 comments on commit 2dccd27

Please sign in to comment.