You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
760 B
31 lines
760 B
13 years ago
|
class Permission < ActiveRecord::Base
|
||
|
belongs_to :domain, :inverse_of => :permissions
|
||
|
belongs_to :user, :inverse_of => :permissions
|
||
|
|
||
|
validates :domain_id, :presence => true
|
||
|
validates :user_id, :presence => true, :uniqueness => {
|
||
|
:scope => :domain_id,
|
||
|
:message => "already is permitted"
|
||
|
}
|
||
|
validates :user, :presence => {
|
||
|
:if => lambda {@user_email.present?},
|
||
|
:message => "with given email was not found"
|
||
|
}
|
||
|
validate do
|
||
|
errors[:user] = 'cannot be yourself' if user_id == domain.user_id
|
||
|
end
|
||
|
|
||
|
def user_email
|
||
|
@user_email || user.try(:email)
|
||
|
end
|
||
|
|
||
|
def user_email=(email)
|
||
|
@user_email = email
|
||
|
self.user = User.find_by_email(email)
|
||
|
end
|
||
|
|
||
|
def to_label
|
||
|
user.try(:email) || @user_email || '-'
|
||
|
end
|
||
|
end
|