Change and fix role assign logic and abilities. Other minor fixes. Refs #2261

This commit is contained in:
Pavel Chipiga 2011-11-21 21:06:34 +02:00
parent b98453bd62
commit 366ca320e0
6 changed files with 10 additions and 12 deletions

View File

@ -35,7 +35,7 @@ class UsersController < ApplicationController
end end
def update def update
@user.role = params[:user][:role] if current_user.admin? @user.role = params[:user][:role]
if @user.update_attributes(params[:user]) if @user.update_attributes(params[:user])
flash[:notice] = t('flash.user.saved') flash[:notice] = t('flash.user.saved')
redirect_to users_path redirect_to users_path

View File

@ -27,8 +27,7 @@ class Ability
can :index, AutoBuildList can :index, AutoBuildList
# If rules goes one by one CanCan joins them by 'OR' sql operator # If rules goes one by one CanCan joins them by 'OR' sql operator
can :read, Project, :visibility => 'open' can :read, Project, :visibility => 'open'
# User can read and edit his profile: can :read, User
can :manage, User, :id => user.id
can :manage_collaborators, Project do |project| can :manage_collaborators, Project do |project|
project.relations.exists? :object_id => user.id, :object_type => 'User', :role => 'admin' project.relations.exists? :object_id => user.id, :object_type => 'User', :role => 'admin'
end end

View File

@ -30,12 +30,6 @@
.right .right
= f.text_area :ssh_key, :class => "text_area" = f.text_area :ssh_key, :class => "text_area"
.group.wat-cf
.left
= f.label :role, t("activerecord.attributes.user.role"), :class => :label
.right
= f.select :role, User::ROLES.push("")
/ .group.wat-cf / .group.wat-cf
/ .left / .left
/ = f.label :current_password, :class => "label" / = f.label :current_password, :class => "label"

View File

@ -7,6 +7,9 @@
.group .group
= f.label :email, t("activerecord.attributes.user.email"), :class => :label = f.label :email, t("activerecord.attributes.user.email"), :class => :label
= f.text_field :email, :class => 'text_field' = f.text_field :email, :class => 'text_field'
.group
= f.label :role, t("activerecord.attributes.user.role"), :class => :label
= f.select :role, User::ROLES, :include_blank => true
.group .group
= f.label :ssh_key, t("activerecord.attributes.user.ssh_key"), :class => :label = f.label :ssh_key, t("activerecord.attributes.user.ssh_key"), :class => :label
= f.text_area :ssh_key, :class => 'text_area' = f.text_area :ssh_key, :class => 'text_area'

View File

@ -27,8 +27,10 @@
\: \:
= @user.created_at = @user.created_at
.wat-cf .wat-cf
= link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_user_path(@user), :class => "button" - if can? :edit, @user
= link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), user_path(@user), :method => "delete", :class => "button", :confirm => t("layout.users.confirm_delete") = link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_user_path(@user), :class => "button"
- if can? :destroy, @user
= link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), user_path(@user), :method => "delete", :class => "button", :confirm => t("layout.users.confirm_delete")
.block .block
.secondary-navigation .secondary-navigation

View File

@ -536,7 +536,7 @@ ru:
uname: Никнейм uname: Никнейм
ssh_key: SSH ключ ssh_key: SSH ключ
current_password: Текущий пароль current_password: Текущий пароль
roles: Роли role: Роль
created_at: Создан created_at: Создан
updated_at: Обновлен updated_at: Обновлен
global_role: Роль в системе global_role: Роль в системе