Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class OrganizationMembershipsController < ApplicationController
class Admin::OrganizationMembershipsController < Admin::ApplicationController
PER_PAGE = 50

before_action :require_member_management
before_action :set_membership, only: :update

def index
Expand All @@ -19,17 +18,12 @@ def index

def update
OrganizationMembership::RoleUpdater.new(@membership, actor: Current.user, role: params[:role]).call
redirect_to organization_memberships_path(q: params[:q], roles: params[:roles], page: params[:page])
redirect_to admin_organization_memberships_path(q: params[:q], roles: params[:roles], page: params[:page])
end

private

def set_membership
@membership = Current.organization.organization_memberships.find(params[:id])
end

def require_member_management
redirect_to root_path, alert: "You don't have access to that." unless
Current.user.admin_of?(Current.organization)
end
end
2 changes: 1 addition & 1 deletion app/helpers/scenarios_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ScenariosHelper
CHART_COLORS = ["#E07B39", "#D9632B", "#C99A2E", "#B8842B", "#E0954F", "#C76A28"].freeze
CHART_COLORS = [ "#E07B39", "#D9632B", "#C99A2E", "#B8842B", "#E0954F", "#C76A28" ].freeze

def allocation_chart_color(index)
CHART_COLORS[index % CHART_COLORS.length]
Expand Down
6 changes: 6 additions & 0 deletions app/views/admin/dashboards/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@
<h2 class="text-lg font-semibold text-ink">Allocation categories</h2>
<p class="mt-1 text-sm text-ink-soft">Manage the categories used in allocations.</p>
<% end %>

<%= link_to admin_organization_memberships_path,
class: "block rounded-lg border border-line bg-surface p-5 hover:bg-surface-soft transition" do %>
<h2 class="text-lg font-semibold text-ink">Members</h2>
<p class="mt-1 text-sm text-ink-soft">View and manage who belongs to the organization.</p>
<% end %>
</div>
</div>
92 changes: 92 additions & 0 deletions app/views/admin/organization_memberships/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<% content_for :title, "Members" %>

<div class="mx-auto max-w-6xl w-full px-6 py-10">
<div class="flex flex-wrap items-end justify-between gap-4 border-b border-line pb-5">
<div>
<p class="text-xs font-semibold uppercase tracking-wider text-ink-faint">Admin</p>
<h1 class="mt-1 text-2xl font-semibold tracking-tight text-ink">Members</h1>
<% if owner? %>
<%= link_to "Edit organization", edit_organization_path, class: "mt-1 inline-block text-sm text-ink-soft hover:text-ink hover:underline" %>
<% end %>
</div>
<div class="flex flex-wrap items-center gap-x-5 gap-y-3">
<%= form_with url: admin_organization_memberships_path, method: :get,
data: { controller: "debounced-form", action: "input->debounced-form#submit change->debounced-form#submit",
turbo_frame: "memberships_list", turbo_action: "advance" } do |form| %>
<div class="flex flex-wrap items-center gap-x-5 gap-y-3">
<%= form.search_field :q, value: @query,
placeholder: "Filter by member…", autocomplete: "off",
class: "block w-64 rounded-md border border-line bg-surface px-3 py-1.5 text-sm text-ink placeholder:text-ink-faint focus:border-ink-soft focus:outline-none" %>
<div class="flex items-center gap-4 text-sm text-ink-soft">
<% %w[owner admin member].each do |role| %>
<label class="inline-flex cursor-pointer items-center gap-1.5">
<%= check_box_tag "roles[]", role, @roles.include?(role),
id: "role_#{role}", class: "rounded border-line text-brand focus:ring-brand" %>
<%= role.capitalize %>
</label>
<% end %>
</div>
</div>
<% end %>
</div>
</div>

