Skip to content

Commit

Permalink
add user details page
Browse files Browse the repository at this point in the history
  • Loading branch information
Floppy committed Nov 20, 2024
1 parent 2f2d574 commit cb302b1
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 4 deletions.
9 changes: 8 additions & 1 deletion app/controllers/settings/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
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
policy_scope(User).find_param(:id)
@user = policy_scope(User).find_param(params[:id])
authorize @user
end

def user_params
Expand Down
6 changes: 3 additions & 3 deletions app/views/settings/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<tr>
<th><%= User.human_attribute_name(:username) %></th>
<th><%= User.human_attribute_name(:email) %></th>
<%= content_tag :th, t(".oidc") if SiteSettings.oidc_enabled? %>
<%= 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>
Expand All @@ -16,11 +16,11 @@
<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.auth_uid? ? "✅" : "❌") if SiteSettings.oidc_enabled? %>
<%= 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("pencil", t("general.edit")), t("general.edit")], " "), settings_user_path(user), class: "btn btn-primary" %></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>
44 changes: 44 additions & 0 deletions app/views/settings/users/show.html.erb
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>
6 changes: 6 additions & 0 deletions config/locales/settings/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,10 @@ en:
success: Settings saved.
users:
index:
description: View and edit registered user accounts.
title: Manage Users
fediverse_address: Fediverse address
local: Local
view: View
show:
title: "User details: %{username}"
10 changes: 10 additions & 0 deletions spec/requests/settings/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@
expect(response).to be_successful
end
end

describe "GET /show" do
it "renders a successful response" do
user = Settings::User.create! valid_attributes
get user_url(user)
expect(response).to be_successful
end
end

describe "GET /new" do
end
4 changes: 4 additions & 0 deletions spec/routing/moderation/users_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
it "routes to #index" do
expect(get: "/settings/users").to route_to("settings/users#index")
end

it "routes to #show" do
expect(get: "/settings/users/1").to route_to("settings/users#show", id: "1")
end
end
end

0 comments on commit cb302b1

Please sign in to comment.