2014-10-09 11:22:20 -04:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: members
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# access_level :integer not null
|
|
|
|
# source_id :integer not null
|
|
|
|
# source_type :string(255) not null
|
|
|
|
# user_id :integer not null
|
|
|
|
# notification_level :integer not null
|
|
|
|
# type :string(255)
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
#
|
|
|
|
|
2014-09-14 10:54:10 -04:00
|
|
|
class Member < ActiveRecord::Base
|
2015-02-05 17:20:55 -05:00
|
|
|
include Sortable
|
2014-09-14 10:54:10 -04:00
|
|
|
include Notifiable
|
|
|
|
include Gitlab::Access
|
|
|
|
|
|
|
|
belongs_to :user
|
|
|
|
belongs_to :source, polymorphic: true
|
|
|
|
|
|
|
|
validates :user, presence: true
|
|
|
|
validates :source, presence: true
|
|
|
|
validates :user_id, uniqueness: { scope: [:source_type, :source_id], message: "already exists in source" }
|
2014-09-14 12:32:51 -04:00
|
|
|
validates :access_level, inclusion: { in: Gitlab::Access.all_values }, presence: true
|
2014-09-14 10:54:10 -04:00
|
|
|
|
2014-09-14 12:32:51 -04:00
|
|
|
scope :guests, -> { where(access_level: GUEST) }
|
|
|
|
scope :reporters, -> { where(access_level: REPORTER) }
|
|
|
|
scope :developers, -> { where(access_level: DEVELOPER) }
|
|
|
|
scope :masters, -> { where(access_level: MASTER) }
|
|
|
|
scope :owners, -> { where(access_level: OWNER) }
|
|
|
|
|
|
|
|
delegate :name, :username, :email, to: :user, prefix: true
|
2014-09-14 10:54:10 -04:00
|
|
|
end
|