user can't delete self and flash_messages
This commit is contained in:
parent
318c264cae
commit
e62df90117
|
@ -22,6 +22,7 @@ class Panel::UsersController < ApplicationController
|
|||
def create
|
||||
@user = User.new(params[:user])
|
||||
if @user.save
|
||||
flash[:notice] = t('panel.create_success_user')
|
||||
redirect_to :action => :index
|
||||
else
|
||||
render :action => :new
|
||||
|
@ -43,6 +44,7 @@ class Panel::UsersController < ApplicationController
|
|||
@user.avatar = params[:file] if params[:file]
|
||||
|
||||
if @user.update_attributes(params[:user])
|
||||
flash[:notice] = t('panel.update_success_user')
|
||||
redirect_to :action => :index
|
||||
else
|
||||
@user_info_models = UserInfoModel.all.entries
|
||||
|
@ -52,8 +54,12 @@ class Panel::UsersController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
if params[:id].eql?(session['warden.user.user.key'][1].to_s)
|
||||
flash[:error] = t('panel.cant_delete_self')
|
||||
else
|
||||
@user = User.find(params[:id])
|
||||
@user.destroy
|
||||
end
|
||||
|
||||
redirect_to :action => :index
|
||||
end
|
||||
|
|
|
@ -1,11 +1,31 @@
|
|||
module ApplicationHelper
|
||||
|
||||
FLASH_NOTICE_KEYS = [:error, :notice, :warning]
|
||||
|
||||
def colorize_in_use_locale(locale)
|
||||
@site_in_use_locales.include?(locale)? 'green' : 'red'
|
||||
end
|
||||
|
||||
def flash_messages
|
||||
return unless messages = flash.keys.select{|k| FLASH_NOTICE_KEYS.include?(k)}
|
||||
formatted_messages = messages.map do |type|
|
||||
content_tag :div, :class => type.to_s do
|
||||
message_for_item(flash[type], flash["#{type}_item".to_sym])
|
||||
end
|
||||
end
|
||||
raw(formatted_messages.join)
|
||||
end
|
||||
|
||||
def link_back
|
||||
link_to t('back'), session[:last_page]
|
||||
end
|
||||
|
||||
def message_for_item(message, item = nil)
|
||||
if item.is_a?(Array)
|
||||
message % link_to(*item)
|
||||
else
|
||||
message % item
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
</ul>
|
||||
<% end -%>
|
||||
|
||||
<%= flash_messages %>
|
||||
|
||||
<h1><%= t('admin.list_items') %>: <%= show_parent_items_link unless @parent_item.nil? %></h1>
|
||||
|
||||
<% if !Layout.exist_one? %>
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
</ul>
|
||||
<% end -%>
|
||||
|
||||
<%= flash_messages %>
|
||||
|
||||
<h1><%= t('admin.list_layouts') %></h1>
|
||||
|
||||
<table>
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
</fieldset>
|
||||
<% end %>
|
||||
|
||||
<%= hidden_field_tag :active_roles, @user.active_roles.size > 0 %>
|
||||
<%= hidden_field_tag :active_roles, (@user.active_roles.size > 0 rescue nil ) %>
|
||||
<% if @user_role_models %>
|
||||
<fieldset id="roles" <%= raw(' style="display: none;"') unless (@user.active_roles.size > 0 rescue nil) %>>
|
||||
<legend><%= t('panel.roles') %></legend>
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
</ul>
|
||||
<% end -%>
|
||||
|
||||
<%= flash_messages %>
|
||||
|
||||
<h1><%= t('panel.list_users') %></h1>
|
||||
|
||||
<table>
|
||||
|
@ -14,15 +16,16 @@
|
|||
<th><%= t('panel.action') %></th>
|
||||
</tr>
|
||||
|
||||
<% @users.each do |user| %>
|
||||
<tr>
|
||||
<% @users.each do |user| %>
|
||||
<tr>
|
||||
<td><%= user.get_roles %></td>
|
||||
<td><%= user[:name] %></td>
|
||||
<td><%= user.email %></td>
|
||||
<td>
|
||||
<%= link_to t(:show), panel_user_path(user) %> |
|
||||
<%= link_to t(:edit), edit_panel_user_path(user) %> |
|
||||
<%= link_to t(:delete), panel_user_path(user), :method => :delete %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<%= link_to t(:delete), panel_user_path(user), :confirm => t('sure?'), :method => :delete %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
|
|
@ -97,6 +97,8 @@ en:
|
|||
|
||||
panel:
|
||||
action: Action
|
||||
cant_delete_self: You can not delete yourself.
|
||||
create_success_user: User was successfully created.
|
||||
email: Email
|
||||
home: Home
|
||||
list_users: Users list
|
||||
|
@ -105,5 +107,6 @@ en:
|
|||
new_user: New user
|
||||
infos: Information
|
||||
roles: Roles
|
||||
update_success_user: User was successfully updated.
|
||||
user: User
|
||||
user_panel: User panel
|
||||
|
|
|
@ -94,6 +94,8 @@ zh_tw:
|
|||
|
||||
panel:
|
||||
action: 行動
|
||||
cant_delete_self: 您不可以刪除自己。
|
||||
create_success_user: 用戶已成功創建。
|
||||
email: Email
|
||||
home: 首頁
|
||||
list_users: 使用清單
|
||||
|
@ -102,6 +104,7 @@ zh_tw:
|
|||
new_user: 新增使用
|
||||
infos: 資料
|
||||
roles: 角色
|
||||
update_success_user: 用戶已成功更新。
|
||||
user: 用戶
|
||||
user_panel: 用戶面板
|
||||
|
||||
|
|
|
@ -10,3 +10,15 @@ ul.list li{
|
|||
list-style:none;
|
||||
border-bottom:1px solid #ccc;
|
||||
}
|
||||
|
||||
.error{
|
||||
color:red;
|
||||
}
|
||||
|
||||
.notice, .message{
|
||||
color:green;
|
||||
}
|
||||
|
||||
.warning{
|
||||
color:orange;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue