Skip to content

Commit

Permalink
Favor links on organizations page (#2008)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwr18 authored Sep 4, 2024
1 parent 5f9899e commit c280836
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 56 deletions.
9 changes: 9 additions & 0 deletions app/components/organizations_index/organizations_index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.OrganizationsIndex-organizationsList {
display: grid;
grid-template-columns: repeat(2, 1fr);
list-style-type: none;
}

.OrganizationsIndex-organizationsList a {
padding-left: 0;
}
22 changes: 22 additions & 0 deletions app/components/organizations_index/organizations_index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%= c 'main', style: :lightestGrayBackground, **attrs do %>
<%= c 'page_header', styles: [:flexboxColumn, :wide, :xlargePaddingTop] do %>
<%= c 'heading' do %>
<%= t('.main_heading', first_name: current_user.first_name) %>
<% end %>
<%= c 'heading', tag: :h2 do %>
<%= t('.heading') %>
<% end %>
<% end %>

<%= c 'section', styles: [:wide, :noSpaceBetween] do %>
<ul class="OrganizationsIndex-organizationsList">
<% organizations.each do |organization| %>
<li>
<%= c 'button', link: organization_dashboard_path(organization), styles: [:plain, :underline] do %>
<%= organization.name %>
<% end %>
</li>
<% end %>
</ul>
<% end %>
<% end %>
14 changes: 14 additions & 0 deletions app/components/organizations_index/organizations_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module OrganizationsIndex
class OrganizationsIndex < ApplicationComponent
def initialize(current_user:, organizations:)
super

@current_user = current_user
@organizations = organizations
end

attr_reader :current_user, :organizations
end
end
13 changes: 0 additions & 13 deletions app/components/set_organization_form/set_organization_form.css

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions app/components/set_organization_form/set_organization_form.rb

This file was deleted.

7 changes: 1 addition & 6 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ class OrganizationsController < ApplicationController
layout 'minimal'

def index
@organizations = Organization.all
end

def set_organization
organization = Organization.find(params[:organization_id])
redirect_to organization_dashboard_path(organization)
@organizations = current_user.admin? ? Organization.all : current_user.organizations
end
end
11 changes: 1 addition & 10 deletions app/views/organizations/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
<%= c 'main', style: :lightestGrayBackground do %>
<%= c 'page_header', styles: [:wide, :inheritBackgroundColor, :xlargePaddingTop, :spaceBetween] do %>
<%= c 'heading' do %>
<%= t ".heading", first_name: current_user.first_name %>
<% end %>
<% end %>


<%= c 'set_organization_form', organizations: @organizations %>
<% end %>
<%= c 'organizations_index', current_user: current_user, organizations: @organizations %>
7 changes: 2 additions & 5 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ de:
heading: "Bist du sicher, dass du „%{request_title}” dauerhaft löschen möchtest?"
cancel: abbrechen
confirm: löschen
set_organization_form:
organizations_index:
main_heading: "Hallo, %{first_name}!"
heading: Bitte wähle eine Organisation aus, um fortzufahren
errors_page:
alt_text: Otter arbeitet an der Lösung des Problems
Expand Down Expand Up @@ -955,7 +956,3 @@ de:
shared:
community: Community
editorial: Redaktion

organizations:
index:
heading: "Hallo, %{first_name}!"
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
concern :paginatable do
get '(page/:page)', action: :index, on: :collection, as: ''
end
post '/set-organization', to: 'organizations#set_organization'

resources :organizations, only: :index

Expand Down
50 changes: 50 additions & 0 deletions spec/requests/organizations_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Organizations' do
let(:organizations) { create_list(:organization, 2) }
let!(:other_organizations) { create_list(:organization, 2) }
let(:admin) { create(:user, admin: true) }

describe 'GET /organizations' do
subject { -> { get organizations_path(as: user) } }

context 'unauthenticated' do
let(:user) { nil }

it 'redirects to the sign in path' do
subject.call
expect(response).to redirect_to(sign_in_path)
end
end

context 'authenticated' do
let(:user) { create(:user, organizations: organizations) }
before { subject.call }

it 'should be successful' do
expect(response).to be_successful
end

it 'displays only the organizations the user belongs to' do
expect(page).to have_css("a[href='#{organization_dashboard_path(organizations.first)}']", text: organizations.first.name)
expect(page).to have_css("a[href='#{organization_dashboard_path(organizations.second)}']", text: organizations.second.name)
expect(page).not_to have_css("a[href='#{organization_dashboard_path(other_organizations.first)}']",
text: other_organizations.first.name)
expect(page).not_to have_css("a[href='#{organization_dashboard_path(other_organizations.second)}']",
text: other_organizations.second.name)
end

context 'user has admin privileges' do
let(:user) { create(:user, admin: true) }

it 'displays all organizations' do
Organization.find_each do |organization|
expect(page).to have_css("a[href='#{organization_dashboard_path(organization)}']", text: organization.name)
end
end
end
end
end
end

0 comments on commit c280836

Please sign in to comment.