summaryrefslogtreecommitdiff
path: root/users/app
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-12-03 15:07:11 -0800
committerjessib <jessib@riseup.net>2013-12-03 15:07:11 -0800
commit7d4a9658c29cad526cfe5c952f71109e8eb304e7 (patch)
treeea8e40efd34803f27bceef585a3de77a4021e973 /users/app
parent35761333404e3cc2c93bca23036d0fd8e47fd10b (diff)
Some simplification of code.
Diffstat (limited to 'users/app')
-rw-r--r--users/app/models/service_level.rb26
-rw-r--r--users/app/models/user.rb6
-rw-r--r--users/app/views/users/_edit.html.haml6
3 files changed, 12 insertions, 26 deletions
diff --git a/users/app/models/service_level.rb b/users/app/models/service_level.rb
index ac5244f..299aaf1 100644
--- a/users/app/models/service_level.rb
+++ b/users/app/models/service_level.rb
@@ -1,31 +1,19 @@
class ServiceLevel
def initialize(attributes = {})
- @level = attributes[:level] || APP_CONFIG[:default_service_level]
+ @id = attributes[:id] || APP_CONFIG[:default_service_level]
end
- def level
- @level
+ def self.authenticated_select_options
+ APP_CONFIG[:service_levels].map { |id,config_hash| [config_hash[:description], id] if config_hash[:name] != 'anonymous'}.compact
end
- def name
- APP_CONFIG[:service_levels][@level][:name]
+ def id
+ @id
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]
+ def config_hash
+ APP_CONFIG[:service_levels][@id]
end
end
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index 621ff4e..720f5a9 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -102,12 +102,12 @@ class User < CouchRest::Model::Base
def desired_service_level
code = self.desired_service_level_code || APP_CONFIG[:default_service_level]
- ServiceLevel.new({level: code})
+ ServiceLevel.new({id: code})
end
def effective_service_level
- code = self.effective_service_level_code || self.desired_service_level.level
- ServiceLevel.new({level: code})
+ code = self.effective_service_level_code || self.desired_service_level.id
+ ServiceLevel.new({id: code})
end
protected
diff --git a/users/app/views/users/_edit.html.haml b/users/app/views/users/_edit.html.haml
index d2c2d95..897c54b 100644
--- a/users/app/views/users/_edit.html.haml
+++ b/users/app/views/users/_edit.html.haml
@@ -47,13 +47,11 @@
%legend= t(:service_level)
- if @user != current_user
= t(:desired_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
+ = f.select :desired_service_level_code, ServiceLevel.authenticated_select_options, :selected => @user.desired_service_level.id
- if @user != current_user
%p
= t(:effective_service_level)
- = f.select :effective_service_level_code, [[sl1.description, sl1.level],[sl2.description, sl2.level]], :selected => @user.effective_service_level.level
+ = f.select :effective_service_level_code, ServiceLevel.authenticated_select_options, :selected => @user.effective_service_level.id
.control-group
.controls
= f.submit t(:save), :class => 'btn', :data => {"loading-text" => "Saving..."}