gitlab-org--gitlab-foss/app/models/users_group.rb

47 lines
1.4 KiB
Ruby
Raw Normal View History

2013-06-19 08:40:33 -04:00
# == Schema Information
#
# Table name: users_groups
#
2013-08-21 05:34:02 -04:00
# id :integer not null, primary key
# group_access :integer not null
# group_id :integer not null
# user_id :integer not null
# created_at :datetime
# updated_at :datetime
2013-08-21 05:34:02 -04:00
# notification_level :integer default(3), not null
2013-06-19 08:40:33 -04:00
#
class UsersGroup < ActiveRecord::Base
2013-06-21 16:17:58 -04:00
include Notifiable
2013-08-20 08:59:45 -04:00
include Gitlab::Access
def self.group_access_roles
2013-08-20 08:59:45 -04:00
Gitlab::Access.options_with_owner
end
2013-06-17 06:41:35 -04:00
attr_accessible :group_access, :user_id
belongs_to :user
2013-06-17 10:03:56 -04:00
belongs_to :group
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) }
validates :group_access, inclusion: { in: UsersGroup.group_access_roles.values }, presence: true
validates :user_id, presence: true
validates :group_id, presence: true
validates :user_id, uniqueness: { scope: [:group_id], message: "already exists in group" }
2013-06-17 06:41:35 -04:00
delegate :name, :username, :email, to: :user, prefix: true
2013-08-20 08:59:45 -04:00
def access_field
group_access
end
end