<%= turbo_frame_tag "memberships_list", class: "mt-5 block", data: { turbo_action: "advance" } do %>
<div class="overflow-hidden rounded-lg border border-line">
<table class="w-full text-left text-sm">
<thead class="bg-surface-soft">
<tr class="border-b border-line">
<th class="px-4 py-2.5 text-xs font-semibold uppercase tracking-wide text-ink-faint">Member</th>
<th class="px-4 py-2.5 text-xs font-semibold uppercase tracking-wide text-ink-faint">Role</th>
<th class="px-4 py-2.5 text-right text-xs font-semibold uppercase tracking-wide text-ink-faint">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-line-soft">
<% @memberships.each do |membership| %>
<tr class="bg-surface hover:bg-surface-soft transition">
<td class="px-4 py-2.5">
<p class="font-medium text-ink"><%= membership.user.display_name %></p>
<% if membership.user.name.present? %>
<p class="text-ink-soft"><%= membership.user.email_address %></p>
<% end %>
</td>
<td class="px-4 py-2.5 text-ink-soft"><%= membership.role.capitalize %></td>
<td class="px-4 py-2.5 text-right">
<% if membership.member? %>
<%= button_to "Make admin", admin_organization_membership_path(membership), method: :patch, params: { role: "admin", q: @query, roles: @roles, page: @page },
class: "text-brand hover:underline cursor-pointer bg-transparent p-0" %>
<% elsif membership.admin? && owner? %>
<%= button_to "Make member", admin_organization_membership_path(membership), method: :patch, params: { role: "member", q: @query, roles: @roles, page: @page },
class: "text-ink-soft hover:underline cursor-pointer bg-transparent p-0" %>
<% else %>
<span class="text-ink-faint">—</span>
<% end %>
</td>
</tr>
<% end %>
<% if @total.zero? %>
<tr class="bg-surface">
<td colspan="3" class="px-4 py-12 text-center text-ink-faint">
<%= @query.present? || @roles.any? ? "No members match your filters." : "No members yet." %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>

<% if @total.positive? %>
<div class="mt-3 flex items-center justify-between text-xs text-ink-soft">
<span class="tabular-nums">Showing <%= @offset + 1 %>–<%= @offset + @memberships.size %> of <%= @total %></span>
<div class="flex items-center gap-2">
<% if @page > 1 %>
<%= link_to "← Prev", admin_organization_memberships_path(q: @query, roles: @roles, page: @page - 1), class: "rounded border border-line px-2.5 py-1 text-ink-soft hover:bg-surface-soft hover:text-ink" %>
<% end %>
<% if @has_more %>
<%= link_to "Next →", admin_organization_memberships_path(q: @query, roles: @roles, page: @page + 1), class: "rounded border border-line px-2.5 py-1 text-ink-soft hover:bg-surface-soft hover:text-ink" %>
<% end %>
</div>
</div>
<% end %>
<% end %>
</div>
1 change: 0 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
<%= link_to "Explore options", scenarios_path, class: "text-ink-soft hover:text-ink" %>
<% if Current.user&.admin_of?(Current.organization) %>
<%= link_to "Admin Dashboard", admin_dashboard_path, class: "text-ink-soft hover:text-ink" %>
<%= link_to "Members", organization_memberships_path, class: "text-ink-soft hover:text-ink" %>
<% end %>
<%= link_to "Profile", users_profile_path, class: "text-ink-soft hover:text-ink" %>
<%= button_to "Sign out", session_path, method: :delete, class: "text-ink-soft hover:text-ink cursor-pointer" %>
Expand Down
89 changes: 0 additions & 89 deletions app/views/organization_memberships/index.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/organizations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div class="flex items-center gap-3">
<%= form.submit "Save changes",
class: "rounded-md bg-accent px-3.5 py-2 font-medium text-white hover:bg-[#444] transition cursor-pointer" %>
<%= link_to "Back to members", organization_memberships_path, class: "text-ink-soft hover:text-ink" %>
<%= link_to "Back to members", admin_organization_memberships_path, class: "text-ink-soft hover:text-ink" %>
</div>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
get "auto_sign_in", to: "auto_sign_in#create" if Rails.env.development?

resource :organization, only: %i[ edit update ]
resources :organization_memberships, only: %i[ index update ]
resources :scenarios do
resource :name, only: %i[ show edit update ], module: :scenarios
resource :total_giving_amount, only: %i[ show edit update ], module: :scenarios
Expand All @@ -29,6 +28,7 @@
resource :dashboard, only: :show
resources :scenarios, only: :index
resources :allocation_categories, only: %i[ index new create edit update destroy ]
resources :organization_memberships, only: %i[ index update ]
end

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
Expand Down
Loading
Loading