diff options
author | spag <spag@golwen.net> | 2013-01-24 15:37:24 +0100 |
---|---|---|
committer | spag <spag@golwen.net> | 2013-01-24 15:37:24 +0100 |
commit | 99270421d02b3ac77bf111bbde62a2ef80f8e114 (patch) | |
tree | 6ddb8328729e53dcc7a605040cd7aece622d0e5a /app/models | |
parent | 5f5ea1d06686ec5cd31cf8b9db177191fa7e66fd (diff) | |
parent | 2d6ebf19e5cea45dd714f92a64b1b81e1200a811 (diff) |
Merge branch 'develop' of github.com:amooma/GS5 into develop
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ability.rb | 4 | ||||
-rw-r--r-- | app/models/gemeinschaft_setup.rb | 8 | ||||
-rw-r--r-- | app/models/user.rb | 13 |
3 files changed, 25 insertions, 0 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb index b846af0..0d13dab 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -82,6 +82,10 @@ class Ability # cannot [:create, :destroy], GsParameter cannot [:create, :destroy], GuiFunction + + # An admin can not destroy his/her account + # + cannot [:destroy], User, :id => user.id else # Any user can do the following stuff. # diff --git a/app/models/gemeinschaft_setup.rb b/app/models/gemeinschaft_setup.rb index 6056236..4b4dd37 100644 --- a/app/models/gemeinschaft_setup.rb +++ b/app/models/gemeinschaft_setup.rb @@ -6,6 +6,14 @@ class GemeinschaftSetup < ActiveRecord::Base belongs_to :country belongs_to :language + validates :default_company_name, + :presence => true, + :uniqueness => true + + validates :default_system_email, + :presence => true, + :uniqueness => true + # Remove the cache which was created by the heater rake task. # after_create :expire_cache diff --git a/app/models/user.rb b/app/models/user.rb index b902b99..afb3f04 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -95,6 +95,8 @@ class User < ActiveRecord::Base before_destroy :destroy_or_logout_phones + after_save :become_a_member_of_default_user_groups + def destroy clean_whitelist_entries super @@ -142,6 +144,9 @@ class User < ActiveRecord::Base self.pin_hash == Digest::SHA2.hexdigest( "#{self.pin_salt}#{entered_pin}" ) end + def admin? + self.user_groups.include?(UserGroup.find(2)) + end private @@ -207,4 +212,12 @@ class User < ActiveRecord::Base end end + # Normaly a new user should become a member of default user groups. + # + def become_a_member_of_default_user_groups + UserGroup.where(:id => GsParameter.get('DEFAULT_USER_GROUPS_IDS')).each do |user_group| + user_group.user_group_memberships.create(:user_id => self.id) + end + end + end |