Class: TurboChat::ChatMembershipsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- TurboChat::ChatMembershipsController
- Defined in:
- app/controllers/turbo_chat/chat_memberships_controller.rb
Instance Method Summary collapse
Instance Method Details
#ban ⇒ Object
65 66 67 68 69 70 |
# File 'app/controllers/turbo_chat/chat_memberships_controller.rb', line 65 def ban TurboChat::Moderation.ban_member!(actor: current_chat_participant, membership: @chat_membership) redirect_to chat_path(@chat), notice: "Member removed" rescue TurboChat::Moderation::AuthorizationError head :forbidden end |
#create ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/turbo_chat/chat_memberships_controller.rb', line 13 def create participant = invite_participant membership = @chat.chat_memberships.find_or_initialize_by(participant: participant) if membership.persisted? return redirect_to(chat_path(@chat), alert: "Participant is already in this chat") if membership.active? return redirect_to(chat_path(@chat), alert: "Invitation already pending") if membership.pending? end membership.assign_attributes(invitation_membership_attributes(membership)) membership.save! TurboChat::ChatMessage.( chat: @chat, actor: current_chat_participant, event: :invited, subject: participant ) set_chat_lifecycle_event(action: :invited, chat: @chat, membership: membership) redirect_to chat_path(@chat), notice: "Participant invited" rescue ActiveRecord::RecordNotFound redirect_to chat_path(@chat), alert: "Participant not found" rescue NameError, ArgumentError redirect_to chat_path(@chat), alert: "Invalid participant type" rescue ActiveRecord::RecordInvalid => error redirect_to chat_path(@chat), alert: error.record.errors..to_sentence end |
#mute ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/turbo_chat/chat_memberships_controller.rb', line 53 def mute if @chat_membership.muted? TurboChat::Moderation.unmute_member!(actor: current_chat_participant, membership: @chat_membership) redirect_to chat_path(@chat), notice: "Member unmuted" else TurboChat::Moderation.mute_member!(actor: current_chat_participant, membership: @chat_membership) redirect_to chat_path(@chat), notice: "Member muted" end rescue TurboChat::Moderation::AuthorizationError head :forbidden end |
#update ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/turbo_chat/chat_memberships_controller.rb', line 40 def update requested_role_key = update_params.fetch(:role_key).to_s.strip return redirect_to(chat_path(@chat), alert: "Role is required") if requested_role_key.blank? return redirect_to(chat_path(@chat), alert: "You cannot assign that role") unless role_assignment_allowed?(requested_role_key) @chat_membership.update!(role_key: requested_role_key) redirect_to chat_path(@chat), notice: "Member permissions updated" rescue ActiveRecord::RecordNotFound redirect_to chat_path(@chat), alert: "Membership not found" rescue ActiveRecord::RecordInvalid => error redirect_to chat_path(@chat), alert: error.record.errors..to_sentence end |