docbrown/app/models/chat_channel_membership.rb
Ben Halpern 4638768d79
Remove channel member count limit (#545)
* check for dataset content in triggeractive

* Remove channel member count limit
2018-07-03 16:50:53 -04:00

22 lines
768 B
Ruby

class ChatChannelMembership < ApplicationRecord
belongs_to :chat_channel
belongs_to :user
validates :user_id, presence: true, uniqueness: { scope: :chat_channel_id }
validates :chat_channel_id, presence: true, uniqueness: { scope: :user_id }
validates :status, inclusion: { in: %w{active inactive pending rejected left_channel} }
validates :role, inclusion: { in: %w{member mod} }
validate :permission
private
def permission
if chat_channel.channel_type == "direct" && chat_channel.slug.split("/").exclude?(user.username)
errors.add(:user_id, "is not allowed in chat")
end
# To be possibly implemented in future
# if chat_channel.users.size > 128
# errors.add(:base, "too many members in channel")
# end
end
end