Adds period_end_date and map_view_quota to Users

period_end_date: next billing cycle for this user
map_view_quota:  total amount of map views per month a given
                 user is allowed to make

This commits also allows to update those attributes using
the superadmin API
2.0
David Arango 11 years ago
parent 7c4a7b0148
commit eb00261ce9

@ -18,6 +18,8 @@ class Superadmin::UsersController < Superadmin::SuperadminController
@user.table_quota = attributes[:table_quota] if attributes.has_key?(:table_quota)
@user.account_type = attributes[:account_type] if attributes.has_key?(:account_type)
@user.private_tables_enabled = attributes[:private_tables_enabled] if attributes.has_key?(:private_tables_enabled)
@user.map_view_quota = attributes[:map_view_quota] if attributes.has_key?(:map_view_quota)
@user.period_end_date = attributes[:period_end_date] if attributes.has_key?(:period_end_date)
if attributes[:password].present?
@user.password = attributes[:password]
@ -44,6 +46,8 @@ class Superadmin::UsersController < Superadmin::SuperadminController
@user.table_quota = attributes[:table_quota] if attributes.has_key?(:table_quota)
@user.account_type = attributes[:account_type] if attributes.has_key?(:account_type)
@user.private_tables_enabled = attributes[:private_tables_enabled] if attributes.has_key?(:private_tables_enabled)
@user.map_view_quota = attributes[:map_view_quota] if attributes.has_key?(:map_view_quota)
@user.period_end_date = attributes[:period_end_date] if attributes.has_key?(:period_end_date)
if attributes[:password].present?
@user.password = attributes[:password]

@ -17,7 +17,9 @@ class User < Sequel::Model
}
# Sequel setup & plugins
set_allowed_columns :email, :map_enabled, :password_confirmation, :quota_in_bytes, :table_quota, :account_type, :private_tables_enabled
set_allowed_columns :email, :map_enabled, :password_confirmation,
:quota_in_bytes, :table_quota, :account_type, :private_tables_enabled,
:period_end_date, :map_view_quota
plugin :validation_helpers
plugin :json_serializer

@ -0,0 +1,14 @@
class AddPeriodEndDateToUsers < Sequel::Migration
def up
alter_table :users do
add_column :period_end_date, DateTime
set_column_default :period_end_date, :now.sql_function
end
end #up
def down
alter_table :users do
drop_column :period_end_date
end
end #down
end

@ -0,0 +1,7 @@
Sequel.migration do
change do
alter_table :users do
add_column :map_view_quota, :integer, :default => 10000
end
end
end

@ -62,12 +62,14 @@ feature "Superadmin's users API" do
scenario "user create default account settings" do
@user_atts[:private_tables_enabled] = false
@user_atts[:map_view_quota] = 80
post_json superadmin_users_path, { :user => @user_atts }, default_headers do |response|
response.status.should == 201
response.body[:quota_in_bytes].should == 104857600
response.body[:table_quota].should == 5
response.body[:account_type].should == 'FREE'
response.body[:private_tables_enabled].should == false
response.body[:map_view_quota].should == 80
# Double check that the user has been created properly
user = User.filter(:email => @user_atts[:email]).first
@ -138,11 +140,12 @@ feature "Superadmin's users API" do
scenario "user update success" do
user = create_user
put_json superadmin_user_path(user), { :user => { :email => "newmail@test.com" } }, default_headers do |response|
put_json superadmin_user_path(user), { :user => { :email => "newmail@test.com", :map_view_quota => 80 } }, default_headers do |response|
response.status.should == 204
end
user = User[user.id]
user.email.should == "newmail@test.com"
user.map_view_quota.should == 80
end
scenario "user delete success" do

@ -22,9 +22,11 @@ module CartoDB
user.admin = attributes[:admin] == false ? false : true
user.private_tables_enabled= attributes[:private_tables_enabled] == false ? false : true
user.enabled = attributes[:enabled] == false ? false : true
user.table_quota = attributes[:table_quota] if attributes[:table_quota]
user.quota_in_bytes = attributes[:quota_in_bytes] if attributes[:quota_in_bytes]
user.account_type = attributes[:account_type] if attributes[:account_type]
user.table_quota = attributes[:table_quota] if attributes[:table_quota]
user.quota_in_bytes = attributes[:quota_in_bytes] if attributes[:quota_in_bytes]
user.account_type = attributes[:account_type] if attributes[:account_type]
user.map_view_quota = attributes[:map_view_quota] if attributes.has_key?(:map_view_quota)
user.period_end_date = attributes[:period_end_date] if attributes.has_key?(:period_end_date)
user
end

Loading…
Cancel
Save