From 9266694d650953b9e2fe994c7821f90ed5b5b9ae Mon Sep 17 00:00:00 2001 From: Oleksandr Turchyn Date: Thu, 24 Oct 2024 20:09:57 +0300 Subject: [PATCH] add integration users page --- app/controllers/users_controller.rb | 6 ++- app/views/users/_bottom_links.html.erb | 14 ++++++ app/views/users/index.html.erb | 33 ++++++------- config/locales/i18n.yml | 25 +++++++--- config/routes.rb | 2 + spec/system/team_settings_spec.rb | 64 +++++++++++++++++++++++++- 6 files changed, 115 insertions(+), 29 deletions(-) create mode 100644 app/views/users/_bottom_links.html.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cf37d24c..80767193 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -9,9 +9,11 @@ class UsersController < ApplicationController def index @users = if params[:status] == 'archived' - @users.archived + @users.archived.where.not(role: 'integration') + elsif params[:status] == 'integration' + @users.active.where(role: 'integration') else - @users.active + @users.active.where.not(role: 'integration') end @pagy, @users = pagy(@users.where(account: current_account).order(id: :desc)) diff --git a/app/views/users/_bottom_links.html.erb b/app/views/users/_bottom_links.html.erb new file mode 100644 index 00000000..e028bb36 --- /dev/null +++ b/app/views/users/_bottom_links.html.erb @@ -0,0 +1,14 @@ +
+ <% if %w[archived integration].include?(params[:status]) %> + <%= link_to t('view_active'), settings_users_path, class: 'link text-sm' %> + <% else %> + <% links = [] %> + <% if current_account.users.active.exists?(role: 'integration') %> + <% links << link_to(t('view_embedding_users'), settings_integration_users_path, class: 'link text-sm') %> + <% end %> + <% if current_account.users.archived.exists? %> + <% links << link_to(t('view_archived'), settings_archived_users_path, class: 'link text-sm') %> + <% end %> + <%= links.join('|').html_safe %> + <% end %> +
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 1171a94d..6d08ecaf 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,12 +1,18 @@
<%= render 'shared/settings_nav' %>
-
+

- <%= t('status_users', status: params[:status].to_s.titleize) %> + <% if params[:status] == 'archived' %> + <%= t('archived_users') %> + <% elsif params[:status] == 'integration' %> + <%= t('embedding_users') %> + <% else %> + <%= t('users') %> + <% end %>

