diff --git a/app/components/organizations_index/organizations_index.css b/app/components/organizations_index/organizations_index.css new file mode 100644 index 000000000..2347de164 --- /dev/null +++ b/app/components/organizations_index/organizations_index.css @@ -0,0 +1,9 @@ +.OrganizationsIndex-organizationsList { + display: grid; + grid-template-columns: repeat(2, 1fr); + list-style-type: none; +} + +.OrganizationsIndex-organizationsList a { + padding-left: 0; +} diff --git a/app/components/organizations_index/organizations_index.erb b/app/components/organizations_index/organizations_index.erb new file mode 100644 index 000000000..8a04abbbb --- /dev/null +++ b/app/components/organizations_index/organizations_index.erb @@ -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 %> + + <% end %> +<% end %> diff --git a/app/components/organizations_index/organizations_index.rb b/app/components/organizations_index/organizations_index.rb new file mode 100644 index 000000000..45fd79939 --- /dev/null +++ b/app/components/organizations_index/organizations_index.rb @@ -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 diff --git a/app/components/set_organization_form/set_organization_form.css b/app/components/set_organization_form/set_organization_form.css deleted file mode 100644 index 6d09a55df..000000000 --- a/app/components/set_organization_form/set_organization_form.css +++ /dev/null @@ -1,13 +0,0 @@ -.SetOrganizationForm select { - -webkit-appearance: none; - -moz-appearance: none; - - display: block; - width: 100%; - padding: var(--input-padding); - - font-size: inherit; - color: inherit; - border-radius: var(--border-radius); - border: var(--input-border-width) solid var(--color-border); -} diff --git a/app/components/set_organization_form/set_organization_form.html.erb b/app/components/set_organization_form/set_organization_form.html.erb deleted file mode 100644 index c00ef479a..000000000 --- a/app/components/set_organization_form/set_organization_form.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -<%= c 'section', styles: [:wide, :largeBottomMargin], class: 'OrganizationsList', **attrs do %> - <%= c 'heading', tag: :h2 do %> - <%= t('.heading') %> - <% end %> - <%= c 'form', url: set_organization_path, auto_submit: true, allow_blank: true do %> - <%= select_tag "organization_id", options_from_collection_for_select(@organizations, "id", "name"), include_blank: true %> - <% end %> -<% end %> diff --git a/app/components/set_organization_form/set_organization_form.rb b/app/components/set_organization_form/set_organization_form.rb deleted file mode 100644 index d10520c39..000000000 --- a/app/components/set_organization_form/set_organization_form.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module SetOrganizationForm - class SetOrganizationForm < ApplicationComponent - def initialize(organizations:) - super - - @organizations = organizations - end - - attr_reader :organizations - end -end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 4e0244e07..14959e234 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -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 diff --git a/app/views/organizations/index.html.erb b/app/views/organizations/index.html.erb index 0b00453cc..202ac90e9 100644 --- a/app/views/organizations/index.html.erb +++ b/app/views/organizations/index.html.erb @@ -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 %> diff --git a/config/locales/de.yml b/config/locales/de.yml index 6daf485f7..1ffec48b8 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -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 @@ -955,7 +956,3 @@ de: shared: community: Community editorial: Redaktion - - organizations: - index: - heading: "Hallo, %{first_name}!" diff --git a/config/routes.rb b/config/routes.rb index 65b24edad..b3230a6e2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/requests/organizations_spec.rb b/spec/requests/organizations_spec.rb new file mode 100644 index 000000000..15370a6a8 --- /dev/null +++ b/spec/requests/organizations_spec.rb @@ -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