Add user status update

This commit is contained in:
cryptogopher 2023-05-17 23:40:09 +02:00
parent 9ecdd10b2d
commit 9d97eb3f6f
5 changed files with 45 additions and 16 deletions

View File

@ -32,13 +32,17 @@ body {
margin: 0 0.5rem; margin: 0 0.5rem;
} }
input { /* blue - target for interaction with pointer */
/* gray - target for interaction with keyboard */
input,
select {
background-color: white; background-color: white;
border: 1px solid; border: 1px solid;
border-radius: 0.2rem; border-radius: 0.2rem;
border-color: #cccccc; border-color: #cccccc;
} }
input:not([type=checkbox]) { input:not([type=checkbox]),
select {
font-size: 0.9rem; font-size: 0.9rem;
padding: 0.2rem 0.4rem; padding: 0.2rem 0.4rem;
} }
@ -51,8 +55,17 @@ input[type=checkbox] {
width: 1.1rem; width: 1.1rem;
-webkit-appearance: none; -webkit-appearance: none;
} }
input:hover,
select:hover {
border-color: #009ade;
outline: #009ade solid 1px;
}
select:hover {
cursor: pointer;
}
input:focus-visible, input:focus-visible,
input:hover { select:focus-within,
select:focus-visible {
accent-color: #006c9b; accent-color: #006c9b;
background-color: #f3f3f3; background-color: #f3f3f3;
} }
@ -313,7 +326,12 @@ table.items button {
margin-right: 0.25rem; margin-right: 0.25rem;
padding: 0.25rem; padding: 0.25rem;
} }
table.items select:not(:hover),
table.items button:not(:hover) { table.items button:not(:hover) {
border-color: #dddddd; border-color: #dddddd;
color: #909090; color: #909090;
} }
table.items select:focus-within,
table.items select:focus-visible {
color: black;
}

View File

@ -1,7 +1,7 @@
class UsersController < ApplicationController class UsersController < ApplicationController
helper_method :allow_disguise? helper_method :allow_disguise?
before_action :find_user, only: [:show, :disguise] before_action :find_user, only: [:show, :update, :disguise]
before_action except: :revert do before_action except: :revert do
raise AccessForbidden unless current_user.at_least(:admin) raise AccessForbidden unless current_user.at_least(:admin)
end end
@ -16,8 +16,12 @@ class UsersController < ApplicationController
def show def show
end end
def update
@user.update!(params.require(:user).permit(:status))
end
def disguise def disguise
raise ActionController::BadRequest unless allow_disguise?(@user) raise ArgumentError unless allow_disguise?(@user)
session[:revert_to_id] = current_user.id session[:revert_to_id] = current_user.id
bypass_sign_in(@user) bypass_sign_in(@user)
redirect_to root_url redirect_to root_url
@ -29,8 +33,6 @@ class UsersController < ApplicationController
redirect_to users_url redirect_to users_url
end end
# TODO: add #update to change user status
# NOTE: limited actions availabe to :admin by design. Users are meant to # NOTE: limited actions availabe to :admin by design. Users are meant to
# manage their accounts by themselves through registrations. In future :admin # manage their accounts by themselves through registrations. In future :admin
# may be allowed to sing-in as user and make changes there. # may be allowed to sing-in as user and make changes there.

View File

@ -12,16 +12,24 @@
<% @users.each do |user| %> <% @users.each do |user| %>
<tr> <tr>
<td><%= link_to user.email, user_path(user) %></td> <td><%= link_to user.email, user_path(user) %></td>
<td><%= user.status %></td> <td>
<td class="svg"> <% if user == current_user %>
<%= svg_tag "pictograms/checkbox-marked-outline" if user.confirmed_at.present? %> <%= user.status %>
</td> <% else %>
<td><%= user.created_at.to_fs(:db_without_sec) %></td> <%= form_for user do |u| %>
<td class="actions"> <%= u.select :status, User.statuses.keys, {}, onchange: "this.form.submit();" %>
<% if allow_disguise?(user) %> <% end %>
<%= image_button_to t(".disguise"), "incognito", disguise_user_path(user) %>
<% end %> <% end %>
</td> </td>
<td class="svg">
<%= svg_tag "pictograms/checkbox-marked-outline" if user.confirmed_at.present? %>
</td>
<td><%= user.created_at.to_fs(:db_without_sec) %></td>
<td class="actions">
<% if allow_disguise?(user) %>
<%= image_button_to t(".disguise"), "incognito", disguise_user_path(user) %>
<% end %>
</td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>

View File

@ -32,6 +32,7 @@ module FixinMe
# config.eager_load_paths << Rails.root.join("extras") # config.eager_load_paths << Rails.root.join("extras")
config.action_dispatch.rescue_responses['ApplicationController::AccessForbidden'] = :forbidden config.action_dispatch.rescue_responses['ApplicationController::AccessForbidden'] = :forbidden
config.action_dispatch.rescue_responses['ArgumentError'] = :bad_request
# SETUP: Below settings need to be updated on a per-installation basis. # SETUP: Below settings need to be updated on a per-installation basis.
# #

View File

@ -2,7 +2,7 @@ Rails.application.routes.draw do
devise_for :users, path: '', path_names: {registration: 'profile'}, devise_for :users, path: '', path_names: {registration: 'profile'},
controllers: {registrations: :registrations} controllers: {registrations: :registrations}
resources :users, only: [:index, :show] do resources :users, only: [:index, :show, :update] do
member do member do
post :disguise post :disguise
end end