Skip to content

Commit

Permalink
FIX: relies only on staff? and prefer defined? for memoization
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaffeux committed Apr 14, 2020
1 parent 2fd93fb commit 4e7c798
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,18 @@ def valid_event
end

add_to_class(:user, :can_create_event?) do
@can_create_event ||=
begin
return true if admin? || staff?
allowed_groups = SiteSetting.discourse_post_event_allowed_on_groups.split('|').compact
allowed_groups.present? && groups.where(id: allowed_groups).exists? ?
:true : :false
end
@can_create_event == :true
return @can_create_event if defined?(@can_create_event)
@can_create_event = begin
return true if staff?
allowed_groups = SiteSetting.discourse_post_event_allowed_on_groups.split('|').compact
allowed_groups.present? && groups.where(id: allowed_groups).exists?
rescue
false
end
end

add_to_class(:guardian, :can_act_on_invitee?) do |invitee|
user && (user.staff? || user.admin? || user.id == invitee.user_id)
user && (user.staff? || user.id == invitee.user_id)
end

add_to_class(:guardian, :can_create_event?) { user && user.can_create_event? }
Expand All @@ -148,12 +148,13 @@ def valid_event
end

add_to_class(:user, :can_act_on_event?) do |event|
@can_act_on_event ||=
begin
return true if admin? || staff?
can_create_event? && event.post.user_id == id ? :true : :false
end
@can_act_on_event == :true
return @can_act_on_event if defined?(@can_act_on_event)
@can_act_on_event = begin
return true if admin?
can_create_event? && event.post.user_id == id
rescue
false
end
end

add_to_class(:guardian, :can_act_on_event?) { |event| user && user.can_act_on_event?(event) }
Expand Down

0 comments on commit 4e7c798

Please sign in to comment.