- <% if can?(:create, User.new(account: current_account)) %> + <% if params[:status].blank? && can?(:create, User.new(account: current_account)) %> <%= render 'users/extra_buttons' %> <% if content_for(:add_user_button) %> <%= content_for(:add_user_button) %> @@ -57,17 +63,17 @@ <%= user.last_sign_in_at ? l(user.last_sign_in_at.in_time_zone(current_account.timezone), format: :short, locale: current_account.locale) : '-' %> - <% if can?(:update, user) && user.archived_at.blank? %> + <% if params[:status].blank? && can?(:update, user) && user.archived_at.blank? %> <%= link_to edit_user_path(user), class: 'btn btn-outline btn-xs', title: t('edit'), data: { turbo_frame: 'modal' } do %> <%= t('edit') %> <% end %> <% end %> - <% if params[:status].blank? && can?(:destroy, user) && user != current_user %> + <% if params[:status] != 'archived' && can?(:destroy, user) && user != current_user %> <%= button_to user_path(user), method: :delete, class: 'btn btn-outline btn-error btn-xs', title: t('remove'), data: { turbo_confirm: t('are_you_sure_') } do %> <%= t('remove') %> <% end %> <% end %> - <% if params[:status].present? && can?(:manage, user) && user != current_user %> + <% if params[:status] == 'archived' && can?(:manage, user) && user != current_user && user.archived_at? %> <%= button_to user_path(user), method: :put, params: { user: { archived_at: nil } }, class: 'btn btn-outline btn-xs', title: t('unarchive'), data: { turbo_confirm: t('are_you_sure_') } do %> <%= t('unarchive') %> <% end %> @@ -78,22 +84,11 @@
- <% view_archived_html = capture do %> - <% if current_account.users.archived.exists? %> -
- <% if params[:status] == 'archived' %> - <%= t('view_active') %> - <% else %> - <%= t('view_archived') %> - <% end %> -
- <% end %> - <% end %> <% if @pagy.pages > 1 %> - <%= render 'shared/pagination', pagy: @pagy, items_name: 'users', left_additional_html: view_archived_html %> + <%= render 'shared/pagination', pagy: @pagy, items_name: 'users', left_additional_html: render('bottom_links') %> <% else %>
- <%= view_archived_html %> + <%= render 'bottom_links' %>
<% end %>
diff --git a/config/locales/i18n.yml b/config/locales/i18n.yml index 36a27291..9655b0d9 100644 --- a/config/locales/i18n.yml +++ b/config/locales/i18n.yml @@ -474,7 +474,6 @@ en: &en back: Back add_secret: Add Secret submission_example_payload: Submission example payload - status_users: '%{status} Users' there_are_no_signatures: There are no signatures signed_with_trusted_certificate: Signed with trusted certificate signed_with_external_certificate: Signed with external certificate @@ -619,6 +618,10 @@ en: &en use_international_format_1xxx_: 'Use internatioanl format: +1xxx...' submitter_cannot_be_updated: Submitter cannot be updated. at_least_one_field_must_be_filled: At least one field must be filled. + archived_users: Archived Users + embedding_users: Embedding Users + view_embedding_users: View Embedding Users + view_users: View Users submission_event_names: send_email_to_html: 'Email sent to %{submitter_name}' send_reminder_email_to_html: 'Reminder email sent to %{submitter_name}' @@ -1111,7 +1114,6 @@ es: &es back: Atrás add_secret: Agregar secreto submission_example_payload: Ejemplo de payload de envío - status_users: '%{status} Usuarios' there_are_no_signatures: No hay firmas signed_with_trusted_certificate: Firmado con certificado de confianza signed_with_external_certificate: Firmado con certificado externo @@ -1256,6 +1258,9 @@ es: &es use_international_format_1xxx_: 'Usa el formato internacional: +1xxx...' submitter_cannot_be_updated: El remitente no puede ser actualizado. at_least_one_field_must_be_filled: Al menos un campo debe estar completo. + archived_users: Usuarios Archivados + embedding_users: Usuarios Integrados + view_embedding_users: Ver Usuarios Integrado submission_event_names: send_email_to_html: 'Correo electrónico enviado a %{submitter_name}' send_reminder_email_to_html: 'Correo de recordatorio enviado a %{submitter_name}' @@ -1748,7 +1753,6 @@ it: &it back: Indietro add_secret: Aggiungi segreto submission_example_payload: Esempio di payload di invio - status_users: '%{status} Utenti' there_are_no_signatures: Non ci sono firme signed_with_trusted_certificate: Firmato con certificato affidabile signed_with_external_certificate: Firmato con certificato esterno @@ -1893,6 +1897,9 @@ it: &it use_international_format_1xxx_: 'Utilizza il formato internazionale: +1xxx...' submitter_cannot_be_updated: Il mittente non può essere aggiornato. at_least_one_field_must_be_filled: Almeno un campo deve essere compilato. + archived_users: Utenti Archiviati + embedding_users: Utenti Incorporati + view_embedding_users: Visualizza Utenti Incorporati submission_event_names: send_email_to_html: 'E-mail inviato a %{submitter_name}' send_reminder_email_to_html: 'E-mail di promemoria inviato a %{submitter_name}' @@ -2386,7 +2393,6 @@ fr: &fr back: Retour add_secret: Ajouter un secret submission_example_payload: Exemple de payload de soumission - status_users: '%{status} Utilisateurs' there_are_no_signatures: "Il n'y a pas de signatures" signed_with_trusted_certificate: Signé avec un certificat de confiance signed_with_external_certificate: Signé avec un certificat externe @@ -2531,6 +2537,9 @@ fr: &fr use_international_format_1xxx_: 'Utilizza il formato internazionale: +1xxx...' submitter_cannot_be_updated: Il mittente non può essere aggiornato. at_least_one_field_must_be_filled: Almeno un campo deve essere compilato. + archived_users: Utilisateurs Archivés + embedding_users: Utilisateurs Intégrés + view_embedding_users: Voir les Utilisateurs Intégrés submission_event_names: send_email_to_html: 'E-mail envoyé à %{submitter_name}' send_reminder_email_to_html: 'E-mail de rappel envoyé à %{submitter_name}' @@ -3023,7 +3032,6 @@ pt: &pt back: Voltar add_secret: Adicionar segredo submission_example_payload: Exemplo de payload de submissão - status_users: '%{status} Usuários' there_are_no_signatures: Não há assinaturas signed_with_trusted_certificate: Assinado com certificado confiável signed_with_external_certificate: Assinado com certificado externo @@ -3168,6 +3176,9 @@ pt: &pt use_international_format_1xxx_: 'Use o formato internacional: +1xxx...' submitter_cannot_be_updated: O remetente não pode ser atualizado. at_least_one_field_must_be_filled: Pelo menos um campo deve ser preenchido. + archived_users: Usuários Arquivados + embedding_users: Usuários Incorporados + view_embedding_users: Ver Usuários Incorporados submission_event_names: send_email_to_html: 'E-mail enviado para %{submitter_name}' send_reminder_email_to_html: 'E-mail de lembrete enviado para %{submitter_name}' @@ -3660,7 +3671,6 @@ de: &de back: Zurück add_secret: Geheimnis hinzufügen submission_example_payload: Beispiel-Payload für Einreichung - status_users: '%{status} Benutzer' there_are_no_signatures: Es gibt keine Unterschriften signed_with_trusted_certificate: Signiert mit vertrauenswürdigem Zertifikat signed_with_external_certificate: Signiert mit externem Zertifikat @@ -3805,6 +3815,9 @@ de: &de use_international_format_1xxx_: 'Verwenden Sie das internationale Format: +1xxx...' submitter_cannot_be_updated: Der Absender kann nicht aktualisiert werden. at_least_one_field_must_be_filled: Mindestens ein Feld muss ausgefüllt werden. + archived_users: Archivierte Benutzer + embedding_users: Einbettende Benutzer + view_embedding_users: Einbettende Benutzer anzeigen submission_event_names: send_email_to_html: 'E-Mail gesendet an %{submitter_name}' send_reminder_email_to_html: 'Erinnerungs-E-Mail gesendet an %{submitter_name}' diff --git a/config/routes.rb b/config/routes.rb index 57f6a830..389d6f50 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -162,6 +162,8 @@ Rails.application.routes.draw do resources :users, only: %i[index] resources :archived_users, only: %i[index], path: 'users/:status', controller: 'users', defaults: { status: :archived } + resources :integration_users, only: %i[index], path: 'users/:status', controller: 'users', + defaults: { status: :integration } resource :personalization, only: %i[show create], controller: 'personalization_settings' resources :api, only: %i[index create], controller: 'api_settings' resource :webhooks, only: %i[show create update], controller: 'webhook_settings' diff --git a/spec/system/team_settings_spec.rb b/spec/system/team_settings_spec.rb index c3c35832..3472917a 100644 --- a/spec/system/team_settings_spec.rb +++ b/spec/system/team_settings_spec.rb @@ -18,13 +18,19 @@ RSpec.describe 'Team Settings' do visit settings_users_path end - it 'shows all users' do + it 'shows only active users' do within '.table' do users.each do |user| expect(page).to have_content(user.full_name) expect(page).to have_content(user.email) - expect(page).to have_no_content(other_user.email) + expect(page).to have_link('Edit', href: edit_user_path(user)) end + + expect(page).to have_button('Remove') + expect(page).to have_no_button('Unarchive') + + expect(page).to have_no_content(other_user.full_name) + expect(page).to have_no_content(other_user.email) end end @@ -89,4 +95,58 @@ RSpec.describe 'Team Settings' do expect(page).to have_no_content('User has been removed') end end + + context 'when some users are archived' do + let!(:users) { create_list(:user, 2, account:) } + let!(:archived_users) { create_list(:user, 2, account:, archived_at: Time.current) } + let!(:other_user) { create(:user) } + + it 'shows only active users' do + visit settings_users_path + + within '.table' do + users.each do |user| + expect(page).to have_content(user.full_name) + expect(page).to have_content(user.email) + end + + archived_users.each do |user| + expect(page).to have_no_content(user.full_name) + expect(page).to have_no_content(user.email) + end + + expect(page).to have_no_content(other_user.full_name) + expect(page).to have_no_content(other_user.email) + end + + expect(page).to have_link('View Archived', href: settings_archived_users_path) + end + + it 'shows only archived users' do + visit settings_archived_users_path + + within '.table' do + archived_users.each do |user| + expect(page).to have_content(user.full_name) + expect(page).to have_content(user.email) + expect(page).to have_no_link('Edit', href: edit_user_path(user)) + end + + users.each do |user| + expect(page).to have_no_content(user.full_name) + expect(page).to have_no_content(user.email) + expect(page).to have_no_link('Edit', href: edit_user_path(user)) + end + + expect(page).to have_button('Unarchive') + expect(page).to have_no_button('Remove') + + expect(page).to have_no_content(other_user.full_name) + expect(page).to have_no_content(other_user.email) + end + + expect(page).to have_content('Archived Users') + expect(page).to have_link('View Active', href: settings_users_path) + end + end end