From e8ac9cfcc142dd68421bf8b1edc741260388e182 Mon Sep 17 00:00:00 2001 From: albert Date: Fri, 21 Oct 2011 17:29:41 -0400 Subject: [PATCH] users can now select their level when signing up (for testing only) --- app/assets/stylesheets/specific/users.css.scss | 11 +++++++---- app/controllers/users_controller.rb | 4 ++-- app/models/user.rb | 18 +++++++++++++++++- app/views/users/new.html.erb | 1 + 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/specific/users.css.scss b/app/assets/stylesheets/specific/users.css.scss index e39eb0286..6cd608109 100644 --- a/app/assets/stylesheets/specific/users.css.scss +++ b/app/assets/stylesheets/specific/users.css.scss @@ -16,7 +16,7 @@ div#c-users { } div#a-new { - max-width: 60em; + max-width: 50em; p { margin-bottom: 1em; @@ -28,8 +28,11 @@ div#c-users { } div#account-comparison { + padding: 0 1em; + margin: 1em 0; + h1 { - font-size: $h2_size; + font-size: $h3_size; } li { @@ -38,9 +41,9 @@ div#c-users { } section { - width: 18em; + width: 15em; float: left; - padding: 1em; + padding-right: 1em; } } diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 2ab60a448..06b1aa332 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -27,7 +27,7 @@ class UsersController < ApplicationController end def create - @user = User.create(params[:user]) + @user = User.create(params[:user], :as => :admin) if @user.errors.empty? session[:user_id] = @user.id end @@ -38,7 +38,7 @@ class UsersController < ApplicationController def update @user = User.find(params[:id]) check_privilege(@user) - @user.update_attributes(params[:user]) + @user.update_attributes(params[:user], :as => :admin) respond_with(@user) end diff --git a/app/models/user.rb b/app/models/user.rb index c07b25279..bfa7e2fdb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,7 +15,8 @@ class User < ActiveRecord::Base attr_accessor :password, :old_password attr_accessible :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size - validates_length_of :name, :within => 2..1000, :on => :create + attr_accessible :level, :as => :admin + validates_length_of :name, :within => 2..100, :on => :create validates_format_of :name, :with => /\A[^\s:]+\Z/, :on => :create, :message => "cannot have whitespace or colons" validates_uniqueness_of :name, :case_sensitive => false, :on => :create validates_uniqueness_of :email, :case_sensitive => false, :on => :create, :if => lambda {|rec| !rec.email.blank?} @@ -191,6 +192,21 @@ class User < ActiveRecord::Base end module LevelMethods + extend ActiveSupport::Concern + + module ClassMethods + def level_hash + return { + "Member" => Levels::MEMBER, + "Privileged" => Levels::PRIVILEGED, + "Contributor" => Levels::CONTRIBUTOR, + "Janitor" => Levels::JANITOR, + "Moderator" => Levels::MODERATOR, + "Admin" => Levels::ADMIN + } + end + end + def promote_to_admin_if_first_user return if Rails.env.test? diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 000e9fe72..6d863d7e4 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -69,6 +69,7 @@ <%= f.input :password %> <%= f.input :password_confirmation %> <%= f.input :email, :required => false %> + <%= f.input :level, :collection => User.level_hash.to_a, :include_blank => false %> <%= f.button :submit %> <% end %>