-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3209 from manyfold3d/user-moderation-ui
Add user listings for admins & moderators
- Loading branch information
Showing
10 changed files
with
175 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
module SettingsHelper | ||
def masked_email(email) | ||
email.gsub(/(?<=^.)[^@]*|(?<=@.).*(?=\.[^.]+$)/, "****") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<h3><%= t(".title") %></h3> | ||
|
||
<p class="lead"><%= t(".description") %></p> | ||
|
||
<table class="table table-striped"> | ||
<tr> | ||
<th><%= User.human_attribute_name(:username) %></th> | ||
<th><%= User.human_attribute_name(:email) %></th> | ||
<%= 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? %> | ||
<th><%= User.human_attribute_name(:roles) %></th> | ||
<th></th> | ||
</tr> | ||
<% @users.each do |user| %> | ||
<tr> | ||
<td><%= user.entity.is_a?(User) ? user.entity.username : user.username %></td> | ||
<td><%= user.entity.is_a?(User) ? masked_email(user.entity.email) : nil %></td> | ||
<%= 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? %> | ||
<td><%= user.entity.roles.map(&:name).join(", ") if user.entity.is_a?(User) %></td> | ||
<td><%= link_to safe_join([icon("search", t(".view")), t(".view")], " "), settings_user_path(user.entity), class: "btn btn-primary" %></td> | ||
</tr> | ||
<% end %> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<h3><%= t(".title", username: @user.username) %></h3> | ||
<table class="table table-striped"> | ||
<tr> | ||
<th><%= User.human_attribute_name(:username) %></th> | ||
<td><%= @user.username %></td> | ||
</tr> | ||
<tr> | ||
<th><%= User.human_attribute_name(:email) %></th> | ||
<td><%= @user.email %></td> | ||
</tr> | ||
<tr> | ||
<th><%= User.human_attribute_name(:created_at) %></th> | ||
<td><%= @user.created_at.to_fs(:long) %></td> | ||
</tr> | ||
<tr> | ||
<th><%= User.human_attribute_name(:updated_at) %></th> | ||
<td><%= @user.updated_at.to_fs(:long) %></td> | ||
</tr> | ||
<tr> | ||
<th><%= User.human_attribute_name(:interface_language) %></th> | ||
<td><%= @user.interface_language.present? ? I18nData.languages(@user.interface_language)[@user.interface_language.to_s]&.capitalize : t("devise.registrations.general_settings.interface_language.autodetect") %></td> | ||
</tr> | ||
<% if SiteSettings.oidc_enabled? %> | ||
<tr> | ||
<th><%= User.human_attribute_name(:auth_uid) %></th> | ||
<td><%= (user.auth_uid ? "✅" : "❌") %></td> | ||
</tr> | ||
<% end %> | ||
<% if SiteSettings.federation_enabled? %> | ||
<tr> | ||
<th><%= t("settings.users.index.fediverse_address") %></th> | ||
<td><%= @user.actor.at_address %></td> | ||
</tr> | ||
<% else %> | ||
<tr> | ||
<th><%= User.human_attribute_name(:public_id) %></th> | ||
<td><%= @user.public_id %></td> | ||
</tr> | ||
<% end %> | ||
<tr> | ||
<th><%= User.human_attribute_name(:roles) %></th> | ||
<td><%= @user.roles.map(&:name).join(", ") %></td> | ||
</tr> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "/settings/users", :multiuser do | ||
describe "GET /index", :as_moderator do | ||
it "renders a successful response" do | ||
create(:user) | ||
get "/settings/users" | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe "GET /show", :as_moderator do | ||
it "renders a successful response" do | ||
user = create(:user) | ||
get "/settings/users/#{user.to_param}" | ||
expect(response).to be_successful | ||
end | ||
end | ||
end |