summaryrefslogtreecommitdiff
path: root/users
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2013-12-09 10:14:17 -0800
committerazul <azul@riseup.net>2013-12-09 10:14:17 -0800
commit0f2e1316894cdffac47448b6ddbf2cfaf5f93a55 (patch)
treeae2577c3584e66ffa2937ad9807e32cc6ff49db3 /users
parente7e5dac36127a36cac9ed35054767d04b2e5ae17 (diff)
parent6ebf095bc553345a3e0b8c48cadc3e1440c59ca5 (diff)
Merge pull request #119 from jessib/feature/service_level
Feature/service level
Diffstat (limited to 'users')
-rw-r--r--users/app/controllers/users_controller.rb6
-rw-r--r--users/app/models/service_level.rb19
-rw-r--r--users/app/models/unauthenticated_user.rb2
-rw-r--r--users/app/models/user.rb24
-rw-r--r--users/app/views/users/_edit.html.haml19
5 files changed, 70 insertions, 0 deletions
diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb
index 3cbb6dc..8b4715c 100644
--- a/users/app/controllers/users_controller.rb
+++ b/users/app/controllers/users_controller.rb
@@ -34,6 +34,12 @@ class UsersController < UsersBaseController
def edit
end
+ ## added so updating service level works, but not sure we will actually want this. also not sure that this is place to prevent user from updating own effective service level, but here as placeholder:
+ def update
+ @user.update_attributes(params[:user]) unless (!admin? and params[:user][:effective_service_level])
+ respond_with @user
+ end
+
def deactivate
@user.enabled = false
@user.save
diff --git a/users/app/models/service_level.rb b/users/app/models/service_level.rb
new file mode 100644
index 0000000..299aaf1
--- /dev/null
+++ b/users/app/models/service_level.rb
@@ -0,0 +1,19 @@
+class ServiceLevel
+
+ def initialize(attributes = {})
+ @id = attributes[:id] || APP_CONFIG[:default_service_level]
+ end
+
+ 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 id
+ @id
+ end
+
+ def config_hash
+ APP_CONFIG[:service_levels][@id]
+ end
+
+end
diff --git a/users/app/models/unauthenticated_user.rb b/users/app/models/unauthenticated_user.rb
index 99a6874..0fc17d2 100644
--- a/users/app/models/unauthenticated_user.rb
+++ b/users/app/models/unauthenticated_user.rb
@@ -1,4 +1,6 @@
# The nil object for the user class
class UnauthenticatedUser < Object
+ # will probably want something here to return service level as APP_CONFIG[:service_levels][0] but not sure how will be accessing.
+
end
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index a14fcb5..720f5a9 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -9,6 +9,12 @@ class User < CouchRest::Model::Base
property :enabled, TrueClass, :default => 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
+
validates :login, :password_salt, :password_verifier,
:presence => true
@@ -94,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({id: code})
+ end
+
+ def effective_service_level
+ code = self.effective_service_level_code || self.desired_service_level.id
+ ServiceLevel.new({id: code})
+ end
+
protected
##
@@ -116,4 +132,12 @@ class User < CouchRest::Model::Base
def serverside?
true
end
+
+ def update_effective_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 b86172e..0b36d6e 100644
--- a/users/app/views/users/_edit.html.haml
+++ b/users/app/views/users/_edit.html.haml
@@ -37,6 +37,25 @@
.controls
= f.submit t(:save), :class => 'btn', :data => {"loading-text" => "Saving..."}
+
+-# TODO: probably won't want here, but here for now. Also, we will need way to ensure payment if they pick a non-free plan.
+-#
+-# SERVICE LEVEL
+-#
+- if APP_CONFIG[:service_levels]
+ - form_options = {:html => {:class => user_form_class('form-horizontal'), :id => 'update_service_level', :data => {token: session[:token]}}, :validate => true}
+ = simple_form_for @user, form_options do |f|
+ %legend= t(:service_level)
+ - if @user != current_user
+ = t(:desired_service_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, ServiceLevel.authenticated_select_options, :selected => @user.effective_service_level.id
+ .control-group
+ .controls
+ = f.submit t(:save), :class => 'btn', :data => {"loading-text" => "Saving..."}
-#
-# DESTROY ACCOUNT
-#