Reroute and refactor admin user creation to force invitation and self registration work correct. Refs #270

This commit is contained in:
Pavel Chipiga 2012-03-26 17:49:00 +03:00
parent 4b96c988d4
commit dafedb3dcf
6 changed files with 8 additions and 12 deletions

View File

@ -1,8 +1,7 @@
# -*- encoding : utf-8 -*-
class Admin::UsersController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource :except => :create
authorize_resource :only => :create
load_and_authorize_resource
def index
@filter = params[:filter] || 'all'
@ -12,14 +11,13 @@ class Admin::UsersController < ApplicationController
end
def create
@user = User.new params[:user]
@user.role = params[:role]
@user.uname = params[:uname]
if @user.save
flash[:notice] = t('flash.user.saved')
redirect_to users_path
else
flash[:error] = t('flash.user.save_error')
flash[:warning] = @user.errors.full_messages.join('. ')
render :action => :new
end
end

View File

@ -14,12 +14,9 @@ class Ability
# Shared rights between guests and registered users
can :forbidden, Platform
# TODO remove because auth callbacks skipped
can :auto_build, Project
can [:publish_build, :status_build, :pre_build, :post_build, :circle_build, :new_bbdt], BuildList
if user.guest? # Guest rights
can :create, User
can [:create, :show_message], RegisterRequest
else # Registered user rights
if user.admin?

View File

@ -43,7 +43,7 @@ class User < ActiveRecord::Base
validates :role, :inclusion => {:in => ROLES}, :allow_blank => true
validates :language, :inclusion => {:in => LANGUAGES}, :allow_blank => true
attr_accessible :email, :password, :password_confirmation, :current_password, :remember_me, :login, :name, :language,
attr_accessible :email, :password, :password_confirmation, :current_password, :remember_me, :login, :name, :uname, :language,
:site, :company, :professional_experience, :location, :avatar
attr_readonly :uname, :own_projects_count
attr_accessor :login

View File

@ -2,9 +2,10 @@
.content
%h2.title= t("layout.users.new_header")
.inner
= form_for @user, :url => users_path, :html => { :class => :form } do |f|
= form_for @user, :url => create_user_path, :html => { :class => :form } do |f|
= render :partial => "users/form", :locals => {:f => f}
- content_for :sidebar do
.bordered.nopadding
= render 'admin/submenu'
= render 'admin/submenu'

View File

@ -7,7 +7,7 @@
.leftlist
= f.label :uname, t("activerecord.attributes.user.uname")
.rightlist
= f.text_field :uname, :name => 'uname'
= f.text_field :uname
.leftlist
= f.label :password, t("activerecord.attributes.user.password")
.rightlist

View File

@ -10,7 +10,7 @@ Rosa::Application.routes.draw do
get '/users' => 'admin/users#index', :as => :users
get '/users/new' => 'admin/users#new', :as => :new_user
get '/users/list' => 'admin/users#list', :as => :users_list
post '/users' => 'admin/users#create', :as => :create_user
post '/users/create' => 'admin/users#create', :as => :create_user
get '/users/:id/edit' => 'admin/users#profile', :as => :edit_user
put '/users/:id/edit' => 'admin/users#update', :as => :update_user
delete '/users/:id/delete' => 'admin/users#destroy', :as => :delete_user