2013-06-17 06:07:16 -04:00
|
|
|
class UsersGroup < ActiveRecord::Base
|
|
|
|
GUEST = 10
|
|
|
|
REPORTER = 20
|
|
|
|
DEVELOPER = 30
|
|
|
|
MASTER = 40
|
|
|
|
OWNER = 50
|
|
|
|
|
2013-06-17 06:26:58 -04:00
|
|
|
def self.group_access_roles
|
|
|
|
{
|
|
|
|
"Guest" => GUEST,
|
|
|
|
"Reporter" => REPORTER,
|
|
|
|
"Developer" => DEVELOPER,
|
|
|
|
"Master" => MASTER,
|
|
|
|
"Owner" => OWNER
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2013-06-17 06:41:35 -04:00
|
|
|
attr_accessible :group_access, :user_id
|
2013-06-17 06:07:16 -04:00
|
|
|
|
|
|
|
belongs_to :user
|
|
|
|
belongs_to :project
|
|
|
|
|
|
|
|
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 06:26:58 -04: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 06:41:35 -04:00
|
|
|
delegate :name, :username, :email, to: :user, prefix: true
|
|
|
|
|
2013-06-17 07:17:32 -04:00
|
|
|
def human_access
|
2013-06-17 06:26:58 -04:00
|
|
|
UsersGroup.group_access_roles.index(self.group_access)
|
|
|
|
end
|
2013-06-17 06:07:16 -04:00
|
|
|
end
|