FIX: relies only on staff? and prefer defined? for memoization

This commit is contained in:
jjaffeux 2020-04-14 15:39:49 +02:00
parent 2fd93fb355
commit 4e7c798971
1 changed files with 16 additions and 15 deletions

View File

@ -127,18 +127,18 @@ after_initialize do
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? }
@ -148,12 +148,13 @@ after_initialize do
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) }