Project

General

Profile

Patch #11057 » 0001-Confirm-admin-flag-change-on-a-separate-page.patch

Alex Shulgin, 2012-05-30 16:44

View differences:

app/controllers/users_controller.rb
layout 'admin'
before_filter :require_admin, :except => :show
before_filter :find_user, :only => [:show, :edit, :update, :destroy, :edit_membership, :destroy_membership]
before_filter :find_user, :only => [:show, :edit, :update, :destroy, :edit_membership, :destroy_membership, :edit_admin, :update_admin]
before_filter :check_self, :only => [:edit_admin, :update_admin]
accept_api_auth :index, :show, :create, :update, :destroy
helper :sort
......
def create
@user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
@user.safe_attributes = params[:user]
@user.admin = params[:user][:admin] || false
@user.admin = false
@user.login = params[:user][:login]
@user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id
......
verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
def update
@user.admin = params[:user][:admin] if params[:user][:admin]
@user.login = params[:user][:login] if params[:user][:login]
if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
@user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
......
end
end
def edit_admin
end
def update_admin
@user.admin = params[:admin] if params[:admin]
if @user.save
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_update)
redirect_to :controller => 'users', :action => 'edit', :id => @user
}
end
end
end
private
def find_user
......
rescue ActiveRecord::RecordNotFound
render_404
end
def check_self
# prevent user from unsetting admin flag on himself
redirect_to(:controller => 'users', :action => 'edit', :id => @user) if @user == User.current
end
end
app/views/users/_form.html.erb
<p><%= custom_field_tag_with_label :user, value %></p>
<% end %>
<p><%= f.check_box :admin, :disabled => (@user == User.current) %></p>
<p>
<%= f.check_box :admin, :disabled => true %>
<%= link_to(l(:button_edit), edit_admin_user_path(@user)) unless @user == User.current %>
</p>
<%= call_hook(:view_users_form, :user => @user, :form => f) %>
</fieldset>
app/views/users/edit_admin.html.erb
<h2><%=l(:label_confirmation)%></h2>
<div class="warning">
<p><strong><%=h @user.login %></strong><br />
<%=l(:text_user_admin_flag_confirmation)%>
<p>
<% form_tag(update_admin_user_path(@user), :method => :post) do %>
<%= hidden_field_tag 'admin', '0' %>
<label><%= check_box_tag 'admin', 1, @user.admin? %> <%= l(:field_admin) %></label>
<%= submit_tag l(:button_save) %>
<% end %>
</p>
</div>
config/locales/en.yml
text_scm_command_version: Version
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
text_user_admin_flag_confirmation: "You can change the administrator flag for this user below:"
default_role_manager: Manager
default_role_developer: Developer
config/routes.rb
map.resources :users, :member => {
:edit_membership => :post,
:destroy_membership => :post
:destroy_membership => :post,
:edit_admin => :get,
:update_admin => :post
}
# For nice "roadmap" in the url for the index action
(1-1/2)