2013-06-19 12:40:33 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: users_groups
|
|
|
|
#
|
2013-08-21 09:34:02 +00:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# group_access :integer not null
|
|
|
|
# group_id :integer not null
|
|
|
|
# user_id :integer not null
|
2014-04-09 12:05:03 +00:00
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2013-08-21 09:34:02 +00:00
|
|
|
# notification_level :integer default(3), not null
|
2013-06-19 12:40:33 +00:00
|
|
|
#
|
|
|
|
|
2013-06-17 10:07:16 +00:00
|
|
|
class UsersGroup < ActiveRecord::Base
|
2013-06-21 20:17:58 +00:00
|
|
|
include Notifiable
|
2013-08-20 12:59:45 +00:00
|
|
|
include Gitlab::Access
|
2013-06-17 10:07:16 +00:00
|
|
|
|
2013-06-17 10:26:58 +00:00
|
|
|
def self.group_access_roles
|
2013-08-20 12:59:45 +00:00
|
|
|
Gitlab::Access.options_with_owner
|
2013-06-17 10:26:58 +00:00
|
|
|
end
|
|
|
|
|
2013-06-17 10:41:35 +00:00
|
|
|
attr_accessible :group_access, :user_id
|
2013-06-17 10:07:16 +00:00
|
|
|
|
|
|
|
belongs_to :user
|
2013-06-17 14:03:56 +00:00
|
|
|
belongs_to :group
|
2013-06-17 10:07:16 +00:00
|
|
|
|
|
|
|
scope :guests, -> { where(group_access: GUEST) }
|
|
|
|
scope :reporters, -> { where(group_access: REPORTER) }
|
|
|
|
scope :developers, -> { where(group_access: DEVELOPER) }
|
|
|
|
scope :masters, -> { where(group_access: MASTER) }
|
|
|
|
scope :owners, -> { where(group_access: OWNER) }
|
|
|
|
|
|
|
|
scope :with_group, ->(group) { where(group_id: group.id) }
|
|
|
|
scope :with_user, ->(user) { where(user_id: user.id) }
|
2013-06-17 10:26:58 +00:00
|
|
|
|
2014-06-17 18:36:40 +00:00
|
|
|
after_create :notify_create
|
|
|
|
after_update :notify_update
|
|
|
|
|
2013-06-17 10:26:58 +00:00
|
|
|
validates :group_access, inclusion: { in: UsersGroup.group_access_roles.values }, presence: true
|
|
|
|
validates :user_id, presence: true
|
|
|
|
validates :group_id, presence: true
|
2013-06-17 13:51:43 +00:00
|
|
|
validates :user_id, uniqueness: { scope: [:group_id], message: "already exists in group" }
|
2013-06-17 10:26:58 +00:00
|
|
|
|
2013-06-17 10:41:35 +00:00
|
|
|
delegate :name, :username, :email, to: :user, prefix: true
|
|
|
|
|
2013-08-20 12:59:45 +00:00
|
|
|
def access_field
|
|
|
|
group_access
|
2013-06-17 10:26:58 +00:00
|
|
|
end
|
2014-06-17 18:36:40 +00:00
|
|
|
|
|
|
|
def notify_create
|
|
|
|
notification_service.new_group_member(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def notify_update
|
|
|
|
if group_access_changed?
|
|
|
|
notification_service.update_group_member(self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def notification_service
|
|
|
|
NotificationService.new
|
|
|
|
end
|
2013-06-17 10:07:16 +00:00
|
|
|
end
|