summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-11-18 15:44:54 -0800
committerjessib <jessib@riseup.net>2013-11-18 15:44:54 -0800
commit8e9b65b01bbd9d44d4077d94f2dc4ac375cf8e85 (patch)
treec6e59e7a1e837b8cf759948acd8874594e54e19d
parentd2eaffde87286c0cc9c0658503a60706759f7f51 (diff)
Start of service level code, which will be tweaked
* stores desired & effective service level * whenever desired level is changed, effective level will be updated * allows user to set their desired service level * allow admin to update desired & effective service level
-rw-r--r--config/defaults.yml23
-rw-r--r--users/app/controllers/users_controller.rb6
-rw-r--r--users/app/models/unauthenticated_user.rb2
-rw-r--r--users/app/models/user.rb12
-rw-r--r--users/app/views/users/_edit.html.haml18
5 files changed, 61 insertions, 0 deletions
diff --git a/config/defaults.yml b/config/defaults.yml
index c7c8502..c986d01 100644
--- a/config/defaults.yml
+++ b/config/defaults.yml
@@ -41,12 +41,33 @@ common: &common
# handles that will be allowed despite being in /etc/passwd or rfc2142
handle_whitelist: []
+service_levels: &service_levels
+ service_levels:
+ 0:
+ name: anonymous
+ cert_prefix: "LIMITED"
+ description: "anonymous account, with rate limited VPN"
+ 1:
+ name: free
+ cert_prefix: "LIMITED"
+ description: "free account, with rate limited VPN"
+ cost: 0
+ quota: 100
+ 2:
+ name: premium
+ cert_prefix: "UNLIMITED"
+ description: "premium account, with unlimited vpn"
+ cost:
+ USD: 10
+ EUR: 10
+ default_service_level: 1
development:
<<: *downloads
<<: *dev_ca
<<: *cert_options
<<: *common
+ <<: *service_levels
admins: [blue, admin, admin2]
domain: example.org
secret_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
@@ -57,6 +78,7 @@ test:
<<: *dev_ca
<<: *cert_options
<<: *common
+ <<: *service_levels
admins: [admin, admin2]
domain: test.me
secret_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
@@ -66,6 +88,7 @@ production:
<<: *downloads
<<: *cert_options
<<: *common
+ <<: *service_levels
admins: []
domain: example.net
payment: []
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/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..35212a1 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. 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
+
+ before_save :update_effective_service_level
+
validates :login, :password_salt, :password_verifier,
:presence => true
@@ -116,4 +122,10 @@ class User < CouchRest::Model::Base
def serverside?
true
end
+
+ def update_effective_service_level
+ if self.desired_service_level_changed?
+ self.effective_service_level = self.desired_service_level
+ end
+ end
end
diff --git a/users/app/views/users/_edit.html.haml b/users/app/views/users/_edit.html.haml
index b86172e..d5a0ff1 100644
--- a/users/app/views/users/_edit.html.haml
+++ b/users/app/views/users/_edit.html.haml
@@ -37,6 +37,24 @@
.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
+-#
+- 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, [[APP_CONFIG[:service_levels][1][:description], 1],[APP_CONFIG[:service_levels][2][:description], 2]], :selected => @user.desired_service_level || APP_CONFIG[:default_service_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]
+ .control-group
+ .controls
+ = f.submit t(:save), :class => 'btn', :data => {"loading-text" => "Saving..."}
-#
-# DESTROY ACCOUNT
-#