From a7fce807c56e6ba9074f6b8bc48055b9ece2d279 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Fri, 5 May 2023 18:29:11 +0200 Subject: [PATCH] Add Users#show --- app/assets/stylesheets/application.css | 30 ++++++++++++++++----- app/controllers/users_controller.rb | 10 ++++--- app/views/users/index.html.erb | 17 ++++++------ app/views/users/registrations/edit.html.erb | 10 +++---- app/views/users/show.html.erb | 23 +++++++++++----- config/locales/en.yml | 6 +++-- config/routes.rb | 2 +- test/system/users_test.rb | 8 ++++-- 8 files changed, 68 insertions(+), 38 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 297fbd5..9a389c0 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -250,36 +250,52 @@ table.items { font-size: 0.85rem; margin: 1rem auto 0 auto; } -table.items th { +table.items thead { font-size: 0.8rem; + line-height: 2.2rem; } -table.items th, -table.items tr:hover { +table.items thead, +table.items tbody tr:hover { background-color: #f3f3f3; } table.items th, -table.items td:not(.svg):not(.actions) { - padding: 0.8rem; +table.items td:not(:first-child):not(.actions) { + padding: 0 0.8rem; + text-align: center; } table.items td { border-top: 1px solid #dddddd; + line-height: 2.5rem; + padding: 0; } table.items td a { + color: black; + cursor: pointer; + display: block; + font-weight: normal; + padding: 0 0.8rem; + text-decoration: none; +} +table.items td a:hover { + text-decoration: underline; + text-decoration-thickness: 0.05rem; + text-underline-offset: 0.2rem; +} +table.items td a.image-button { border-color: #dddddd; color: #909090; - font-weight: normal; margin-right: 0.25rem; padding: 0.25rem; } table.items td:not(:first-child) { color: #909090; fill: #909090; - text-align: center; } table.items td.actions { text-align: right; } table.items svg { height: 1.2rem; + vertical-align: middle; width: 1.2rem; } diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 54fd79c..1305292 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,5 @@ class UsersController < ApplicationController - before_action :find_user, only: [:destroy] + before_action :find_user, only: [:show] before_action do raise AccessForbidden unless current_user.at_least(:admin) end @@ -8,9 +8,11 @@ class UsersController < ApplicationController @users = User.all end - # TODO: add #show and #update to change user status - # TODO: remove admin dependent fields from registrations#edit and move them to - # #show + def show + end + + # TODO: add #update to change user status + # TODO: add #become/#revert to change to user view # NOTE: limited actions availabe to :admin by design. Users are meant to # manage their accounts by themselves through registrations. In future :admin diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index b597ae1..30eaff6 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,23 +1,24 @@ -<% if current_user.at_least(:admin) %> - +
+ - + + + <% @users.each do |user| %> - <%# TODO: add user show link %> - + - + <% end %> -
<%= User.human_attribute_name(:email).capitalize %> <%= User.human_attribute_name(:status).capitalize %><%= User.human_attribute_name(:created_at).capitalize %> UTC <%= User.human_attribute_name(:confirmed_at).capitalize %><%= User.human_attribute_name(:created_at).capitalize %> UTC
<%= user.email %><%= link_to user.email, user_path(user) %> <%= user.status %><%= user.created_at.to_fs(:db_without_sec) %> <%= svg_tag "pictograms/checkbox-marked-outline" if user.confirmed_at.present? %> <%= user.created_at.to_fs(:db_without_sec) %>
-<% end %> + + diff --git a/app/views/users/registrations/edit.html.erb b/app/views/users/registrations/edit.html.erb index 6ce52eb..b41f4da 100644 --- a/app/views/users/registrations/edit.html.erb +++ b/app/views/users/registrations/edit.html.erb @@ -1,6 +1,6 @@ <% content_for :navigation, flush: true do %>
- <%= image_link_to t(".back"), "arrow-left-bold-outline", + <%= image_link_to t(:back), "arrow-left-bold-outline", request.referer.present? ? :back : root_url %>
@@ -11,12 +11,6 @@ <% end %> <%= tabular_form_for resource, url: registration_path(resource), html: {method: :patch} do |f| %> - <%= f.select :status, User.statuses, readonly: !current_user.at_least(:admin) %> - - <% if current_user.at_least(:admin) %> - <%= f.text_field :created_at, readonly: true, tabindex: -1 %> - <% end %> - <%= f.email_field :email, size: 30, autofocus: true, autocomplete: "off" %> <% if f.object.pending_reconfirmation? %> <%= f.text_field :unconfirmed_email, readonly: true, tabindex: -1, @@ -24,6 +18,8 @@ timestamp: f.object.confirmation_sent_at.to_fs(:db_without_sec)) %> <% end %> + <%= f.select :status, User.statuses, readonly: true %> + <%= f.password_field :password, size: 30, autocomplete: "off", hint: t('.blank_password_hint_html', subhint: t('.minimum_length_hint_html', count: @minimum_password_length)) %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 673fae2..6f016bb 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,10 +1,19 @@ -

