Skip to content

Commit f96b565

Browse files
committed
edit with role
1 parent 9ea773f commit f96b565

File tree

6 files changed

+22
-15
lines changed

6 files changed

+22
-15
lines changed

app/controllers/auth/panel/users_controller.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
module Auth
22
class Panel::UsersController < Panel::BaseController
3-
before_action :set_user, only: [:show, :edit, :update, :edit_user_tags, :destroy]
3+
before_action :set_user, only: [:show, :edit, :update, :edit_user_tags, :edit_role, :destroy]
44

55
def index
66
q_params = {
77
'created_at-desc': 2
88
}
99
q_params.merge! user_filter_params
1010

11-
@users = User.with_attached_avatar.includes(:accounts, :roles, oauth_users: :app).default_where(q_params).page(params[:page])
11+
@users = User.with_attached_avatar.includes(
12+
:accounts,
13+
:role,
14+
oauth_users: :app
15+
).default_where(q_params).page(params[:page])
1216
end
1317

1418
def month
@@ -28,6 +32,10 @@ def edit_user_tags
2832
@user_tags = UserTag.default_where(default_params).page(params[:page])
2933
end
3034

35+
def edit_role
36+
@roles = Roled::UserRole.all
37+
end
38+
3139
def mock
3240
@user = User.find_or_initialize_by(user_uuid: params[:account])
3341

@@ -68,6 +76,7 @@ def user_permit_params
6876
:avatar,
6977
:password,
7078
:disabled,
79+
:role_id,
7180
user_tag_ids: [],
7281
accounts_attributes: {}
7382
]

app/views/auth/panel/users/_base/_index_tbody.html.erb

+3-10
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,7 @@
4141
<% end %>
4242
</td>
4343
<td>
44-
<div class="tags">
45-
<% model.roles.pluck(:name).each do |role| %>
46-
<span class="tag"><%= role %></span>
47-
<% end %>
48-
</div>
49-
<div>
50-
<%= link_to({ controller: 'roled/panel/whos', action: 'edit', who_type: model.base_class_name, who_id: model.id }, aria: { label: t('roled.panel.whos.edit.title') }, data: { turbo_frame: 'modal' }, class: 'button is-small is-rounded is-light') do %>
51-
<i class="fa-solid fa-user-lock"></i>
52-
<% end %>
53-
</div>
44+
<% if model.role %>
45+
<span class="tag"><%= model.role.name %></span>
46+
<% end %>
5447
</td>

app/views/auth/panel/users/_base/_index_tr.html.erb

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<i class="fa-solid fa-user-tag text-success"></i>
1818
<span class="ml-1"><%= t('.edit_user_tags.title') %></span>
1919
<% end %>
20+
<%= button_to({ action: 'edit_role', id: model.id }, class: 'button is-small is-rounded is-light') do %>
21+
<i class="fa-solid fa-user-lock"></i>
22+
<span class="ml-1"><%= t('.edit_role.title') %></span>
23+
<% end %>
2024
</div>
2125
</td>
2226
</tr>

app/views/auth/panel/users/_edit_modal_form.html.erb app/views/auth/panel/users/_role_form.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<%= render 'modal_header' %>
33
<div class="modal-card-body">
44
<%= render 'error_messages', target: @user %>
5-
<%= f.collection_check_boxes :role_ids, @roles, :id, :name %>
5+
<%= f.collection_radio_buttons :role_id, @roles, :id, :name %>
66
</div>
77
<%= f.submit %>
88
<% end %>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<%= turbo_stream.append 'body', partial: 'user_tags_form', layout: 'modal_form' %>
1+
<%= turbo_stream.append 'body', partial: 'role_form', layout: 'modal_form' %>

config/locales/zh.controller.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ zh:
7878
users:
7979
index:
8080
title: 用户列表
81-
role: 角色设置
8281
edit_user_tags:
8382
title: 用户标签
83+
edit_role:
84+
title: 权限管理
8485
accounts:
8586
index:
8687
title: 账号

0 commit comments

Comments
 (0)