diff options
Diffstat (limited to 'users')
-rw-r--r-- | users/app/models/service_level.rb | 31 | ||||
-rw-r--r-- | users/app/models/user.rb | 22 | ||||
-rw-r--r-- | users/app/views/users/_edit.html.haml | 6 |
3 files changed, 52 insertions, 7 deletions
diff --git a/users/app/models/service_level.rb b/users/app/models/service_level.rb new file mode 100644 index 0000000..ac5244f --- /dev/null +++ b/users/app/models/service_level.rb @@ -0,0 +1,31 @@ +class ServiceLevel + + def initialize(attributes = {}) + @level = attributes[:level] || APP_CONFIG[:default_service_level] + end + + def level + @level + end + + def name + APP_CONFIG[:service_levels][@level][:name] + end + + def cert_prefix + APP_CONFIG[:service_levels][@level][:cert_prefix] + end + + def description + APP_CONFIG[:service_levels][@level][:description] + end + + def cost + APP_CONFIG[:service_levels][@level][:cost] + end + + def quota + APP_CONFIG[:service_levels][@level][:quota] + end + +end diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 35212a1..621ff4e 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -9,9 +9,9 @@ class User < CouchRest::Model::Base property :enabled, TrueClass, :default => true - # these will be null by default. should we set to APP_CONFIG[:default_service_level] by default, or have code assume that until these get set?: - property :desired_service_level, Integer, :accessible => true - property :effective_service_level, Integer, :accessible => true + # these will be null by default but we shouldn't ever pull them directly, but only via the methods that will return the full ServiceLevel + property :desired_service_level_code, Integer, :accessible => true + property :effective_service_level_code, Integer, :accessible => true before_save :update_effective_service_level @@ -100,6 +100,16 @@ class User < CouchRest::Model::Base @identity = Identity.for(self) end + def desired_service_level + code = self.desired_service_level_code || APP_CONFIG[:default_service_level] + ServiceLevel.new({level: code}) + end + + def effective_service_level + code = self.effective_service_level_code || self.desired_service_level.level + ServiceLevel.new({level: code}) + end + protected ## @@ -124,8 +134,10 @@ class User < CouchRest::Model::Base end def update_effective_service_level - if self.desired_service_level_changed? - self.effective_service_level = self.desired_service_level + # TODO: Is this always the case? Might there be a situation where the admin has set the effective service level and we don't want it changed to match the desired one? + if self.desired_service_level_code_changed? + self.effective_service_level_code = self.desired_service_level_code end end + end diff --git a/users/app/views/users/_edit.html.haml b/users/app/views/users/_edit.html.haml index d5a0ff1..d2c2d95 100644 --- a/users/app/views/users/_edit.html.haml +++ b/users/app/views/users/_edit.html.haml @@ -47,11 +47,13 @@ %legend= t(:service_level) - if @user != current_user = t(:desired_service_level) - = f.select :desired_service_level, [[APP_CONFIG[:service_levels][1][:description], 1],[APP_CONFIG[:service_levels][2][:description], 2]], :selected => @user.desired_service_level || APP_CONFIG[:default_service_level] + - sl1 = ServiceLevel.new({level: 1}) #ugly but okay for now + - sl2 = ServiceLevel.new({level: 2}) + = f.select :desired_service_level_code, [[sl1.description, sl1.level],[sl2.description, sl2.level]], :selected => @user.desired_service_level.level - if @user != current_user %p = t(:effective_service_level) - = f.select :effective_service_level, [[APP_CONFIG[:service_levels][1][:description], 1],[APP_CONFIG[:service_levels][2][:description], 2]], :selected => @user.effective_service_level || APP_CONFIG[:default_service_level] + = f.select :effective_service_level_code, [[sl1.description, sl1.level],[sl2.description, sl2.level]], :selected => @user.effective_service_level.level .control-group .controls = f.submit t(:save), :class => 'btn', :data => {"loading-text" => "Saving..."} |