<%= notice %>

+<% content_for :navigation, flush: true do %> +
+ <%= image_link_to t(:back), "arrow-left-bold-outline", users_path %> +
+<% end %> -<%= render @user %> +<%= tabular_form_for @user do |f| %> + <%= f.email_field :email, readonly: true %> + <% if f.object.pending_reconfirmation? %> + <%= f.email_field :unconfirmed_email, readonly: true, + hint: t("users.registrations.edit.unconfirmed_email_hint", + timestamp: f.object.confirmation_sent_at.to_fs(:db_without_sec)) %> + <% end %> -
- <%= link_to "Edit this user", edit_user_path(@user) %> | - <%= link_to "Back to users", users_path %> + <%= f.select :status, User.statuses, readonly: true %> - <%= button_to "Destroy this user", @user, method: :delete %> -
+ <%= f.text_field :created_at, readonly: true %> + <%= f.text_field :confirmed_at, readonly: true %> +<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 21d0987..5cc0d71 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -5,10 +5,12 @@ en: email: e-mail status: status password: password - created_at: registration + created_at: registered confirmed_at: confirmed unconfirmed_email: Awaiting confirmation for users: + index: + become: View as... passwords: edit: new_password: New password @@ -18,7 +20,6 @@ en: new: password_confirmation: Retype password edit: - back: Back confirm_delete: Are you sure you want to delete profile? All data will be irretrievably lost. delete: Delete profile @@ -35,6 +36,7 @@ en: application: users: Users actions: Actions + back: Back or: or profile: Profile register: Register diff --git a/config/routes.rb b/config/routes.rb index 5522cdd..7fafc6c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,7 @@ Rails.application.routes.draw do devise_for :users, path: '', path_names: {registration: 'profile'}, controllers: {registrations: :registrations} - resources :users, only: [:index] + resources :users, only: [:index, :show] devise_scope :user do root to: "devise/sessions#new" diff --git a/test/system/users_test.rb b/test/system/users_test.rb index 3f86f5e..758fe92 100644 --- a/test/system/users_test.rb +++ b/test/system/users_test.rb @@ -96,15 +96,19 @@ class UsersTest < ApplicationSystemTestCase test "show profile" do sign_in user: users.select(&:admin?).select(&:confirmed?).sample click_link t('layouts.application.users') - #all('tr').drop(1).sample.click_link t(:view) + email = all('tr').drop(1).sample.first('a').text + click_link email + assert_current_path user_path(User.find_by_email!(email)) end test "destroy profile" do sign_in user: users.select(&:confirmed?).sample - click_link t(:profile) + # TODO: remove condition after root changed to different path than profile + click_link t(:profile) unless has_current_path?(edit_user_registration_path) assert_difference ->{ User.count }, -1 do accept_confirm { click_link t('users.registrations.edit.delete') } end + assert_current_path new_user_session_path end test "index forbidden for non admin" do