Added UserTeam core models (team and m-t-m relationships) and updated other models
This commit is contained in:
parent
f6c482c06f
commit
8a86fe7bb0
14 changed files with 248 additions and 28 deletions
24
app/models/user_team_project_relationship.rb
Normal file
24
app/models/user_team_project_relationship.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
class UserTeamProjectRelationship < ActiveRecord::Base
|
||||
attr_accessible :greatest_access, :project_id, :user_team_id
|
||||
|
||||
belongs_to :user_team
|
||||
belongs_to :project
|
||||
|
||||
validates :project, presence: true
|
||||
validates :user_team, presence: true
|
||||
validate :check_greatest_access
|
||||
|
||||
scope :with_project, ->(project){ where(project_id: project.id) }
|
||||
|
||||
private
|
||||
|
||||
def check_greatest_access
|
||||
errors.add(:base, :incorrect_access_code) unless correct_access?
|
||||
end
|
||||
|
||||
def correct_access?
|
||||
return false if greatest_access.blank?
|
||||
return true if UsersProject.access_roles.has_value?(greatest_access)
|
||||
false
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue