FIX: prevents name collision by namespacing guardian method
This commit is contained in:
parent
4e7c798971
commit
cc193bf2ba
|
@ -24,7 +24,7 @@ module DiscoursePostEvent
|
|||
|
||||
def invite
|
||||
event = Event.find(params[:id])
|
||||
guardian.ensure_can_act_on_event!(event)
|
||||
guardian.ensure_can_act_on_discourse_post_event!(event)
|
||||
invites = Array(params.permit(invites: [])[:invites])
|
||||
users = Invitee.extract_uniq_usernames(invites)
|
||||
|
||||
|
@ -44,7 +44,7 @@ module DiscoursePostEvent
|
|||
|
||||
def destroy
|
||||
event = Event.find(params[:id])
|
||||
guardian.ensure_can_act_on_event!(event)
|
||||
guardian.ensure_can_act_on_discourse_post_event!(event)
|
||||
event.publish_update!
|
||||
event.destroy
|
||||
render json: success_json
|
||||
|
@ -54,7 +54,7 @@ module DiscoursePostEvent
|
|||
DistributedMutex.synchronize("discourse-post-event[event-update]") do
|
||||
event = Event.find(params[:id])
|
||||
guardian.ensure_can_edit!(event.post)
|
||||
guardian.ensure_can_act_on_event!(event)
|
||||
guardian.ensure_can_act_on_discourse_post_event!(event)
|
||||
event.update_with_params!(event_params)
|
||||
serializer = EventSerializer.new(event, scope: guardian)
|
||||
render_json_dump(serializer)
|
||||
|
@ -64,7 +64,7 @@ module DiscoursePostEvent
|
|||
def create
|
||||
event = Event.new(event_params)
|
||||
guardian.ensure_can_edit!(event.post)
|
||||
guardian.ensure_can_create_event!
|
||||
guardian.ensure_can_create_discourse_post_event!
|
||||
event.enforce_utc!(event_params)
|
||||
|
||||
case event_params[:status].to_i
|
||||
|
|
|
@ -32,7 +32,7 @@ module DiscoursePostEvent
|
|||
def create
|
||||
status = Invitee.statuses[invitee_params[:status].to_sym]
|
||||
event = Event.find(invitee_params[:post_id])
|
||||
guardian.ensure_can_act_on_event!(event)
|
||||
guardian.ensure_can_act_on_discourse_post_event!(event)
|
||||
invitee = Invitee.create!(
|
||||
status: status,
|
||||
post_id: invitee_params[:post_id],
|
||||
|
|
|
@ -13,13 +13,13 @@ module DiscoursePostEvent
|
|||
attributes :raw_invitees
|
||||
attributes :post
|
||||
attributes :name
|
||||
attributes :can_act_on_event
|
||||
attributes :can_act_on_discourse_post_event
|
||||
attributes :can_update_attendance
|
||||
attributes :is_expired
|
||||
attributes :should_display_invitees
|
||||
|
||||
def can_act_on_event
|
||||
scope.can_act_on_event?(object)
|
||||
def can_act_on_discourse_post_event
|
||||
scope.can_act_on_discourse_post_event?(object)
|
||||
end
|
||||
|
||||
def is_expired
|
||||
|
|
|
@ -150,7 +150,7 @@ export default createWidget("discourse-post-event", {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{{#if state.eventModel.can_act_on_event}}
|
||||
{{#if state.eventModel.can_act_on_discourse_post_event}}
|
||||
<div class="actions">
|
||||
{{attach
|
||||
widget="button"
|
||||
|
@ -204,7 +204,7 @@ export default createWidget("discourse-post-event", {
|
|||
}}
|
||||
|
||||
{{#unless state.eventModel.is_expired}}
|
||||
{{#if state.eventModel.can_act_on_event}}
|
||||
{{#if state.eventModel.can_act_on_discourse_post_event}}
|
||||
{{#if transformed.isPublicEvent}}
|
||||
{{attach
|
||||
widget="button"
|
||||
|
|
|
@ -7,7 +7,7 @@ function initializeEventBuilder(api) {
|
|||
api.onToolbarCreate(toolbar => {
|
||||
if (
|
||||
!currentUser ||
|
||||
!currentUser.can_create_event ||
|
||||
!currentUser.can_create_discourse_post_event ||
|
||||
!toolbar.context.outletArgs
|
||||
) {
|
||||
return;
|
||||
|
|
|
@ -26,12 +26,12 @@ module DiscoursePostEvent
|
|||
extracted_event = extracted_events.first
|
||||
|
||||
if @post.acting_user && @post.event
|
||||
if !@post.acting_user.can_act_on_event?(@post.event)
|
||||
if !@post.acting_user.can_act_on_discourse_post_event?(@post.event)
|
||||
@post.errors.add(:base, I18n.t("discourse_post_event.errors.models.event.acting_user_not_allowed_to_act_on_this_event"))
|
||||
return false
|
||||
end
|
||||
else
|
||||
if !@post.acting_user || !@post.acting_user.can_create_event?
|
||||
if !@post.acting_user || !@post.acting_user.can_create_discourse_post_event?
|
||||
@post.errors.add(:base, I18n.t("discourse_post_event.errors.models.event.acting_user_not_allowed_to_create_event"))
|
||||
return false
|
||||
end
|
||||
|
|
22
plugin.rb
22
plugin.rb
|
@ -126,9 +126,9 @@ after_initialize do
|
|||
end
|
||||
end
|
||||
|
||||
add_to_class(:user, :can_create_event?) do
|
||||
return @can_create_event if defined?(@can_create_event)
|
||||
@can_create_event = begin
|
||||
add_to_class(:user, :can_create_discourse_post_event?) do
|
||||
return @can_create_discourse_post_event if defined?(@can_create_discourse_post_event)
|
||||
@can_create_discourse_post_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?
|
||||
|
@ -141,23 +141,23 @@ after_initialize do
|
|||
user && (user.staff? || user.id == invitee.user_id)
|
||||
end
|
||||
|
||||
add_to_class(:guardian, :can_create_event?) { user && user.can_create_event? }
|
||||
add_to_class(:guardian, :can_create_discourse_post_event?) { user && user.can_create_discourse_post_event? }
|
||||
|
||||
add_to_serializer(:current_user, :can_create_event) do
|
||||
object.can_create_event?
|
||||
add_to_serializer(:current_user, :can_create_discourse_post_event) do
|
||||
object.can_create_discourse_post_event?
|
||||
end
|
||||
|
||||
add_to_class(:user, :can_act_on_event?) do |event|
|
||||
return @can_act_on_event if defined?(@can_act_on_event)
|
||||
@can_act_on_event = begin
|
||||
add_to_class(:user, :can_act_on_discourse_post_event?) do |event|
|
||||
return @can_act_on_discourse_post_event if defined?(@can_act_on_discourse_post_event)
|
||||
@can_act_on_discourse_post_event = begin
|
||||
return true if admin?
|
||||
can_create_event? && event.post.user_id == id
|
||||
can_create_discourse_post_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) }
|
||||
add_to_class(:guardian, :can_act_on_discourse_post_event?) { |event| user && user.can_act_on_discourse_post_event?(event) }
|
||||
|
||||
add_class_method(:group, :discourse_post_event_allowed_groups) do
|
||||
where(id: SiteSetting.discourse_post_event_allowed_on_groups.split('|').compact)
|
||||
|
|
Loading…
Reference in New Issue