diff --git a/app/controllers/settings/users_controller.rb b/app/controllers/settings/users_controller.rb new file mode 100644 index 000000000..e93f54f88 --- /dev/null +++ b/app/controllers/settings/users_controller.rb @@ -0,0 +1,23 @@ +class Settings::UsersController < ApplicationController + before_action :get_user, except: [:index] + + def index + @users = policy_scope(Federails::Actor).where(entity_type: "User") + render layout: "settings" + end + + def show + render layout: "settings" + end + + private + + def get_user + @user = policy_scope(User).find_param(params[:id]) + authorize @user + end + + def user_params + params.require(:user).permit + end +end diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index ffbedbaf4..f21985b15 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -1,2 +1,5 @@ module SettingsHelper + def masked_email(email) + email.gsub(/(?<=^.)[^@]*|(?<=@.).*(?=\.[^.]+$)/, "****") + end end diff --git a/app/policies/federails/actor_policy.rb b/app/policies/federails/actor_policy.rb new file mode 100644 index 000000000..ded3777b1 --- /dev/null +++ b/app/policies/federails/actor_policy.rb @@ -0,0 +1,27 @@ +class Federails::ActorPolicy < ApplicationPolicy + def index? + all_of( + SiteSettings.multiuser_enabled?, + @user.is_moderator? + ) + end + + def show? + index? + end + + def edit? + index? + end + + def update? + index? + end + + def destroy? + index? + end + + class Scope < ApplicationPolicy::Scope + end +end diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index b7198b237..e074ff7c4 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -1,7 +1,7 @@ class UserPolicy < ApplicationPolicy def index? all_of( - user&.is_administrator?, + user&.is_moderator?, none_of( SiteSettings.demo_mode_enabled? ) @@ -12,7 +12,7 @@ def show? all_of( one_of( user == record, - user&.is_administrator? + user&.is_moderator? ) ) end @@ -22,7 +22,7 @@ def create? SiteSettings.multiuser_enabled?, one_of( SiteSettings.registration_enabled?, - user&.is_administrator? + user&.is_moderator? ), none_of( SiteSettings.demo_mode_enabled? @@ -41,7 +41,7 @@ def destroy? all_of( one_of( user == record, - user&.is_administrator? + user&.is_moderator? ), SiteSettings.multiuser_enabled?, none_of( diff --git a/app/views/layouts/settings.html.erb b/app/views/layouts/settings.html.erb index 3bcde304b..c6a441770 100644 --- a/app/views/layouts/settings.html.erb +++ b/app/views/layouts/settings.html.erb @@ -9,13 +9,16 @@ <%= link_to t(".libraries"), settings_libraries_path, class: "nav-link" %>
<%= t(".description") %>
+ +<%= User.human_attribute_name(:username) %> | +<%= User.human_attribute_name(:email) %> | + <%= content_tag :th, User.human_attribute_name(:auth_uid) if SiteSettings.oidc_enabled? %> + <%= content_tag :th, t(".local") if SiteSettings.federation_enabled? %> + <%= content_tag :th, t(".fediverse_address") if SiteSettings.federation_enabled? %> +<%= User.human_attribute_name(:roles) %> | ++ |
---|---|---|---|
<%= user.entity.is_a?(User) ? user.entity.username : user.username %> | +<%= user.entity.is_a?(User) ? masked_email(user.entity.email) : nil %> | + <%= content_tag :td, (user.entity.auth_uid ? "✅" : "❌") if SiteSettings.oidc_enabled? %> + <%= content_tag :td, (user.local? ? "✅" : "❌") if SiteSettings.federation_enabled? %> + <%= content_tag :td, user.at_address if SiteSettings.federation_enabled? %> +<%= user.entity.roles.map(&:name).join(", ") if user.entity.is_a?(User) %> | +<%= link_to safe_join([icon("search", t(".view")), t(".view")], " "), settings_user_path(user.entity), class: "btn btn-primary" %> | +
<%= User.human_attribute_name(:username) %> | +<%= @user.username %> | +
---|---|
<%= User.human_attribute_name(:email) %> | +<%= @user.email %> | +
<%= User.human_attribute_name(:created_at) %> | +<%= @user.created_at.to_fs(:long) %> | +
<%= User.human_attribute_name(:updated_at) %> | +<%= @user.updated_at.to_fs(:long) %> | +
<%= User.human_attribute_name(:interface_language) %> | +<%= @user.interface_language.present? ? I18nData.languages(@user.interface_language)[@user.interface_language.to_s]&.capitalize : t("devise.registrations.general_settings.interface_language.autodetect") %> | +
<%= User.human_attribute_name(:auth_uid) %> | +<%= (user.auth_uid ? "✅" : "❌") %> | +
<%= t("settings.users.index.fediverse_address") %> | +<%= @user.actor.at_address %> | +
<%= User.human_attribute_name(:public_id) %> | +<%= @user.public_id %> | +
<%= User.human_attribute_name(:roles) %> | +<%= @user.roles.map(&:name).join(", ") %> | +