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,4 +1,4 @@
class OrganizationsController < ApplicationController
class Admin::OrganizationsController < Admin::ApplicationController
before_action :require_owner

def edit
Expand All @@ -9,7 +9,7 @@ def update
@organization = Current.organization

if @organization.update(organization_params)
redirect_to edit_organization_path, notice: "Organization updated."
redirect_to edit_admin_organization_path, notice: "Organization updated."
else
render :edit, status: :unprocessable_entity
end
Expand Down
8 changes: 8 additions & 0 deletions app/views/admin/dashboards/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,13 @@
<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 %>

<% if owner? %>
<%= link_to edit_admin_organization_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">Organization</h2>
<p class="mt-1 text-sm text-ink-soft">Update your organization's name and logo.</p>
<% end %>
<% end %>
</div>
</div>
3 changes: 0 additions & 3 deletions app/views/admin/organization_memberships/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<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,
Expand Down
38 changes: 38 additions & 0 deletions app/views/admin/organizations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<% content_for :title, "Organization settings" %>

<div class="mx-auto max-w-xl w-full px-6 py-10">
<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">Organization settings</h1>
<p class="mt-1 text-sm text-ink-soft">
Update the name and logo for <%= Current.organization.name %>. Only owners can make these changes.
</p>

<%= form_with model: @organization, url: admin_organization_path, method: :patch, class: "contents" do |form| %>
<% if @organization.errors.any? %>
<p class="mt-5 py-2 px-3 bg-danger-tint text-danger font-medium rounded-lg inline-block">
<%= @organization.errors.full_messages.to_sentence %>
</p>
<% end %>

<div class="mt-6">
<%= form.label :name, "Name", class: "block text-ink-soft" %>
<%= form.text_field :name,
class: "mt-2 block w-full rounded-md border border-line bg-surface px-3 py-2 shadow-sm focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/10" %>
</div>

<div class="mt-6">
<%= form.label :logo, "Logo", class: "block text-ink-soft" %>
<% if @organization.logo.attached? %>
<div class="mt-2 mb-1">
<%= image_tag url_for(@organization.logo), alt: "#{@organization.name} logo", class: "h-12 w-auto" %>
</div>
<% end %>
<%= form.file_field :logo, accept: "image/*",
class: "mt-2 block w-full text-sm text-ink-soft file:mr-4 file:rounded-md file:border-0 file:bg-accent file:px-3.5 file:py-2 file:font-medium file:text-white hover:file:bg-[#444] file:cursor-pointer" %>
</div>

<div class="mt-6 flex items-center gap-3">
<%= form.submit "Save changes", class: "rounded-md px-3.5 py-2.5 bg-accent hover:bg-[#444] text-white font-medium cursor-pointer transition" %>
</div>
<% end %>
</div>
47 changes: 0 additions & 47 deletions app/views/organizations/edit.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# Dev-only convenience: sign in as the first user without a password
get "auto_sign_in", to: "auto_sign_in#create" if Rails.env.development?

resource :organization, only: %i[ edit 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 @@ -26,6 +25,7 @@

namespace :admin do
resource :dashboard, only: :show
resource :organization, only: %i[ edit update ]
resources :scenarios, only: :index
resources :allocation_categories, only: %i[ index new create edit update destroy ]
resources :organization_memberships, only: %i[ index update ]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class OrganizationsControllerTest < ActionDispatch::IntegrationTest
class Admin::OrganizationsControllerTest < ActionDispatch::IntegrationTest
setup do
host! "arlington.localhost"
@organization = organizations(:arlington)
Expand All @@ -13,42 +13,42 @@ class OrganizationsControllerTest < ActionDispatch::IntegrationTest

test "owners can view the edit form" do
sign_in_as(@owner)
get edit_organization_path
get edit_admin_organization_path
assert_response :success
end

test "admins are redirected away from the edit form" do
sign_in_as(@admin)
get edit_organization_path
get edit_admin_organization_path
assert_redirected_to root_path
end

test "plain members are redirected away from the edit form" do
sign_in_as(@member)
get edit_organization_path
get edit_admin_organization_path
assert_redirected_to root_path
end

# update

test "an owner can change the organization name" do
sign_in_as(@owner)
patch organization_path, params: { organization: { name: "Renamed Foundation" } }
assert_redirected_to edit_organization_path
patch admin_organization_path, params: { organization: { name: "Renamed Foundation" } }
assert_redirected_to edit_admin_organization_path
assert_equal "Renamed Foundation", @organization.reload.name
end

test "an owner can upload a logo" do
sign_in_as(@owner)
logo = fixture_file_upload("logo.png", "image/png")
patch organization_path, params: { organization: { logo: logo } }
assert_redirected_to edit_organization_path
patch admin_organization_path, params: { organization: { logo: logo } }
assert_redirected_to edit_admin_organization_path
assert @organization.reload.logo.attached?
end

test "a non-owner cannot update the organization" do
sign_in_as(@admin)
patch organization_path, params: { organization: { name: "Hijacked" } }
patch admin_organization_path, params: { organization: { name: "Hijacked" } }
assert_redirected_to root_path
assert_not_equal "Hijacked", @organization.reload.name
end
Expand All @@ -57,14 +57,14 @@ class OrganizationsControllerTest < ActionDispatch::IntegrationTest

test "a super admin can view the edit form for an org they don't belong to" do
sign_in_as(users(:super_admin))
get edit_organization_path
get edit_admin_organization_path
assert_response :success
end

test "a super admin can update an org they don't belong to" do
sign_in_as(users(:super_admin))
patch organization_path, params: { organization: { name: "Renamed by super admin" } }
assert_redirected_to edit_organization_path
patch admin_organization_path, params: { organization: { name: "Renamed by super admin" } }
assert_redirected_to edit_admin_organization_path
assert_equal "Renamed by super admin", @organization.reload.name
end
end
Loading