Reroute and refactor admin user creation to force invitation and self registration work correct. Refs #270
This commit is contained in:
parent
4b96c988d4
commit
dafedb3dcf
|
@ -1,8 +1,7 @@
|
||||||
# -*- encoding : utf-8 -*-
|
# -*- encoding : utf-8 -*-
|
||||||
class Admin::UsersController < ApplicationController
|
class Admin::UsersController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
load_and_authorize_resource :except => :create
|
load_and_authorize_resource
|
||||||
authorize_resource :only => :create
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@filter = params[:filter] || 'all'
|
@filter = params[:filter] || 'all'
|
||||||
|
@ -12,14 +11,13 @@ class Admin::UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@user = User.new params[:user]
|
|
||||||
@user.role = params[:role]
|
@user.role = params[:role]
|
||||||
@user.uname = params[:uname]
|
|
||||||
if @user.save
|
if @user.save
|
||||||
flash[:notice] = t('flash.user.saved')
|
flash[:notice] = t('flash.user.saved')
|
||||||
redirect_to users_path
|
redirect_to users_path
|
||||||
else
|
else
|
||||||
flash[:error] = t('flash.user.save_error')
|
flash[:error] = t('flash.user.save_error')
|
||||||
|
flash[:warning] = @user.errors.full_messages.join('. ')
|
||||||
render :action => :new
|
render :action => :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,12 +14,9 @@ class Ability
|
||||||
|
|
||||||
# Shared rights between guests and registered users
|
# Shared rights between guests and registered users
|
||||||
can :forbidden, Platform
|
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
|
can [:publish_build, :status_build, :pre_build, :post_build, :circle_build, :new_bbdt], BuildList
|
||||||
|
|
||||||
if user.guest? # Guest rights
|
if user.guest? # Guest rights
|
||||||
can :create, User
|
|
||||||
can [:create, :show_message], RegisterRequest
|
can [:create, :show_message], RegisterRequest
|
||||||
else # Registered user rights
|
else # Registered user rights
|
||||||
if user.admin?
|
if user.admin?
|
||||||
|
|
|
@ -43,7 +43,7 @@ class User < ActiveRecord::Base
|
||||||
validates :role, :inclusion => {:in => ROLES}, :allow_blank => true
|
validates :role, :inclusion => {:in => ROLES}, :allow_blank => true
|
||||||
validates :language, :inclusion => {:in => LANGUAGES}, :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
|
:site, :company, :professional_experience, :location, :avatar
|
||||||
attr_readonly :uname, :own_projects_count
|
attr_readonly :uname, :own_projects_count
|
||||||
attr_accessor :login
|
attr_accessor :login
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
.content
|
.content
|
||||||
%h2.title= t("layout.users.new_header")
|
%h2.title= t("layout.users.new_header")
|
||||||
.inner
|
.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}
|
= render :partial => "users/form", :locals => {:f => f}
|
||||||
|
|
||||||
- content_for :sidebar do
|
- content_for :sidebar do
|
||||||
.bordered.nopadding
|
.bordered.nopadding
|
||||||
= render 'admin/submenu'
|
|
||||||
|
= render 'admin/submenu'
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
.leftlist
|
.leftlist
|
||||||
= f.label :uname, t("activerecord.attributes.user.uname")
|
= f.label :uname, t("activerecord.attributes.user.uname")
|
||||||
.rightlist
|
.rightlist
|
||||||
= f.text_field :uname, :name => 'uname'
|
= f.text_field :uname
|
||||||
.leftlist
|
.leftlist
|
||||||
= f.label :password, t("activerecord.attributes.user.password")
|
= f.label :password, t("activerecord.attributes.user.password")
|
||||||
.rightlist
|
.rightlist
|
||||||
|
|
|
@ -10,7 +10,7 @@ Rosa::Application.routes.draw do
|
||||||
get '/users' => 'admin/users#index', :as => :users
|
get '/users' => 'admin/users#index', :as => :users
|
||||||
get '/users/new' => 'admin/users#new', :as => :new_user
|
get '/users/new' => 'admin/users#new', :as => :new_user
|
||||||
get '/users/list' => 'admin/users#list', :as => :users_list
|
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
|
get '/users/:id/edit' => 'admin/users#profile', :as => :edit_user
|
||||||
put '/users/:id/edit' => 'admin/users#update', :as => :update_user
|
put '/users/:id/edit' => 'admin/users#update', :as => :update_user
|
||||||
delete '/users/:id/delete' => 'admin/users#destroy', :as => :delete_user
|
delete '/users/:id/delete' => 'admin/users#destroy', :as => :delete_user
|
||||||
|
|
Loading…
Reference in New Issue