From 5c79d3752420c391b3e60ca237c0c490e6793131 Mon Sep 17 00:00:00 2001 From: Ahmad Farhat Date: Wed, 7 Oct 2020 11:23:19 -0400 Subject: [PATCH] GRN2-xx: Added a tab that displays invited users when using Join by Invitation (#2162) * Added a tab that displays invited users when using Join by Invitation * Made search work --- app/controllers/admins_controller.rb | 11 +- app/controllers/concerns/populator.rb | 11 ++ app/models/invitation.rb | 9 ++ .../components/_invited_users_table.html.erb | 49 +++++++ .../components/_manage_users_table.html.erb | 122 ++++++++++++++++ .../components/_manage_users_tags.html.erb | 9 +- app/views/admins/components/_users.html.erb | 133 ++---------------- config/locales/en.yml | 2 + 8 files changed, 216 insertions(+), 130 deletions(-) create mode 100644 app/views/admins/components/_invited_users_table.html.erb create mode 100644 app/views/admins/components/_manage_users_table.html.erb diff --git a/app/controllers/admins_controller.rb b/app/controllers/admins_controller.rb index 24f6d91d..dbe8ef00 100644 --- a/app/controllers/admins_controller.rb +++ b/app/controllers/admins_controller.rb @@ -40,9 +40,14 @@ class AdminsController < ApplicationController @tab = params[:tab] || "active" @role = params[:role] ? Role.find_by(name: params[:role], provider: @user_domain) : nil - @user_list = merge_user_list + if @tab == "invited" + users = invited_users_list + else + users = manage_users_list + @user_list = merge_user_list + end - @pagy, @users = pagy(manage_users_list) + @pagy, @users = pagy(users) end # GET /admins/site_settings @@ -133,7 +138,7 @@ class AdminsController < ApplicationController send_invitation_email(current_user.name, email, invitation.invite_token) end - redirect_to admins_path + redirect_back fallback_location: admins_path end # GET /admins/reset diff --git a/app/controllers/concerns/populator.rb b/app/controllers/concerns/populator.rb index 0b0cd743..59e2b9d7 100644 --- a/app/controllers/concerns/populator.rb +++ b/app/controllers/concerns/populator.rb @@ -85,4 +85,15 @@ module Populator return initial_list unless Rails.configuration.loadbalanced_configuration initial_list.where(provider: @user_domain) end + + # Returns a list off all current invitations + def invited_users_list + list = if Rails.configuration.loadbalanced_configuration + Invitation.where(provider: @user_domain) + else + Invitation.all + end + + list.admins_search(@search).order(updated_at: :desc) + end end diff --git a/app/models/invitation.rb b/app/models/invitation.rb index b1e36afb..20b05ad1 100644 --- a/app/models/invitation.rb +++ b/app/models/invitation.rb @@ -20,4 +20,13 @@ class Invitation < ApplicationRecord has_secure_token :invite_token scope :valid, -> { where(updated_at: (Time.now - 48.hours)..Time.now) } + + def self.admins_search(string) + return all if string.blank? + + search_query = "email LIKE :search" + + search_param = "%#{sanitize_sql_like(string)}%" + where(search_query, search: search_param) + end end diff --git a/app/views/admins/components/_invited_users_table.html.erb b/app/views/admins/components/_invited_users_table.html.erb new file mode 100644 index 00000000..dc0b2671 --- /dev/null +++ b/app/views/admins/components/_invited_users_table.html.erb @@ -0,0 +1,49 @@ +
+
+
+
+ + + + + + + + + + <% if @users %> + <% @users.each do |user| %> + + + + + + <% end %> + <% end %> + +
+ <%= t("email") %> + + <%= t("administrator.users.table.time") %> + + <%= t("administrator.users.table.valid") %> +
+
<%= user.email %>
+
+
<%= friendly_time(user.updated_at) %>
+
+
+ <% if ((Time.now - 48.hours)..Time.now).cover?(user.updated_at) %> + + <% else %> + + <% end %> +
+
+
+ <%== pagy_bootstrap_nav(@pagy) %> +
+
+
+
+
\ No newline at end of file diff --git a/app/views/admins/components/_manage_users_table.html.erb b/app/views/admins/components/_manage_users_table.html.erb new file mode 100644 index 00000000..f4d00db3 --- /dev/null +++ b/app/views/admins/components/_manage_users_table.html.erb @@ -0,0 +1,122 @@ +
+
+
+
+ + + + + + + + + + + + + + + <% if @users %> + <% @users.each do |user| %> + <% if user != current_user %> + + + + + + + + <% end %> + <% end %> + <% else %> + + + + <% end %> + +
"> + <%= t("administrator.users.table.name") %> + <% if @order_column == "name" && @order_direction == "desc" %> + ↓ + <% elsif @order_column == "name" && @order_direction == "asc" %> + ↑ + <% end %> + "> + <%= t("administrator.users.table.username") %> + <% if @order_column == "email" && @order_direction == "desc" %> + ↓ + <% elsif @order_column == "email" && @order_direction == "asc" %> + ↑ + <% end %> + "> + <%= t("administrator.users.table.authenticator") %> + <% if @order_column == "provider" && @order_direction == "desc" %> + ↓ + <% elsif @order_column == "provider" && @order_direction == "asc" %> + ↑ + <% end %> + + <%= t("administrator.users.table.role") %> + +
+
<%= user.name %>
+
<%= [t("administrator.users.table.created"), ": ", user.created_at].join %>
+
<%= user.email && user.email != "" ? user.email : user.username%><%= user.provider %> + <%= render "admins/components/admins_role", role: user.role %> + + <% if !user.has_role?("super_admin") %> + + <% end %> +
+ <%= t("administrator.users.table.no_users") %> +
+
+ <%== pagy_bootstrap_nav(@pagy) %> +
+
+
+
+
\ No newline at end of file diff --git a/app/views/admins/components/_manage_users_tags.html.erb b/app/views/admins/components/_manage_users_tags.html.erb index d3928db6..29fe491a 100644 --- a/app/views/admins/components/_manage_users_tags.html.erb +++ b/app/views/admins/components/_manage_users_tags.html.erb @@ -28,11 +28,16 @@ <%= t("roles.deleted") %> - - <% if admin_invite_registration %> + <% if admin_invite_registration %> + + <%= t("roles.invited") %> + + <%= link_to "#inviteModal", class: "btn btn-primary pt-3", id: "invite-user", "data-toggle": "modal" do %> <%= t("administrator.users.invite") %> <% end %> + <% else %> + <% end %> diff --git a/app/views/admins/components/_users.html.erb b/app/views/admins/components/_users.html.erb index c58adb3e..c34b405f 100644 --- a/app/views/admins/components/_users.html.erb +++ b/app/views/admins/components/_users.html.erb @@ -19,129 +19,12 @@ <%= render "admins/components/admins_tags" %> <% end %> -
-
-
-
- - - - - - - - - - - - - - - <% if @users %> - <% @users.each do |user| %> - <% if user != current_user %> - - - - - - - - <% end %> - <% end %> - <% else %> - - - - <% end %> - -
"> - <%= t("administrator.users.table.name") %> - <% if @order_column == "name" && @order_direction == "desc" %> - ↓ - <% elsif @order_column == "name" && @order_direction == "asc" %> - ↑ - <% end %> - "> - <%= t("administrator.users.table.username") %> - <% if @order_column == "email" && @order_direction == "desc" %> - ↓ - <% elsif @order_column == "email" && @order_direction == "asc" %> - ↑ - <% end %> - "> - <%= t("administrator.users.table.authenticator") %> - <% if @order_column == "provider" && @order_direction == "desc" %> - ↓ - <% elsif @order_column == "provider" && @order_direction == "asc" %> - ↑ - <% end %> - - <%= t("administrator.users.table.role") %> - -
-
<%= user.name %>
-
<%= [t("administrator.users.table.created"), ": ", user.created_at].join %>
-
<%= user.email && user.email != "" ? user.email : user.username%><%= user.provider %> - <%= render "admins/components/admins_role", role: user.role %> - - <% if !user.has_role?("super_admin") %> - - <% end %> -
- <%= t("administrator.users.table.no_users") %> -
-
- <%== pagy_bootstrap_nav(@pagy) %> -
-
-
-
-
+<% if @tab == "invited" %> + <%= render "admins/components/invited_users_table" %> +<% else %> + <%= render "admins/components/manage_users_table" %> + <%= render "shared/modals/delete_account_modal", delete_location: relative_root %> + <%= render "shared/modals/merge_user_modal" %> +<% end %> -<%= render "shared/modals/invite_user_modal" %> -<%= render "shared/modals/delete_account_modal", delete_location: relative_root %> -<%= render "shared/modals/merge_user_modal" %> + <%= render "shared/modals/invite_user_modal" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index dca31006..c14ce71a 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -202,12 +202,14 @@ en: table: authenticator: Authenticator created: Created + time: Time Sent name: Name not_found: No users match your search no_users: No users found role: Role uid: User ID username: Username + valid: Valid title: Manage Users add_to_google_calendar: "Add to Google Calendar" bigbluebutton: BigBlueButton