Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.
Ruby agplai-assistantdockerdsgvogdprhotwireissue-trackerjira-alternativeknowledge-basellmmcp-servermeeting-notesopen-sourceproject-managementredmine-alternativeruby-on-railsself-hostedticketingtime-tracking
feat(glossary): add the glossary page with a lane and the menu entry
Guido Boykeb2a3181cba99
diff --git a/.github/workflows/guards.yml b/.github/workflows/guards.ymlindex fc79877..0534884 100644--- a/.github/workflows/guards.yml+++ b/.github/workflows/guards.yml@@ -348,6 +348,7 @@ jobs:spec/models/term_correction_spec.rbspec/requests/organisations/roles_glossary_right_spec.rbspec/services/actors/merge_glossary_terms_spec.rb+ spec/requests/organisations/glossary_spec.rbspec/requests/organisations/people_spec.rbspec/requests/organisations/shown_email_spec.rbspec/requests/user_preferences_email_visibility_spec.rbdiff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.cssindex 7ebee46..29efc9d 100644--- a/app/assets/stylesheets/application.tailwind.css+++ b/app/assets/stylesheets/application.tailwind.css@@ -517,3 +517,35 @@.people-form__hint { @apply text-xs text-muted; }.people-page :is(a, button, input, select, textarea, li[tabindex]):focus-visible { outline: 2px solid rgb(var(--ink)); outline-offset: 2px; }}++/* Glossar (organisations/glossary, K4a): the people page's list and lane+ (people-* above, the wrapper carries people-page too), plus what only a+ glossary has: the status of a term, its heard forms and the merge form. */+@layer components {+ .glossary-tools { @apply gap-3; }+ .glossary-filters { @apply flex flex-wrap items-center gap-2; }+ .glossary-filters__select { @apply w-auto py-1.5 text-[13px]; }+ .glossary-row { @apply items-start; }+ .glossary-row--rejected .people-row__name { @apply text-muted line-through; }+ .glossary-row__head { @apply flex min-w-0 flex-wrap items-center gap-1.5; }+ .glossary-row__origin { @apply text-cream-500; }+ .glossary-row__count { @apply w-10 flex-none self-center text-end text-xs tabular-nums text-muted; }+ .glossary-status { @apply shrink-0 rounded-full px-1.5 text-[11px]; }+ .glossary-status--proposed { border: 1px solid #C08A3E; color: #8A5A1C; }+ .dark .glossary-status--proposed { color: #E0B26E; }+ .glossary-status--rejected { @apply border border-cream-300 text-cream-600; }+ .glossary-status-actions { @apply flex flex-none flex-wrap items-center gap-1.5 self-center; }+ .glossary-heard { @apply flex flex-col gap-3 border-t border-cream-200 pt-4; }+ .glossary-heard__groups { @apply flex flex-col gap-3; }+ .glossary-heard__form { @apply flex items-baseline gap-2 text-sm font-medium text-heading; }+ .glossary-heard__count { @apply text-xs font-normal text-muted; }+ .glossary-heard__list { @apply mt-1 flex flex-col; }+ .glossary-heard__row { @apply flex flex-wrap items-baseline gap-x-3 gap-y-0.5 border-b border-cream-200 py-1.5 text-[13px] text-heading; }+ .glossary-heard__speaker { @apply min-w-[8rem] font-medium; }+ .glossary-heard__origin { @apply min-w-0 flex-1 text-cream-600; }+ .glossary-heard__when { @apply whitespace-nowrap text-xs tabular-nums text-muted; }+ .glossary-merge { @apply flex flex-col gap-1.5 border-t border-cream-200 pt-4; }+ .glossary-merge__label { @apply text-sm font-semibold text-heading; }+ .glossary-merge__row { @apply flex flex-wrap items-center gap-2; }+ .glossary-merge__row select { @apply w-auto min-w-[12rem] flex-1; }+}diff --git a/app/controllers/organisations/glossary_controller.rb b/app/controllers/organisations/glossary_controller.rbnew file mode 100644index 0000000..dd2a8ad--- /dev/null+++ b/app/controllers/organisations/glossary_controller.rb@@ -0,0 +1,298 @@+# frozen_string_literal: true++# The glossary of an organisation (K4a): GlossaryTerm with its heard forms+# (TermCorrection). One page with a lane, the shape of the people directory+# (PeopleController): the terms on the left, a term or the form in the lane+# frame on the right. The address carries the lane state, ?term_id= for a+# term and ?new=term for the form, and the filters (LIST_PARAMS).+#+# show, new and edit answer the lane frame (a row click, the "+",+# "Bearbeiten"); a full visit of them lands on the index with the same lane+# state. The index answers a lane frame request with the lane alone.+#+# Writes go through the glossary actors and leave the frame (_top): they land+# on the list again, with the term open where one is left. A refused save+# renders the index with the form and its reason (422).+#+# Rights: GlossaryPolicy (view_glossary / manage_glossary, account admins+# without a row). A denial answers 403, as on the people page: the page and+# its frame have nothing to show, and a redirect inside the lane frame loops.+# A term of another organisation is no term at all (404). The glossary shows+# heard forms from every project (E3), but the title and the link of a meeting+# only to a reader of that meeting, and the link to a person only with+# view_people (GlossaryHelper).+module Organisations+ class GlossaryController < Organisations::BaseController+ include ViewportSwitchable++ DETAIL_FRAME_ID = 'glossary_term_display_frame'+ LIST_FRAME_ID = 'glossary_results'+ NEW_STATE = 'term'+ # The filters the address, the lane's forms and the writes carry along.+ LIST_PARAMS = %w[project_id category status].freeze++ rescue_from Pundit::NotAuthorizedError, with: :render_forbidden++ # Every action: the lane frames render the phone layout too, and only the+ # address knows which one.+ before_action :set_viewport_mode+ before_action :set_term, except: %i[index new create]++ def index+ authorize GlossaryTerm+ @terms = policy_scope(GlossaryTerm)+ return render_lane_frame if lane_frame_request?++ load_list+ @lane_term = selected_term+ @form_term = new_term if @lane_term.nil? && new_term_requested?+ end++ def show+ authorize @term+ return redirect_to(index_path(term_id: @term.id)) unless turbo_frame_request?++ render_frame(:detail, term: @term)+ end++ def new+ @term = new_term+ authorize @term+ return redirect_to(index_path(new: NEW_STATE)) unless turbo_frame_request?++ render_frame(:form, term: @term)+ end++ def edit+ authorize @term+ return redirect_to(index_path(term_id: @term.id)) unless turbo_frame_request?++ render_frame(:form, term: @term)+ end++ def create+ authorize GlossaryTerm+ save_term(id: nil, flash_key: 'controllers.glossary.create.success')+ end++ def update+ authorize @term+ save_term(id: @term.id, flash_key: 'controllers.glossary.update.success')+ end++ def destroy+ authorize @term+ result = Actors::DestroyGlossaryTerm.call(term: @term, current_user: current_user)+ land(result, notice: 'controllers.glossary.destroy.success', lane: {}, failure_lane: { term_id: @term.id })+ end++ def confirm+ authorize @term+ change_status('confirmed', notice: 'controllers.glossary.confirm.success')+ end++ def reject+ authorize @term+ change_status('rejected', notice: 'controllers.glossary.reject.success')+ end++ # Into the target named by target_id, a term of this glossary found+ # through the policy scope, never a raw id. The lane of the target opens.+ def merge+ authorize @term+ target = merge_target+ return refuse_merge_without_target unless target++ result = Actors::MergeGlossaryTerms.call(source: @term, target: target, current_user: current_user)+ land(result, notice: 'controllers.glossary.merge.success', lane: { term_id: target.id }, failure_lane: { term_id: @term.id })+ end++ # One heard form of this term, learnt wrong. The write right first (403+ # before the heard form is looked up), then only a form of this term.+ def destroy_correction+ authorize @term, :update?+ correction = policy_scope(TermCorrection).where(glossary_term_id: @term.id).find(params[:correction_id])+ authorize correction, :destroy?+ result = Actors::DestroyTermCorrection.call(correction: correction, current_user: current_user)+ land(result, notice: 'controllers.glossary.correction.destroy.success', lane: { term_id: @term.id },+ failure_lane: { term_id: @term.id })+ end++ private++ # The right first (403 without it, before anything is looked up), then+ # through the policy scope: a term of another organisation is no term at+ # all (404).+ def set_term+ authorize GlossaryTerm, :index?+ @term = policy_scope(GlossaryTerm).find(params[:id])+ end++ def save_term(id:, flash_key:)+ result = Actors::SaveGlossaryTerm.call(organisation: current_organisation, params: term_params,+ current_user: current_user, id: id)+ if result.success?+ redirect_to index_path(term_id: result.resource.id), status: :see_other, notice: t(flash_key)+ else+ render_refused_save(result)+ end+ end++ # The index again, with the form open in the lane and the reason above it.+ def render_refused_save(result)+ @terms = policy_scope(GlossaryTerm)+ @form_term = result.resource || new_term+ @form_message = result.errors.to_sentence+ load_list+ render :index, status: :unprocessable_content+ end++ # From the list the list stays as it was; from the lane (term_id sent+ # along) the lane stays open.+ def change_status(status, notice:)+ result = Actors::SetGlossaryTermStatus.call(term: @term, status: status, current_user: current_user)+ lane = params[:term_id] == @term.id ? { term_id: @term.id } : {}+ land(result, notice: notice, lane: lane, failure_lane: lane)+ end++ def land(result, notice:, lane:, failure_lane:)+ if result.success?+ redirect_to index_path(**lane), status: :see_other, notice: t(notice)+ else+ redirect_to index_path(**failure_lane), status: :see_other, alert: result.errors.to_sentence+ end+ end++ def term_params+ params.require(:glossary_term).permit(*Actors::SaveGlossaryTerm::ATTRIBUTES)+ end++ def refuse_merge_without_target+ redirect_to index_path(term_id: @term.id), status: :see_other, alert: t('controllers.glossary.merge.no_target')+ end++ def merge_target+ id = params[:target_id]+ policy_scope(GlossaryTerm).find_by(id: id) if id.is_a?(String) && id.present?+ end++ def new_term+ GlossaryTerm.new(organisation: current_organisation)+ end++ def new_term_requested?+ params[:new] == NEW_STATE && policy(GlossaryTerm).create?+ end++ def selected_term+ id = params[:term_id]+ @terms.find_by(id: id) if id.is_a?(String) && id.present?+ end++ # The terms of the list in their order (open proposals first), with what a+ # row shows of their heard forms: speaker and project, never the meeting.+ # Filtered by status, category and the project a heard form came from.+ def load_list+ @status_counts = @terms.group(:status).count+ @origin_projects = glossary_origin_projects+ @entries = filtered_terms.ordered.includes(term_corrections: %i[project person user]).to_a+ end++ def filtered_terms+ terms = @terms+ terms = terms.where(status: list_state['status']) if list_state['status']+ terms = terms.where(category: list_state['category']) if list_state['category']+ terms = terms.where(id: heard_in_project(list_state['project_id'])) if list_state['project_id']+ terms+ end++ def heard_in_project(project_id)+ policy_scope(TermCorrection).where(project_id: project_id).select(:glossary_term_id)+ end++ # The projects heard forms came from, by name: the choices of the project+ # filter. Their names are part of the glossary (E3), also for a reader+ # who cannot open the project.+ def glossary_origin_projects+ @glossary_origin_projects ||=+ Project.where(id: policy_scope(TermCorrection).where.not(project_id: nil).select(:project_id))+ .order(Arel.sql('LOWER(projects.name)'), :id).pluck(:id, :name)+ end++ def lane_frame_request?+ turbo_frame_request? && request.headers['Turbo-Frame'] == DETAIL_FRAME_ID+ end++ # The lane alone, as a full visit of the same address shows it.+ def render_lane_frame+ term = selected_term+ if term+ render_frame(:detail, term: term)+ elsif new_term_requested?+ render_frame(:form, term: new_term)+ else+ render_frame(:empty)+ end+ end++ def render_frame(state, term: nil)+ render html: helpers.turbo_frame_tag(DETAIL_FRAME_ID) {+ helpers.render(partial: 'organisations/glossary/lane', locals: { state: state, term: term, message: nil })+ }, layout: false+ end++ def render_forbidden+ skip_authorization+ skip_policy_scope+ if turbo_frame_request?+ render html: helpers.turbo_frame_tag(request.headers['Turbo-Frame']) {+ helpers.tag.p(t('shared.errors.not_authorized'), class: 'py-10 text-center text-sm text-muted')+ }, layout: false, status: :forbidden+ else+ render plain: t('shared.errors.not_authorized'), status: :forbidden+ end+ end++ def index_path(**lane)+ organisation_glossary_terms_path(current_organisation, list_state.merge(lane.stringify_keys).compact_blank)+ end++ # The filters of this request (the address, or the hidden fields of a lane+ # form), each one only with a value it knows; anything else is no filter.+ # The phone view rides along (viewport=mobile), as on the people page.+ def list_state+ @list_state ||= begin+ given = request.query_parameters.merge(request.request_parameters)+ state = given.slice(*LIST_PARAMS).select { |_key, value| value.is_a?(String) && value.present? }+ state.delete('status') unless GlossaryTerm::STATUSES.include?(state['status'])+ state.delete('category') unless GlossaryTerm::CATEGORIES.include?(state['category'])+ state.delete('project_id') if state['project_id'] && glossary_origin_projects.none? { |id, _name| id == state['project_id'] }+ state['viewport'] = 'mobile' if given['viewport'] == 'mobile'+ state+ end+ end+ helper_method :list_state++ # Whether a speaker's name may link to the people page (view_people),+ # once per request: the lane asks it for every heard form.+ def glossary_people_linkable?+ return @glossary_people_linkable if defined?(@glossary_people_linkable)++ @glossary_people_linkable = PersonPolicy.view_allowed?(current_user, current_organisation)+ end+ helper_method :glossary_people_linkable?++ # The rows and members the reader may see on the people page+ # (PersonPolicy::Scope, MembershipPolicy::Scope), once per request: a+ # speaker links only to one of them, so the link never opens an empty lane.+ def glossary_visible_person_ids+ @glossary_visible_person_ids ||= policy_scope(Person).pluck(:id).to_set+ end+ helper_method :glossary_visible_person_ids++ def glossary_visible_member_ids+ @glossary_visible_member_ids ||= policy_scope(Membership).where(organisation: current_organisation).pluck(:user_id).to_set+ end+ helper_method :glossary_visible_member_ids+ end+enddiff --git a/app/helpers/glossary_helper.rb b/app/helpers/glossary_helper.rbnew file mode 100644index 0000000..242dd93--- /dev/null+++ b/app/helpers/glossary_helper.rb@@ -0,0 +1,142 @@+# frozen_string_literal: true++# The glossary page (Organisations::GlossaryController): the wiring of its list+# and lane, the words of a term, and what the page shows of a heard form.+#+# What a reader with view_glossary sees (E3): every term with its heard forms,+# speakers and projects, also from projects they cannot read. Two things need+# more: the title and the link of a meeting (read access to that meeting,+# glossary_readable_meetings) and the link to a person (view_people and a row+# the reader may see, glossary_speaker_url).+module GlossaryHelper+ # The one thing a row opens in the lane.+ SELECTION_PARAMS = %w[term_id].freeze+ # The distinct heard forms a row names before "…".+ ROW_FORMS_SHOWN = 4++ # The page wrapper's data: the lane (layout-toggle, index-page) and the+ # desktop/mobile switch, the controllers of the people page+ # (people_page_data).+ def glossary_page_data(viewport_mode:, selected:, form_open:)+ detail_frame_id = Organisations::GlossaryController::DETAIL_FRAME_ID+ unresolved = glossary_unresolved_lane_params(selected: selected, form_open: form_open)+ {+ controller: 'layout-toggle index-page viewport',+ layout_toggle_list_frame_ids_value: [Organisations::GlossaryController::LIST_FRAME_ID].to_json,+ layout_toggle_detail_frame_id_value: detail_frame_id,+ layout_toggle_content_selector_value: '.glossary-content',+ layout_toggle_selected_row_selector_value: '.selected-row[data-glossary-row]',+ layout_toggle_selection_params_value: SELECTION_PARAMS.to_json,+ layout_toggle_list_filter_params_value: Organisations::GlossaryController::LIST_PARAMS.to_json,+ layout_toggle_storage_key_value: 'layoutState:glossary',+ layout_toggle_unresolved_selection_value: (unresolved.to_json if unresolved.any?),+ viewport_breakpoint_value: MeetingsHelper::LANE_FULL_PAGE_BELOW_PX,+ viewport_current_mode_value: viewport_mode,+ index_page_param_name_value: SELECTION_PARAMS.join(','),+ index_page_frame_id_value: detail_frame_id,+ index_page_content_selector_value: '.glossary-content',+ index_page_placeholder_id_value: 'glossary-term-placeholder',+ index_page_placeholder_class_value: 'ticket-placeholder px-4',+ index_page_placeholder_title_value: t('views.organisations.glossary.index.placeholder_title'),+ index_page_placeholder_body_value: t('views.organisations.glossary.index.placeholder_body'),+ index_page_selected_row_selector_value: '.selected-row[data-glossary-row]',+ index_page_skip_if_content_visible_value: 'true',+ index_url: organisation_glossary_terms_path(current_organisation),+ lane_params: lane_params_json(selection: SELECTION_PARAMS, form: %w[new])+ }.compact+ end++ # Lane parameters of this visit the server did not open (an unknown term, a+ # form the reader may not open). layout-toggle takes them out of the+ # address, so the page stays the list.+ def glossary_unresolved_lane_params(selected:, form_open:)+ unresolved = {}+ term_id = params[:term_id]+ unresolved['term_id'] = term_id if term_id.is_a?(String) && term_id.present? && selected.nil?+ new_state = params[:new]+ unresolved['new'] = new_state if new_state.is_a?(String) && new_state.present? && !form_open+ unresolved+ end++ def glossary_category_name(category)+ t("views.organisations.glossary.categories.#{category}")+ end++ def glossary_status_name(status)+ t("views.organisations.glossary.statuses.#{status}")+ end++ # The category choices of a select: [name, key], in GlossaryTerm's order.+ def glossary_category_options+ GlossaryTerm::CATEGORIES.map { |category| [glossary_category_name(category), category] }+ end++ # The heard forms of a term as the page groups them: one entry per compared+ # form, with the spelling last heard, how often it was corrected, and its+ # corrections newest first. Reads the loaded corrections, no query.+ def glossary_heard_groups(term)+ term.term_corrections.group_by(&:normalized_heard).sort_by(&:first).map do |_normalized, corrections|+ newest_first = corrections.sort_by { |correction| [-correction.created_at.to_f, correction.id] }+ { heard: newest_first.first.heard, count: corrections.size, corrections: newest_first }+ end+ end++ # The line under a term in the list: its heard forms, each with its count+ # when it was heard more than once.+ def glossary_row_forms(term)+ groups = glossary_heard_groups(term)+ shown = groups.first(ROW_FORMS_SHOWN).map do |group|+ quoted = t('views.organisations.glossary.quoted', text: group[:heard])+ group[:count] > 1 ? t('views.organisations.glossary.index.form_count', form: quoted, count: group[:count]) : quoted+ end+ shown << t('views.organisations.glossary.index.more_forms', count: groups.size - ROW_FORMS_SHOWN) if groups.size > ROW_FORMS_SHOWN+ shown.join(', ')+ end++ # The second line of a row: who spoke and in which projects, distinct, as+ # names only (links live in the lane).+ def glossary_row_origin(term)+ corrections = term.term_corrections+ speakers = corrections.filter_map { |correction| glossary_speaker_name(correction) }.uniq+ projects = corrections.filter_map { |correction| correction.project&.name }.uniq+ [speakers.to_sentence.presence, projects.join(', ').presence].compact.join(' · ')+ end++ # The speaker of a heard form as a name: a member through the reader's name+ # display setting, a person of the directory as written there; nil without+ # a speaker (none linked, or deleted).+ def glossary_speaker_name(correction)+ if correction.user then viewer_display_name(correction.user)+ elsif correction.person then correction.person.name+ end+ end++ # Where the name of a speaker links to on the people page, or nil: only+ # with view_people, and only for a row or a member the reader may see+ # there (PersonPolicy::Scope, MembershipPolicy::Scope), so the link never+ # opens an empty lane.+ def glossary_speaker_url(correction)+ return unless glossary_people_linkable?++ if correction.person_id && glossary_visible_person_ids.include?(correction.person_id)+ organisation_people_path(current_organisation, person_id: correction.person_id)+ elsif correction.user_id && glossary_visible_member_ids.include?(correction.user_id)+ organisation_people_path(current_organisation, member_id: correction.user_id)+ end+ end++ # The meetings of these heard forms the reader may READ, as id => title+ # (MeetingPolicy::Scope, one query). A meeting not in it shows neither+ # title nor link: only its project's name stands (E3).+ def glossary_readable_meetings(corrections)+ ids = corrections.filter_map(&:meeting_id).uniq+ return {} if ids.empty?++ policy_scope(Meeting).where(id: ids).pluck(:id, :title).to_h+ end++ # The other terms a term can be merged into, by spelling.+ def glossary_merge_options(term)+ policy_scope(GlossaryTerm).where.not(id: term.id).order(:normalized_term, :id).pluck(:term, :id)+ end+enddiff --git a/app/helpers/mobile_navigation_helper.rb b/app/helpers/mobile_navigation_helper.rbindex bbd02d9..c9f128e 100644--- a/app/helpers/mobile_navigation_helper.rb+++ b/app/helpers/mobile_navigation_helper.rb@@ -18,6 +18,7 @@ module MobileNavigationHelper'billing' => 'settings.billing','changelog' => 'navigation.changelog','codebase_import_files' => 'mobile.page_titles.imports',+ 'glossary' => 'navigation.glossary','help' => 'mobile.help','invitations' => 'mobile.page_titles.invitations','meetings_overview' => 'navigation.all_meetings',diff --git a/app/views/common/_navigation_application.html.erb b/app/views/common/_navigation_application.html.erbindex d6586a1..f4ef4f7 100644--- a/app/views/common/_navigation_application.html.erb+++ b/app/views/common/_navigation_application.html.erb@@ -132,8 +132,9 @@gate that actually belongs to it. That predicate is exactly the old blockcondition, so nothing changes for anybody who had the block before.The people directory is a right of its own (PersonPolicy) and opens the- block too: a customer role may hold it without any project. %>- <% if user_signed_in? && (policy(Project).index? || policy(TimeSession).index? || assistant_available? || policy(Person).index?) %>+ block too: a customer role may hold it without any project. So does the+ glossary (GlossaryPolicy). %>+ <% if user_signed_in? && (policy(Project).index? || policy(TimeSession).index? || assistant_available? || policy(Person).index? || policy(GlossaryTerm).index?) %><div class="w-full px-4 pt-3"><div class="mb-2"><% can_view_times = TimeSessionNavigationService.new(current_user, current_organisation).can_show_all_time_sessions_menu? %>@@ -189,6 +190,10 @@<% if can_view_meetings %><%= render 'common/navigation_item', name: t('navigation.all_meetings'), path: organisation_meetings_path(organisation_id: current_organisation.id), icon: 'bi bi-chat-quote', active: controller_name == 'meetings_overview' %><% end %>+ <%# The glossary: a right of its own (GlossaryPolicy, K4a). %>+ <% if policy(GlossaryTerm).index? %>+ <%= render 'common/navigation_item', name: t('navigation.glossary'), path: organisation_glossary_terms_path(organisation_id: current_organisation.id), icon: 'bi bi-book', active: controller_name == 'glossary' %>+ <% end %><%# The people directory: a right of its own (PersonPolicy). %><% if policy(Person).index? %><%= render 'common/navigation_item', name: t('navigation.people'), path: organisation_people_path(organisation_id: current_organisation.id), icon: 'bi bi-people', active: controller_name == 'people' %>diff --git a/app/views/organisations/glossary/_correction.html.erb b/app/views/organisations/glossary/_correction.html.erbnew file mode 100644index 0000000..057c540--- /dev/null+++ b/app/views/organisations/glossary/_correction.html.erb@@ -0,0 +1,44 @@+<%# locals: (correction:, term:, meetings:, can_write:) %>+<%# One correction of a heard form: who spoke (a name, a link only with+ view_people), the project it came from (a name for every reader of the+ glossary), the meeting (title and link only when the reader may read it,+ meetings holds those), the date, how often it was replaced, and delete for+ those who may keep the glossary. %>+<% speaker = glossary_speaker_name(correction) %>+<% speaker_url = glossary_speaker_url(correction) if speaker %>+<% meeting_title = meetings[correction.meeting_id] %>+<li class="glossary-heard__row">+ <span class="glossary-heard__speaker">+ <% if speaker_url %>+ <%= link_to speaker, speaker_url, class: 'people-fields__link', data: { turbo_frame: '_top' } %>+ <% elsif speaker %>+ <%= speaker %>+ <% else %>+ <span class="text-muted"><%= t('views.organisations.glossary.show.no_speaker') %></span>+ <% end %>+ </span>+ <span class="glossary-heard__origin">+ <%= correction.project&.name || t('views.organisations.glossary.show.no_project') %>+ <% if meeting_title %>+ · <%= link_to meeting_title, organisation_meetings_path(@current_organisation, meeting_id: correction.meeting_id),+ class: 'people-fields__link', data: { turbo_frame: '_top' } %>+ <% end %>+ </span>+ <span class="glossary-heard__when">+ <time datetime="<%= correction.created_at.iso8601 %>"><%= l(correction.created_at.to_date, format: :default) %></time>+ <% if correction.replaced_count > 1 %>+ · <%= t('views.organisations.glossary.show.replaced', count: correction.replaced_count) %>+ <% end %>+ </span>+ <% if can_write %>+ <%= render Neo::Buttons::ButtonComponent.new(+ variant: :ghost, size: :small, icon: 'trash',+ title: t('views.organisations.glossary.show.delete_heard', heard: correction.heard),+ confirm: t('views.organisations.glossary.show.delete_heard_confirm', heard: correction.heard, term: term.term),+ form: { action: correction_organisation_glossary_term_path(@current_organisation, term, correction_id: correction.id),+ method: :delete, params: list_state, data: { turbo_frame: '_top' } }+ ) do %>+ <span class="sr-only"><%= t('views.organisations.glossary.show.delete_heard', heard: correction.heard) %></span>+ <% end %>+ <% end %>+</li>diff --git a/app/views/organisations/glossary/_detail.html.erb b/app/views/organisations/glossary/_detail.html.erbnew file mode 100644index 0000000..2639787--- /dev/null+++ b/app/views/organisations/glossary/_detail.html.erb@@ -0,0 +1,91 @@+<%# locals: (term:) %>+<%# One term: its spelling with category and status, confirm and reject, the+ heard forms with speaker, project, meeting and date, merging into another+ term, and delete. Speakers and projects stand for every reader of the+ glossary (E3); a meeting's title and link only for a reader of that+ meeting (glossary_readable_meetings), a speaker's link only with+ view_people (glossary_speaker_url). The body ends at reading width. %>+<% can_write = policy(term).update? %>+<% corrections = term.term_corrections.includes(:project, :person, :user).in_lane_order.to_a %>+<% meetings = glossary_readable_meetings(corrections) %>+<% groups = corrections.group_by(&:normalized_heard).values %>+<div class="people-detail glossary-detail">+ <%= render 'organisations/glossary/lane_head',+ edit_url: (edit_organisation_glossary_term_path(@current_organisation, term, list_state) if can_write) %>++ <div class="people-detail__body width-text">+ <div class="people-identity__text">+ <h2 class="people-identity__name"><%= term.term %></h2>+ <p class="people-identity__line">+ <%= [(glossary_category_name(term.category) if term.category), glossary_status_name(term.status)].compact.join(' · ') %>+ </p>+ </div>++ <% if can_write %>+ <%= render 'organisations/glossary/status_actions', term: term, lane: true %>+ <% end %>++ <section class="glossary-heard" aria-labelledby="glossary-heard-title">+ <h3 id="glossary-heard-title" class="people-meetings__title"><%= t('views.organisations.glossary.show.heard_title') %></h3>+ <% if groups.empty? %>+ <p class="people-meetings__empty"><%= t('views.organisations.glossary.show.no_heard') %></p>+ <% else %>+ <ul class="glossary-heard__groups">+ <% groups.each do |group| %>+ <li class="glossary-heard__group">+ <p class="glossary-heard__form">+ <%= t('views.organisations.glossary.quoted', text: group.first.heard) %>+ <span class="glossary-heard__count"><%= t('views.organisations.glossary.show.times', count: group.size) %></span>+ </p>+ <ul class="glossary-heard__list">+ <% group.each do |correction| %>+ <%= render 'organisations/glossary/correction', correction: correction, term: term, meetings: meetings,+ can_write: can_write %>+ <% end %>+ </ul>+ </li>+ <% end %>+ </ul>+ <% end %>+ </section>++ <% if can_write %>+ <% options = glossary_merge_options(term) %>+ <% if options.any? %>+ <%= form_with url: merge_organisation_glossary_term_path(@current_organisation, term), method: :post, class: 'glossary-merge',+ data: { turbo_frame: '_top', turbo_confirm: t('views.organisations.glossary.show.merge_confirm', term: term.term) } do %>+ <% list_state.each do |name, value| %>+ <%= hidden_field_tag name, value, id: nil %>+ <% end %>+ <label for="glossary-merge-target" class="glossary-merge__label"><%= t('views.organisations.glossary.show.merge_label') %></label>+ <p class="people-form__hint"><%= t('views.organisations.glossary.show.merge_hint') %></p>+ <div class="glossary-merge__row">+ <%= select_tag :target_id, options_for_select(options), include_blank: t('views.organisations.glossary.show.merge_choose'),+ id: 'glossary-merge-target', class: 'people-input', required: true %>+ <%= render Neo::Buttons::ButtonComponent.new(variant: :secondary, size: :medium, type: 'submit') do %>+ <%= t('views.organisations.glossary.show.merge_submit') %>+ <% end %>+ </div>+ <% end %>+ <% end %>+ <% end %>++ <div class="people-footer">+ <p class="people-history__line"><%= t('views.organisations.glossary.show.created_at', date: l(term.created_at.to_date, format: :default)) %></p>+ <% if can_write %>+ <div>+ <%= render Neo::Buttons::ButtonComponent.new(+ variant: :danger, size: :small, icon: 'trash',+ confirm: t('views.organisations.glossary.show.delete_confirm', term: term.term, count: corrections.size),+ form: { action: organisation_glossary_term_path(@current_organisation, term), method: :delete,+ params: list_state, data: { turbo_frame: '_top' } }+ ) do %>+ <%= t('views.organisations.glossary.show.delete') %>+ <% end %>+ </div>+ <% else %>+ <p class="people-footer__readonly"><%= t('views.organisations.glossary.show.read_only') %></p>+ <% end %>+ </div>+ </div>+</div>diff --git a/app/views/organisations/glossary/_form.html.erb b/app/views/organisations/glossary/_form.html.erbnew file mode 100644index 0000000..63475b9--- /dev/null+++ b/app/views/organisations/glossary/_form.html.erb@@ -0,0 +1,50 @@+<%# locals: (term:, message: nil) %>+<%# The form in the lane, new and edit: the spelling and the category. It+ leaves the frame (_top): a save lands on the list with the term open, a+ refused save (a spelling already in the glossary) renders the page again+ with this form and its reason. The filters ride in hidden fields. %>+<% url = term.persisted? ? organisation_glossary_term_path(@current_organisation, term) : organisation_glossary_terms_path(@current_organisation) %>+<% title = term.persisted? ? t('views.organisations.glossary.form.edit_title', term: term.term_in_database) : t('views.organisations.glossary.form.new_title') %>+<% cancel_url = term.persisted? ? organisation_glossary_term_path(@current_organisation, term, list_state) : organisation_glossary_terms_path(@current_organisation, list_state) %>+<div class="people-form-wrap">+ <div class="people-lane__head" data-lane-head data-lane-index-url="<%= organisation_glossary_terms_path(@current_organisation) %>">+ <h2 class="people-form__title"><%= title %></h2>+ <%= link_to cancel_url, class: 'people-icon-action', title: t('views.organisations.glossary.show.close'),+ data: ({ lane_close: true, turbo_frame: '_top' } unless term.persisted?) do %>+ <i class="bi bi-x-lg" aria-hidden="true"></i>+ <% end %>+ </div>++ <% if message.present? %>+ <p class="people-callout people-callout--danger" role="alert"><%= message %></p>+ <% end %>++ <%= form_with model: term, url: url, scope: :glossary_term, class: 'people-form', data: { turbo_frame: '_top' } do |f| %>+ <% list_state.each do |name, value| %>+ <%= hidden_field_tag name, value, id: nil %>+ <% end %>++ <div class="people-form__field">+ <%= f.label :term do %>+ <%= GlossaryTerm.human_attribute_name(:term) %><span class="people-form__required" aria-hidden="true"> *</span>+ <% end %>+ <%= f.text_field :term, class: 'people-input', maxlength: GlossaryTerm::MAX_LENGTH, required: true, autocomplete: 'off',+ placeholder: t('views.organisations.glossary.form.term_placeholder') %>+ <p class="people-form__hint"><%= t('views.organisations.glossary.form.term_hint') %></p>+ </div>++ <div class="people-form__field">+ <%= f.label :category %>+ <%= f.select :category, glossary_category_options, { include_blank: t('views.organisations.glossary.form.no_category') },+ class: 'people-input' %>+ </div>++ <div class="people-form__actions">+ <%= render Neo::Buttons::ButtonComponent.new(variant: :primary, size: :medium, type: 'submit') do %>+ <%= t('views.organisations.glossary.form.save') %>+ <% end %>+ <%= link_to t('views.organisations.glossary.form.cancel'), cancel_url, class: 'people-quiet-action',+ data: ({ turbo_frame: '_top' } unless term.persisted?) %>+ </div>+ <% end %>+</div>diff --git a/app/views/organisations/glossary/_index_desktop.html.erb b/app/views/organisations/glossary/_index_desktop.html.erbnew file mode 100644index 0000000..2346c29--- /dev/null+++ b/app/views/organisations/glossary/_index_desktop.html.erb@@ -0,0 +1,20 @@+<%# locals: (list:, lane:, open:) %>+<%# Desktop: list and lane side by side (NeoTwoColumnGridComponent, lane: true). %>+<%= render NeoTwoColumnGridComponent.new(+ selected_item: (open || nil),+ context_type: :glossary,+ css_classes: "#{open ? 'show-content' : 'hide-content'} hide-panel",+ additional_targets: { "index-page-target" => "layout" },+ chrome_height: NeoTwoColumnGridComponent::LANE_CHROME_HEIGHT_PX,+ lane: true+) do |grid| %>+ <% grid.with_list do %>+ <%= list %>+ <% end %>++ <% grid.with_main_content do %>+ <turbo-frame id="<%= Organisations::GlossaryController::DETAIL_FRAME_ID %>">+ <%= lane %>+ </turbo-frame>+ <% end %>+<% end %>diff --git a/app/views/organisations/glossary/_index_mobile.html.erb b/app/views/organisations/glossary/_index_mobile.html.erbnew file mode 100644index 0000000..375b940--- /dev/null+++ b/app/views/organisations/glossary/_index_mobile.html.erb@@ -0,0 +1,21 @@+<%# locals: (list:, lane:, open:) %>+<%# Mobile: the list, or the term (or the form) full screen with a way back,+ as on the people page. Same frame id as on the desktop. %>+<div class="people-mobile-grid list">+ <%= render NeoMobileTicketViewComponent.new(+ selected_item: (open || nil),+ show_detail: open,+ back_url: organisation_glossary_terms_path(@current_organisation, list_state),+ back_label: t('views.organisations.glossary.index.back_to_list')+ ) do |mobile| %>+ <% mobile.with_list do %>+ <%= list %>+ <% end %>++ <% mobile.with_detail do %>+ <turbo-frame id="<%= Organisations::GlossaryController::DETAIL_FRAME_ID %>">+ <%= lane %>+ </turbo-frame>+ <% end %>+ <% end %>+</div>diff --git a/app/views/organisations/glossary/_lane.html.erb b/app/views/organisations/glossary/_lane.html.erbnew file mode 100644index 0000000..b41cefe--- /dev/null+++ b/app/views/organisations/glossary/_lane.html.erb@@ -0,0 +1,18 @@+<%# locals: (state:, term: nil, message: nil) %>+<%# What the lane frame holds: a term (:detail), the form (:form, new or+ edit), or nothing yet (:empty). Rendered by the index on a full visit and+ alone for a frame request. glossary-content marks LOADED content for+ layout-toggle and index-page; the empty lane must not carry it, or they+ open an empty column. %>+<div class="<%= 'glossary-content' unless state == :empty %> people-lane min-w-0 relative">+ <% if state == :detail %>+ <%= render 'organisations/glossary/detail', term: term %>+ <% elsif state == :form %>+ <%= render 'organisations/glossary/form', term: term, message: message %>+ <% else %>+ <div id="glossary-term-placeholder" class="ticket-placeholder px-4 py-10 text-center">+ <h2 class="text-lg font-semibold text-heading"><%= t('views.organisations.glossary.index.placeholder_title') %></h2>+ <p class="text-sm text-muted"><%= t('views.organisations.glossary.index.placeholder_body') %></p>+ </div>+ <% end %>+</div>diff --git a/app/views/organisations/glossary/_lane_head.html.erb b/app/views/organisations/glossary/_lane_head.html.erbnew file mode 100644index 0000000..65f51f7--- /dev/null+++ b/app/views/organisations/glossary/_lane_head.html.erb@@ -0,0 +1,18 @@+<%# locals: (edit_url: nil) %>+<%# The head of an open term: "Bearbeiten" for those who may keep the+ glossary, and the way out. The ✕ closes the lane in place+ (layout-toggle); on a phone the mobile view brings its own way back. %>+<div class="people-lane__head" data-lane-head data-lane-index-url="<%= organisation_glossary_terms_path(@current_organisation) %>">+ <% if edit_url %>+ <%= link_to edit_url, class: 'people-ghost-action' do %>+ <i class="bi bi-pencil" aria-hidden="true"></i><%= t('views.organisations.glossary.show.edit') %>+ <% end %>+ <% end %>+ <% unless @viewport_mode == 'mobile' %>+ <span class="people-lane__divider" aria-hidden="true"></span>+ <button type="button" class="people-icon-action" title="<%= t('views.organisations.glossary.show.close') %>"+ data-lane-close data-action="click->layout-toggle#closeContent">+ <i class="bi bi-x-lg" aria-hidden="true"></i>+ </button>+ <% end %>+</div>diff --git a/app/views/organisations/glossary/_list_head.html.erb b/app/views/organisations/glossary/_list_head.html.erbnew file mode 100644index 0000000..d4bc3a7--- /dev/null+++ b/app/views/organisations/glossary/_list_head.html.erb@@ -0,0 +1,70 @@+<%# locals: (status_counts:, origin_projects:) %>+<%# The head of the list: the title, the "+" for those who may keep the+ glossary, the status filter as pills with their counts, and project and+ category as selects (a full visit of the index, auto-submitted). %>+<% frame_id = Organisations::GlossaryController::DETAIL_FRAME_ID %>+<% mobile = @viewport_mode == 'mobile' %>+<% add_url = organisation_glossary_terms_path(@current_organisation, list_state.merge('new' => Organisations::GlossaryController::NEW_STATE)) %>+<% add_data = {+ controller: 'lane-link',+ action: 'click->lane-link#click',+ lane_link_url_value: new_organisation_glossary_term_path(@current_organisation),+ lane_link_frame_value: frame_id,+ lane_link_set_value: { new: Organisations::GlossaryController::NEW_STATE }.to_json,+ lane_link_remove_value: GlossaryHelper::SELECTION_PARAMS.to_json,+ lane_link_focus_value: '#glossary_term_term'+ } %>+<div class="people-head">+ <% if mobile %>+ <% if policy(GlossaryTerm).create? %>+ <%= render Neo::Buttons::IconButtonComponent.new(variant: :primary, icon: 'plus-lg', size: :large, url: add_url,+ title: t('views.organisations.glossary.index.new_term'),+ class: 'people-head__action', data: add_data) %>+ <% end %>+ <% else %>+ <%= render NeoTitleBoxComponent.new(title: t('views.organisations.glossary.index.title'), margin_bottom: nil) do |box| %>+ <% if policy(GlossaryTerm).create? %>+ <% box.with_title_action do %>+ <%= render Neo::Buttons::IconButtonComponent.new(variant: :primary, icon: 'plus-lg', size: :medium, url: add_url,+ title: t('views.organisations.glossary.index.new_term'), data: add_data) %>+ <% end %>+ <% end %>+ <% end %>+ <% end %>+</div>++<div class="people-tools glossary-tools">+ <nav class="people-filters" aria-label="<%= t('views.organisations.glossary.index.status_filter_label') %>">+ <% ([nil] + GlossaryTerm::STATUSES).each do |status| %>+ <% active = list_state['status'] == status %>+ <% count = status ? status_counts.fetch(status, 0) : status_counts.values.sum %>+ <%= link_to organisation_glossary_terms_path(@current_organisation, list_state.merge('status' => status).compact),+ class: "people-pill #{'people-pill--active' if active}", 'aria-current': (active ? 'true' : nil),+ data: { turbo_frame: '_top' } do %>+ <%= status ? t("views.organisations.glossary.index.status_filter.#{status}") : t('views.organisations.glossary.index.status_filter.all') %>+ <span class="people-pill__count"><%= count %></span>+ <% end %>+ <% end %>+ </nav>++ <%= form_with url: organisation_glossary_terms_path(@current_organisation), method: :get, class: 'glossary-filters',+ data: { controller: 'auto-submit', turbo_frame: '_top' } do %>+ <%= hidden_field_tag :status, list_state['status'], id: nil if list_state['status'] %>+ <%= hidden_field_tag :viewport, 'mobile', id: nil if list_state['viewport'] %>+ <label class="glossary-filters__field">+ <span class="sr-only"><%= t('views.organisations.glossary.index.project_filter_label') %></span>+ <%= select_tag :project_id, options_for_select(origin_projects.map { |id, name| [name, id] }, list_state['project_id']),+ include_blank: t('views.organisations.glossary.index.all_projects'), class: 'people-input glossary-filters__select',+ id: 'glossary-project-filter' %>+ </label>+ <label class="glossary-filters__field">+ <span class="sr-only"><%= t('views.organisations.glossary.index.category_filter_label') %></span>+ <%= select_tag :category, options_for_select(glossary_category_options, list_state['category']),+ include_blank: t('views.organisations.glossary.index.all_categories'), class: 'people-input glossary-filters__select',+ id: 'glossary-category-filter' %>+ </label>+ <noscript>+ <button type="submit" class="people-secondary-action"><%= t('views.organisations.glossary.index.apply_filters') %></button>+ </noscript>+ <% end %>+</div>diff --git a/app/views/organisations/glossary/_results.html.erb b/app/views/organisations/glossary/_results.html.erbnew file mode 100644index 0000000..f5462c2--- /dev/null+++ b/app/views/organisations/glossary/_results.html.erb@@ -0,0 +1,26 @@+<%# locals: (entries:, status_counts:, selected: nil) %>+<%# The terms of the glossary, open proposals first (GlossaryTerm.ordered):+ the spelling with category and status, the heard forms below, then who+ spoke and in which projects. Every row opens the term in the lane. %>+<turbo-frame id="<%= Organisations::GlossaryController::LIST_FRAME_ID %>">+ <% if entries.any? %>+ <ul class="people-list glossary-list">+ <% entries.each do |term| %>+ <%= render 'organisations/glossary/row', term: term, selected: selected %>+ <% end %>+ </ul>+ <% elsif status_counts.values.sum.zero? %>+ <div class="people-empty">+ <i class="bi bi-book people-empty__icon" aria-hidden="true"></i>+ <p class="people-empty__title"><%= t('views.organisations.glossary.index.empty_title') %></p>+ <p class="people-empty__text width-text"><%= t('views.organisations.glossary.index.empty_description') %></p>+ </div>+ <% else %>+ <div class="people-empty">+ <p class="people-empty__text"><%= t('views.organisations.glossary.index.empty_no_results') %></p>+ <%= link_to t('views.organisations.glossary.index.clear_filters'),+ organisation_glossary_terms_path(@current_organisation, list_state.slice('viewport')),+ class: 'people-text-action', data: { turbo_frame: '_top' } %>+ </div>+ <% end %>+</turbo-frame>diff --git a/app/views/organisations/glossary/_row.html.erb b/app/views/organisations/glossary/_row.html.erbnew file mode 100644index 0000000..68d16f5--- /dev/null+++ b/app/views/organisations/glossary/_row.html.erb@@ -0,0 +1,40 @@+<%# locals: (term:, selected: nil) %>+<%# One term: the spelling, its category and, unless confirmed, its status;+ the heard forms below; then speakers and projects as names. The number on+ the right counts the corrections. A proposal carries "Bestätigen" and+ "Verwerfen" for those who may keep the glossary (buttons do not open the+ row, list-row skips them). Enter and Space open the row like a click. %>+<% open = selected&.id == term.id %>+<% row_data = { controller: 'list-row', action: 'click->list-row#click keydown.enter->list-row#click keydown.space->list-row#click',+ glossary_row: true,+ list_row_url_value: organisation_glossary_term_path(@current_organisation, term), list_row_id_value: term.id,+ list_row_param_value: 'term_id', list_row_params_value: GlossaryHelper::SELECTION_PARAMS.to_json,+ list_row_frame_value: Organisations::GlossaryController::DETAIL_FRAME_ID } %>+<% count = term.term_corrections.size %>+<%# Class names written out: Tailwind keeps only component classes it finds whole in a template. %>+<%= tag.li data: row_data, tabindex: 0, class: ['people-row glossary-row', ('glossary-row--rejected' if term.rejected?), ('selected-row' if open)].compact.join(' ') do %>+ <span class="people-row__text">+ <span class="glossary-row__head">+ <span class="people-row__name"><%= term.term %></span>+ <% if term.category %>+ <span class="people-badge"><%= glossary_category_name(term.category) %></span>+ <% end %>+ <% unless term.confirmed? %>+ <span class="glossary-status <%= term.rejected? ? 'glossary-status--rejected' : 'glossary-status--proposed' %>"><%= glossary_status_name(term.status) %></span>+ <% end %>+ </span>+ <% if count.positive? %>+ <span class="people-row__sub"><%= t('views.organisations.glossary.index.heard_as', forms: glossary_row_forms(term)) %></span>+ <% origin = glossary_row_origin(term) %>+ <% if origin.present? %>+ <span class="people-row__sub glossary-row__origin"><%= origin %></span>+ <% end %>+ <% end %>+ </span>+ <% if term.proposed? && policy(term).confirm? %>+ <%= render 'organisations/glossary/status_actions', term: term, lane: false %>+ <% end %>+ <span class="glossary-row__count" title="<%= t('views.organisations.glossary.index.corrections_count', count: count) %>">+ <%= count %><span class="sr-only"> <%= t('views.organisations.glossary.index.corrections_count', count: count) %></span>+ </span>+<% end %>diff --git a/app/views/organisations/glossary/_status_actions.html.erb b/app/views/organisations/glossary/_status_actions.html.erbnew file mode 100644index 0000000..dae4842--- /dev/null+++ b/app/views/organisations/glossary/_status_actions.html.erb@@ -0,0 +1,25 @@+<%# locals: (term:, lane:) %>+<%# Confirm and reject (E5): "Bestätigen" unless confirmed, "Verwerfen"+ unless rejected. From the lane the term stays open (term_id sent along),+ from the list the list stays as it was. %>+<% params_kept = list_state.merge(lane ? { 'term_id' => term.id } : {}) %>+<div class="glossary-status-actions">+ <% unless term.confirmed? %>+ <%= render Neo::Buttons::ButtonComponent.new(+ variant: :secondary, size: :small, icon: 'check-lg',+ form: { action: confirm_organisation_glossary_term_path(@current_organisation, term), method: :patch,+ params: params_kept, data: { turbo_frame: '_top' } }+ ) do %>+ <%= t('views.organisations.glossary.show.confirm') %>+ <% end %>+ <% end %>+ <% unless term.rejected? %>+ <%= render Neo::Buttons::ButtonComponent.new(+ variant: :secondary, size: :small, icon: 'x-lg',+ form: { action: reject_organisation_glossary_term_path(@current_organisation, term), method: :patch,+ params: params_kept, data: { turbo_frame: '_top' } }+ ) do %>+ <%= t('views.organisations.glossary.show.reject') %>+ <% end %>+ <% end %>+</div>diff --git a/app/views/organisations/glossary/index.html.erb b/app/views/organisations/glossary/index.html.erbnew file mode 100644index 0000000..5422168--- /dev/null+++ b/app/views/organisations/glossary/index.html.erb@@ -0,0 +1,28 @@+<%# The glossary of the organisation (Organisations::GlossaryController, K4a):+ the terms on the left, a term or the form in the lane on the right, the+ shape of the people directory. layout-toggle and index-page own the+ address (?term_id=, ?new=term); a write leaves the lane and lands here+ again. %>+<% content_for :head do %>+ <meta name="turbo-cache-control" content="no-cache">+<% end %>++<% lane_state = if @form_term then :form elsif @lane_term then :detail end %>+<% lane_term = @form_term || @lane_term %>++<div class="labor-layout-view people-page glossary-page <%= 'show-content' if lane_state %> hide-panel"+ <%= tag.attributes(data: glossary_page_data(viewport_mode: @viewport_mode, selected: @lane_term, form_open: @form_term.present?)) %>>+ <% list = capture do %>+ <%= render 'organisations/glossary/list_head', status_counts: @status_counts, origin_projects: @origin_projects %>+ <%= render 'organisations/glossary/results', entries: @entries, status_counts: @status_counts, selected: @lane_term %>+ <% end %>+ <% lane = capture do %>+ <%= render 'organisations/glossary/lane', state: lane_state || :empty, term: lane_term, message: @form_message %>+ <% end %>++ <% if @viewport_mode == 'mobile' %>+ <%= render 'organisations/glossary/index_mobile', list: list, lane: lane, open: lane_state.present? %>+ <% else %>+ <%= render 'organisations/glossary/index_desktop', list: list, lane: lane, open: lane_state.present? %>+ <% end %>+</div>diff --git a/app/views/organisations/mobile_navigation/more.html.erb b/app/views/organisations/mobile_navigation/more.html.erbindex 95c5846..19cccec 100644--- a/app/views/organisations/mobile_navigation/more.html.erb+++ b/app/views/organisations/mobile_navigation/more.html.erb@@ -6,15 +6,19 @@<%= link_to t('mobile.switch'), select_organisation_path, class: 'mobile-text-action' %></div><% show_meetings = AccessCheck::ProjectAccessService.accessible_project_ids(current_user, current_organisation, action: :read, area: :meetings).any? %>+ <% show_glossary = policy(GlossaryTerm).index? %><% show_people = policy(Person).index? %><% show_billings = policy(TimeSessionGroup).index? %><% show_management = can_manage_organisation?(current_organisation) %>- <% if show_meetings || show_people || show_billings || show_management %>+ <% if show_meetings || show_glossary || show_people || show_billings || show_management %><h2 class="mobile-section-label"><%= t('mobile.organisation') %></h2><ul class="mobile-menu-list"><% if show_meetings %><li><%= link_to safe_join([content_tag(:i, '', class: 'bi bi-chat-left', aria: { hidden: true }), content_tag(:span, t('navigation.all_meetings'))]), organisation_meetings_path(current_organisation) %></li><% end %>+ <% if show_glossary %>+ <li><%= link_to safe_join([content_tag(:i, '', class: 'bi bi-book', aria: { hidden: true }), content_tag(:span, t('navigation.glossary'))]), organisation_glossary_terms_path(current_organisation) %></li>+ <% end %><% if show_people %><li><%= link_to safe_join([content_tag(:i, '', class: 'bi bi-people', aria: { hidden: true }), content_tag(:span, t('navigation.people'))]), organisation_people_path(current_organisation) %></li><% end %>diff --git a/config/locales/de.yml b/config/locales/de.ymlindex 8c712b4..c01b582 100644--- a/config/locales/de.yml+++ b/config/locales/de.yml@@ -1493,6 +1493,7 @@ de:meeting_inbox: Eingang für Meetingsall_meetings: Alle Meetingspeople: Personen+ glossary: Glossarall_organisations: Alle Organisationenall_projects: Alle Projektetimes: Zeitendiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 8956106..54fa2df 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1387,6 +1387,7 @@ en:meeting_inbox: Inbox for meetingsall_meetings: All Meetingspeople: People+ glossary: Glossaryall_organisations: All organisationsall_projects: All Projectstimes: Timesdiff --git a/config/locales/views/glossar.de.yml b/config/locales/views/glossar.de.ymlindex c9b7871..197ad10 100644--- a/config/locales/views/glossar.de.yml+++ b/config/locales/views/glossar.de.yml@@ -23,3 +23,82 @@ de:correction:destroy:success: "Gehörte Form gelöscht."+ views:+ organisations:+ glossary:+ quoted: "„%{text}“"+ categories:+ person: "Person"+ company: "Firma"+ product: "Produkt"+ place: "Ort"+ domain: "Fachbegriff"+ foreign: "Fremdwort"+ statuses:+ proposed: "Vorschlag"+ confirmed: "Bestätigt"+ rejected: "Verworfen"+ index:+ title: "Glossar"+ new_term: "Begriff anlegen"+ status_filter_label: "Status"+ status_filter:+ all: "Alle"+ proposed: "Vorschläge"+ confirmed: "Bestätigt"+ rejected: "Verworfen"+ project_filter_label: "Projekt"+ category_filter_label: "Kategorie"+ all_projects: "Alle Projekte"+ all_categories: "Alle Kategorien"+ apply_filters: "Anwenden"+ placeholder_title: "Kein Begriff gewählt"+ placeholder_body: "Wähle links einen Begriff aus."+ back_to_list: "Glossar"+ empty_title: "Noch keine Begriffe"+ empty_description: "Hier steht, wie Fachbegriffe, Namen und Produkte richtig geschrieben werden, und in welchen Formen sie in Meetings falsch gehört wurden. Das Glossar gilt für die ganze Organisation."+ empty_no_results: "Kein Begriff in dieser Auswahl."+ clear_filters: "Filter zurücksetzen"+ heard_as: "gehört als %{forms}"+ form_count: "%{form} (%{count}×)"+ more_forms: "und %{count} weitere"+ corrections_count:+ one: "1 Korrektur"+ other: "%{count} Korrekturen"+ show:+ edit: "Bearbeiten"+ close: "Schließen"+ confirm: "Bestätigen"+ reject: "Verwerfen"+ heard_title: "Gehörte Formen"+ no_heard: "Noch keine gehörten Formen."+ times:+ one: "1-mal"+ other: "%{count}-mal"+ no_speaker: "Sprecher unbekannt"+ no_project: "Ohne Projekt"+ replaced:+ one: "1-mal ersetzt"+ other: "%{count}-mal ersetzt"+ delete_heard: "Gehörte Form „%{heard}“ löschen"+ delete_heard_confirm: "Die gehörte Form „%{heard}“ bei „%{term}“ löschen?"+ merge_label: "Mit anderem Begriff zusammenführen"+ merge_hint: "Die gehörten Formen wandern zu dem gewählten Begriff, dieser Begriff wird gelöscht."+ merge_choose: "Begriff wählen"+ merge_submit: "Zusammenführen"+ merge_confirm: "„%{term}“ in den gewählten Begriff überführen? Dieser Begriff wird danach gelöscht."+ created_at: "Angelegt am %{date}"+ delete: "Begriff löschen"+ delete_confirm:+ zero: "„%{term}“ löschen?"+ one: "„%{term}“ und seine gehörte Form löschen?"+ other: "„%{term}“ und seine %{count} gehörten Formen löschen?"+ read_only: "Nur lesen: Pflegen dürfen Verwalter und wer das Recht „Glossar pflegen“ hat."+ form:+ new_title: "Neuer Begriff"+ edit_title: "„%{term}“ bearbeiten"+ term_placeholder: "Richtige Schreibweise"+ term_hint: "So wird der Begriff geschrieben. Groß- und Kleinschreibung zählt nicht doppelt: jeder Begriff steht einmal im Glossar."+ no_category: "Keine Kategorie"+ save: "Speichern"+ cancel: "Abbrechen"diff --git a/config/locales/views/glossar.en.yml b/config/locales/views/glossar.en.ymlindex 76c9ff7..dd441a3 100644--- a/config/locales/views/glossar.en.yml+++ b/config/locales/views/glossar.en.yml@@ -23,3 +23,82 @@ en:correction:destroy:success: "Heard form deleted."+ views:+ organisations:+ glossary:+ quoted: "“%{text}”"+ categories:+ person: "Person"+ company: "Company"+ product: "Product"+ place: "Place"+ domain: "Technical term"+ foreign: "Foreign word"+ statuses:+ proposed: "Proposal"+ confirmed: "Confirmed"+ rejected: "Rejected"+ index:+ title: "Glossary"+ new_term: "Add term"+ status_filter_label: "Status"+ status_filter:+ all: "All"+ proposed: "Proposals"+ confirmed: "Confirmed"+ rejected: "Rejected"+ project_filter_label: "Project"+ category_filter_label: "Category"+ all_projects: "All projects"+ all_categories: "All categories"+ apply_filters: "Apply"+ placeholder_title: "No term selected"+ placeholder_body: "Pick a term on the left."+ back_to_list: "Glossary"+ empty_title: "No terms yet"+ empty_description: "This is where technical terms, names and products are spelled right, with the forms in which meetings heard them wrong. The glossary holds for the whole organisation."+ empty_no_results: "No term in this selection."+ clear_filters: "Reset filters"+ heard_as: "heard as %{forms}"+ form_count: "%{form} (%{count}×)"+ more_forms: "and %{count} more"+ corrections_count:+ one: "1 correction"+ other: "%{count} corrections"+ show:+ edit: "Edit"+ close: "Close"+ confirm: "Confirm"+ reject: "Reject"+ heard_title: "Heard forms"+ no_heard: "No heard forms yet."+ times:+ one: "once"+ other: "%{count} times"+ no_speaker: "Speaker unknown"+ no_project: "No project"+ replaced:+ one: "replaced once"+ other: "replaced %{count} times"+ delete_heard: "Delete heard form “%{heard}”"+ delete_heard_confirm: "Delete the heard form “%{heard}” of “%{term}”?"+ merge_label: "Merge with another term"+ merge_hint: "The heard forms move to the chosen term, and this term is deleted."+ merge_choose: "Choose a term"+ merge_submit: "Merge"+ merge_confirm: "Move “%{term}” into the chosen term? This term is deleted afterwards."+ created_at: "Created on %{date}"+ delete: "Delete term"+ delete_confirm:+ zero: "Delete “%{term}”?"+ one: "Delete “%{term}” and its heard form?"+ other: "Delete “%{term}” and its %{count} heard forms?"+ read_only: "Read only: admins and holders of the right “Keep the glossary” can change it."+ form:+ new_title: "New term"+ edit_title: "Edit “%{term}”"+ term_placeholder: "Right spelling"+ term_hint: "This is how the term is spelled. Case does not count twice: every term stands once in the glossary."+ no_category: "No category"+ save: "Save"+ cancel: "Cancel"diff --git a/config/routes.rb b/config/routes.rbindex d0cdcdf..e997fef 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -335,6 +335,20 @@ Rails.application.routes.draw doget 'members/:user_id', on: :collection, action: :member, as: :memberend+ # The glossary of the organisation (K4a): one page with a lane, the shape+ # of the people directory. The terms on the left, a term or the form in the+ # lane; show, new and edit answer the lane frame, a full visit lands on the+ # index with ?term_id= or ?new=term. Confirm, reject, merge and deleting one+ # heard form are writes on a term.+ resources :glossary_terms, path: 'glossary', controller: 'glossary' do+ member do+ patch :confirm+ patch :reject+ post :merge+ delete 'corrections/:correction_id', action: :destroy_correction, as: :correction+ end+ end+# The column picker of "Alle Meetings" saves the overview's base view here:# the controller of the project route (view_configuration under a project),# without a project. The path default pins the list type; a view_type in thediff --git a/spec/requests/organisations/glossary_spec.rb b/spec/requests/organisations/glossary_spec.rbnew file mode 100644index 0000000..9a2cca0--- /dev/null+++ b/spec/requests/organisations/glossary_spec.rb@@ -0,0 +1,591 @@+# frozen_string_literal: true++require 'rails_helper'++# The glossary page and its writes (K4a). Every action against the right+# (GlossaryPolicy, E2): 403 without it, view_glossary reads but never writes,+# manage_glossary writes (a guest role too), an account admin needs no row,+# and a term of another organisation answers 404. What a reader sees (E3):+# heard forms with speaker and project from every project, but a meeting's+# title only with read access to that meeting, and a link to a person only+# with view_people. Invented words and names only.+RSpec.describe 'Organisations::Glossary', :ci_guard, type: :request do+ let(:organisation) { create(:organisation) }+ let(:other_organisation) { create(:organisation) }++ before { ActsAsTenant.current_tenant = organisation }+ after { ActsAsTenant.current_tenant = nil }++ def role_with(*rights, billable: true, title: nil)+ role = create(:role, organisation: organisation, billable: billable, **{ title: title }.compact)+ rights.each do |right|+ category, action = right.include?(':') ? right.split(':') : ['glossary', right]+ create(:permission, role: role, category: category, action: action, allowed: true)+ end+ role+ end++ def member_with(role, active: true)+ user = create(:user, first_name: 'Max', last_name: "Muster#{SecureRandom.hex(2)}")+ create(:membership, user: user, organisation: organisation, role: role, active: active)+ user+ end++ let(:admin) { member_with(role_with(title: Role::ACCOUNT_ADMIN_TITLE)) }+ let(:viewer) { member_with(role_with('view_glossary')) }+ let(:manager) { member_with(role_with('manage_glossary')) }+ let(:nobody) { member_with(role_with) }++ let(:open_project) { create(:project, organisation: organisation, name: 'Projekt Ahorn') }+ let(:closed_project) { create(:project, organisation: organisation, name: 'Projekt Birke') }+ let(:speaker) { create(:person, organisation: organisation, name: 'Erika Beispiel') }+ let(:open_meeting) { create(:meeting, organisation: organisation, project: open_project, title: 'Abstimmung Ahorn', creator: admin) }+ let(:closed_meeting) { create(:meeting, organisation: organisation, project: closed_project, title: 'Geheimrunde Birke', creator: admin) }+ let!(:term) { create(:glossary_term, organisation: organisation, term: 'Lalabase', category: 'product') }+ let!(:open_correction) do+ create(:term_correction, organisation: organisation, glossary_term: term, heard: 'lala bass', project: open_project,+ meeting: open_meeting, person: speaker)+ end+ let!(:closed_correction) do+ create(:term_correction, organisation: organisation, glossary_term: term, heard: 'la la base', project: closed_project,+ meeting: closed_meeting)+ end+ let!(:proposal) { create(:glossary_term, :proposed, organisation: organisation, term: 'Zirbelholz', category: 'domain') }++ let(:frame_headers) { { 'Turbo-Frame' => Organisations::GlossaryController::DETAIL_FRAME_ID } }+ let(:valid_params) { { glossary_term: { term: 'Wortmarke', category: 'company' } } }++ # Every write of the page, one example each: Prosopite reads requests sent+ # from one line of a loop as an N+1.+ def self.write_names+ %w[create update destroy confirm reject merge destroy_correction]+ end++ # [verb, path, params] of a write, against the given term.+ def write_request(name, target = term)+ {+ 'create' => [:post, organisation_glossary_terms_path(organisation), valid_params],+ 'update' => [:patch, organisation_glossary_term_path(organisation, target), { glossary_term: { term: 'Umbenannt' } }],+ 'destroy' => [:delete, organisation_glossary_term_path(organisation, target), {}],+ 'confirm' => [:patch, confirm_organisation_glossary_term_path(organisation, target), {}],+ 'reject' => [:patch, reject_organisation_glossary_term_path(organisation, target), {}],+ 'merge' => [:post, merge_organisation_glossary_term_path(organisation, target), { target_id: proposal.id }],+ 'destroy_correction' => [:delete, correction_organisation_glossary_term_path(organisation, target, correction_id: open_correction.id), {}]+ }.fetch(name)+ end++ def self.frame_names+ %w[show new edit]+ end++ def frame_path(name)+ {+ 'show' => organisation_glossary_term_path(organisation, term),+ 'new' => new_organisation_glossary_term_path(organisation),+ 'edit' => edit_organisation_glossary_term_path(organisation, term)+ }.fetch(name)+ end++ def glossary_state+ [GlossaryTerm.order(:id).pluck(:id, :term, :status, :category), TermCorrection.order(:id).pluck(:id, :glossary_term_id)]+ end++ describe 'without the right' do+ before { sign_in nobody }++ it 'answers 403 on the page' do+ get organisation_glossary_terms_path(organisation)++ expect(response).to have_http_status(:forbidden)+ end++ frame_names.each do |name|+ it "answers 403 on the #{name} frame" do+ get frame_path(name), headers: frame_headers++ expect(response).to have_http_status(:forbidden)+ end+ end++ write_names.each do |name|+ it "answers 403 on #{name} and changes nothing" do+ before = glossary_state+ verb, path, params = write_request(name)++ public_send(verb, path, params: params)++ expect(response).to have_http_status(:forbidden)+ expect(glossary_state).to eq(before)+ end+ end++ it 'does not count the people right' do+ sign_in member_with(role_with('people:view_people', 'people:manage_people'))++ get organisation_glossary_terms_path(organisation)+ expect(response).to have_http_status(:forbidden)+ end++ it 'shows no menu entry in the sidebar and on the mobile "more" page' do+ get organisation_root_path(organisation)+ follow_redirect! while response.redirect?+ expect(response.body).to include(I18n.t('navigation.all_organisations'))+ expect(response.body).not_to include(organisation_glossary_terms_path(organisation))++ get organisation_mobile_more_path(organisation)+ expect(response.body).to include(I18n.t('mobile.more'))+ expect(response.body).not_to include(organisation_glossary_terms_path(organisation))+ end+ end++ describe 'with view_glossary only' do+ before { sign_in viewer }++ it 'lists the terms with category, heard forms, speaker and project, proposals first' do+ get organisation_glossary_terms_path(organisation)++ expect(response).to have_http_status(:ok)+ body = response.body+ expect(body).to include('Lalabase', I18n.t('views.organisations.glossary.categories.product'))+ expect(body).to include('lala bass', 'la la base', 'Erika Beispiel')+ # E3: the project's name also where the reader cannot read the project.+ expect(body).to include('Projekt Ahorn', 'Projekt Birke')+ expect(body.index('Zirbelholz')).to be < body.index('Lalabase')+ expect(body).to include(I18n.t('views.organisations.glossary.statuses.proposed'))+ end++ it 'shows no write controls' do+ get organisation_glossary_terms_path(organisation, term_id: term.id)++ expect(response).to have_http_status(:ok)+ expect(response.body).not_to include(new_organisation_glossary_term_path(organisation))+ expect(response.body).not_to include(edit_organisation_glossary_term_path(organisation, term))+ expect(response.body).not_to include(confirm_organisation_glossary_term_path(organisation, proposal))+ expect(response.body).not_to include(merge_organisation_glossary_term_path(organisation, term))+ expect(response.body).not_to include(correction_organisation_glossary_term_path(organisation, term, correction_id: open_correction.id))+ expect(response.body).to include(I18n.t('views.organisations.glossary.show.read_only'))+ end++ it 'shows a term in the lane frame' do+ get organisation_glossary_term_path(organisation, term), headers: frame_headers++ expect(response).to have_http_status(:ok)+ expect(response.body).to include(%(<turbo-frame id="#{Organisations::GlossaryController::DETAIL_FRAME_ID}">), 'Lalabase', 'lala bass')+ end++ it 'sends a full visit of a term to the index with the lane open' do+ get organisation_glossary_term_path(organisation, term)++ expect(response).to redirect_to(organisation_glossary_terms_path(organisation, term_id: term.id))+ end++ write_names.each do |name|+ it "is refused #{name} with 403 and nothing changes" do+ before = glossary_state+ verb, path, params = write_request(name)++ public_send(verb, path, params: params)++ expect(response).to have_http_status(:forbidden)+ expect(glossary_state).to eq(before)+ end+ end++ %w[new edit].each do |name|+ it "is refused the #{name} form with 403" do+ get frame_path(name), headers: frame_headers++ expect(response).to have_http_status(:forbidden)+ end+ end++ it 'shows the menu entry in the sidebar and on the mobile "more" page' do+ get organisation_root_path(organisation)+ follow_redirect! while response.redirect?+ expect(response.body).to include(%(href="#{organisation_glossary_terms_path(organisation)}"), I18n.t('navigation.glossary'))++ get organisation_mobile_more_path(organisation)+ expect(response.body).to include(%(href="#{organisation_glossary_terms_path(organisation)}"))+ end+ end++ # E3: the title and the link of a meeting need read access to that meeting.+ describe 'meetings in the lane' do+ def lane_for(user)+ sign_in user+ get organisation_glossary_term_path(organisation, term), headers: frame_headers+ response.body+ end++ it 'shows no meeting title to a reader without access to any project, only the project names' do+ body = lane_for(viewer)++ expect(body).to include('Projekt Ahorn', 'Projekt Birke', 'lala bass', 'la la base')+ expect(body).not_to include('Abstimmung Ahorn', 'Geheimrunde Birke')+ expect(body).not_to include("meeting_id=#{open_meeting.id}", "meeting_id=#{closed_meeting.id}")+ end++ it 'shows the title and the link of a meeting the reader may read, and no other' do+ create(:project_permission, user: viewer, project: open_project, meetings_access: :read_only)++ body = lane_for(viewer)++ expect(body).to include('Abstimmung Ahorn', organisation_meetings_path(organisation, meeting_id: open_meeting.id))+ expect(body).not_to include('Geheimrunde Birke', "meeting_id=#{closed_meeting.id}")+ end++ it 'shows every meeting title to an account admin' do+ expect(lane_for(admin)).to include('Abstimmung Ahorn', 'Geheimrunde Birke')+ end++ it 'keeps a heard form of a deleted meeting, without a meeting' do+ open_meeting.destroy!++ body = lane_for(admin)++ expect(body).to include('lala bass', 'Projekt Ahorn')+ expect(body).not_to include('Abstimmung Ahorn')+ end+ end++ # E3: speakers are shown as a name; the link to the person needs view_people.+ describe 'speakers in the lane' do+ def lane_for(user)+ sign_in user+ get organisation_glossary_term_path(organisation, term), headers: frame_headers+ Nokogiri::HTML(response.body)+ end++ it 'names the speaker without a link for a reader without view_people' do+ page = lane_for(viewer)++ expect(page.text).to include('Erika Beispiel')+ expect(page.css(%(a[href*="person_id=#{speaker.id}"]))).to be_empty+ end++ it 'links the speaker for a reader with view_people' do+ page = lane_for(member_with(role_with('view_glossary', 'people:view_people')))++ expect(page.css(%(a[href="#{organisation_people_path(organisation, person_id: speaker.id)}"])).text).to eq('Erika Beispiel')+ end++ it 'names a member speaker through the name display, linked to the member' do+ member = member_with(role_with)+ create(:term_correction, organisation: organisation, glossary_term: term, heard: 'lalabeis', user: member)++ page = lane_for(admin)++ expect(page.css(%(a[href="#{organisation_people_path(organisation, member_id: member.id)}"]))).to be_present+ end+ end++ describe 'filters' do+ before { sign_in viewer }++ let!(:other_term) do+ create(:glossary_term, organisation: organisation, term: 'Ahornsirup', category: 'person').tap do |found|+ create(:term_correction, organisation: organisation, glossary_term: found, heard: 'ahorn sirup', project: open_project)+ end+ end++ def listed+ Nokogiri::HTML(response.body).css('[data-glossary-row] .people-row__name').map(&:text)+ end++ it 'filters by the project a heard form came from' do+ get organisation_glossary_terms_path(organisation, project_id: closed_project.id)++ expect(listed).to eq(['Lalabase'])+ end++ it 'filters by category' do+ get organisation_glossary_terms_path(organisation, category: 'person')++ expect(listed).to eq(['Ahornsirup'])+ end++ it 'filters by status' do+ get organisation_glossary_terms_path(organisation, status: 'proposed')++ expect(listed).to eq(['Zirbelholz'])+ end++ it 'ignores a filter value it does not know' do+ get organisation_glossary_terms_path(organisation, status: 'maybe', category: 'planet', project_id: SecureRandom.uuid)++ expect(listed).to contain_exactly('Zirbelholz', 'Ahornsirup', 'Lalabase')+ end++ it 'offers only the projects heard forms came from' do+ unused = create(:project, organisation: organisation, name: 'Projekt Eibe')++ get organisation_glossary_terms_path(organisation)++ options = Nokogiri::HTML(response.body).css('#glossary-project-filter option').map(&:text)+ expect(options).to include('Projekt Ahorn', 'Projekt Birke')+ expect(options).not_to include(unused.name)+ end+ end++ shared_examples 'may keep the glossary' do+ it 'creates a confirmed term and lands on the list with it open' do+ expect { post organisation_glossary_terms_path(organisation), params: valid_params.merge(status: 'proposed') }+ .to change(GlossaryTerm, :count).by(1)++ created = GlossaryTerm.find_by!(term: 'Wortmarke')+ expect(response).to redirect_to(organisation_glossary_terms_path(organisation, status: 'proposed', term_id: created.id))+ expect([created.status, created.category, created.created_by_id]).to eq(['confirmed', 'company', writer.id])+ end++ it 'refuses a spelling already in the glossary with the form and its message' do+ expect { post organisation_glossary_terms_path(organisation), params: { glossary_term: { term: 'LALABASE' } } }+ .not_to change(GlossaryTerm, :count)++ expect(response).to have_http_status(:unprocessable_content)+ expect(response.body).to include(ERB::Util.html_escape(I18n.t('activerecord.errors.models.glossary_term.attributes.term.taken')))+ expect(response.body).to include('id="glossary_term_term"')+ end++ it 'changes spelling and category' do+ patch organisation_glossary_term_path(organisation, term), params: { glossary_term: { term: 'LalaBase', category: 'domain' } }++ expect(response).to redirect_to(organisation_glossary_terms_path(organisation, term_id: term.id))+ expect([term.reload.term, term.category]).to eq(%w[LalaBase domain])+ end++ it 'confirms and rejects a proposal' do+ patch confirm_organisation_glossary_term_path(organisation, proposal)+ expect(proposal.reload.status).to eq('confirmed')+ expect(response).to redirect_to(organisation_glossary_terms_path(organisation))++ patch reject_organisation_glossary_term_path(organisation, proposal), params: { term_id: proposal.id }+ expect(proposal.reload.status).to eq('rejected')+ expect(response).to redirect_to(organisation_glossary_terms_path(organisation, term_id: proposal.id))+ end++ it 'deletes a term with its heard forms' do+ delete organisation_glossary_term_path(organisation, term)++ expect(response).to redirect_to(organisation_glossary_terms_path(organisation))+ expect(GlossaryTerm.where(id: term.id)).not_to exist+ expect(TermCorrection.where(id: [open_correction.id, closed_correction.id])).not_to exist+ end++ it 'merges a term into another, the heard forms move along' do+ post merge_organisation_glossary_term_path(organisation, term), params: { target_id: proposal.id }++ expect(response).to redirect_to(organisation_glossary_terms_path(organisation, term_id: proposal.id))+ expect(GlossaryTerm.where(id: term.id)).not_to exist+ expect(proposal.term_corrections.reload).to contain_exactly(open_correction, closed_correction)+ end++ it 'refuses to merge a term into itself and changes nothing' do+ before = glossary_state+ post merge_organisation_glossary_term_path(organisation, term), params: { target_id: term.id }++ expect(response).to redirect_to(organisation_glossary_terms_path(organisation, term_id: term.id))+ expect(flash[:alert]).to eq(I18n.t('controllers.glossary.merge.same_term'))+ expect(glossary_state).to eq(before)+ end++ it 'treats a target of another organisation as no target' do+ foreign = ActsAsTenant.with_tenant(other_organisation) { create(:glossary_term, organisation: other_organisation) }+ before = glossary_state++ post merge_organisation_glossary_term_path(organisation, term), params: { target_id: foreign.id }++ expect(flash[:alert]).to eq(I18n.t('controllers.glossary.merge.no_target'))+ expect(glossary_state).to eq(before)+ end++ it 'deletes one heard form and keeps the term' do+ delete correction_organisation_glossary_term_path(organisation, term, correction_id: open_correction.id)++ expect(response).to redirect_to(organisation_glossary_terms_path(organisation, term_id: term.id))+ expect(TermCorrection.where(id: open_correction.id)).not_to exist+ expect(TermCorrection.where(id: closed_correction.id)).to exist+ end++ it 'answers 404 for a heard form of another term' do+ delete correction_organisation_glossary_term_path(organisation, proposal, correction_id: open_correction.id)++ expect(response).to have_http_status(:not_found)+ expect(TermCorrection.where(id: open_correction.id)).to exist+ end++ it 'opens the form in the lane, new and edit' do+ get new_organisation_glossary_term_path(organisation), headers: frame_headers+ expect(response.body).to include('id="glossary_term_term"')++ get edit_organisation_glossary_term_path(organisation, term), headers: frame_headers+ expect(response.body).to include('value="Lalabase"')+ end++ it 'shows confirm and reject on a proposal row, and the write controls in the lane' do+ get organisation_glossary_terms_path(organisation, term_id: term.id)++ expect(response.body).to include(confirm_organisation_glossary_term_path(organisation, proposal),+ reject_organisation_glossary_term_path(organisation, proposal),+ merge_organisation_glossary_term_path(organisation, term),+ correction_organisation_glossary_term_path(organisation, term, correction_id: open_correction.id))+ end+ end++ describe 'with manage_glossary' do+ let(:writer) { manager }++ before { sign_in writer }++ include_examples 'may keep the glossary'+ end++ describe 'with manage_glossary on a guest role (billable: false)' do+ let(:writer) { member_with(role_with('manage_glossary', billable: false)) }++ before { sign_in writer }++ include_examples 'may keep the glossary'+ end++ describe 'as an account admin without any row' do+ let(:writer) { admin }++ before { sign_in writer }++ it 'needs no permission row' do+ expect(Permission.where(category: 'glossary')).not_to exist+ end++ include_examples 'may keep the glossary'+ end++ describe 'a deactivated member who still holds the right' do+ it 'gets nothing of the glossary' do+ sign_in member_with(role_with('manage_glossary'), active: false)++ get organisation_glossary_terms_path(organisation)++ expect(response).to have_http_status(:redirect)+ expect(response.body).not_to include('Lalabase')+ end+ end++ describe 'another organisation' do+ let(:foreign_term) do+ ActsAsTenant.with_tenant(other_organisation) { create(:glossary_term, organisation: other_organisation, term: 'Fremdwort') }+ end++ before { sign_in admin }++ # One request per example: after a 404 the test session is signed out.+ it 'answers 404 for show of a term of another organisation' do+ get organisation_glossary_term_path(organisation, foreign_term), headers: frame_headers++ expect(response).to have_http_status(:not_found)+ end++ it 'answers 404 for update and leaves the term alone' do+ patch organisation_glossary_term_path(organisation, foreign_term), params: { glossary_term: { term: 'Gekapert' } }++ expect(response).to have_http_status(:not_found)+ expect(GlossaryTerm.unscoped.find(foreign_term.id).term).to eq('Fremdwort')+ end++ it 'answers 404 for destroy and keeps the term' do+ delete organisation_glossary_term_path(organisation, foreign_term)++ expect(response).to have_http_status(:not_found)+ expect(GlossaryTerm.unscoped.exists?(foreign_term.id)).to be(true)+ end++ it 'answers 404 for confirm, reject and merge of a term of another organisation' do+ patch reject_organisation_glossary_term_path(organisation, foreign_term)++ expect(response).to have_http_status(:not_found)+ expect(GlossaryTerm.unscoped.find(foreign_term.id).status).to eq('confirmed')+ end++ it 'sends the page of an organisation the user is not in to the organisation picker' do+ foreign_term+ get organisation_glossary_terms_path(other_organisation)++ expect(response).to redirect_to(select_organisation_path)+ end+ end++ describe 'the lane' do+ before { sign_in manager }++ it 'opens a term on a full visit with ?term_id=' do+ get organisation_glossary_terms_path(organisation, term_id: term.id)++ expect(response.body).to include('show-content', 'selected-row', 'lala bass')+ end++ it 'opens the form on a full visit with ?new=term' do+ get organisation_glossary_terms_path(organisation, new: 'term')++ expect(response.body).to include('id="glossary_term_term"')+ end++ it 'answers a lane request of the index with the lane alone' do+ get organisation_glossary_terms_path(organisation, term_id: term.id), headers: frame_headers++ expect(response.body).to start_with(%(<turbo-frame id="#{Organisations::GlossaryController::DETAIL_FRAME_ID}">))+ expect(response.body).not_to include('glossary-tools')+ end+ end++ # Prosopite watches every example: the list preloads heard forms, speakers+ # and projects, and asks the write right once, however many rows.+ describe 'queries' do+ # The fixtures are built in a loop; only the requests are watched.+ before do+ Prosopite.pause do+ 3.times do |index|+ found = create(:glossary_term, :proposed, organisation: organisation, term: "Vorschlag #{index}")+ create(:term_correction, organisation: organisation, glossary_term: found, heard: "vor schlag #{index}",+ project: create(:project, organisation: organisation), user: member_with(role_with))+ create(:term_correction, organisation: organisation, glossary_term: found, heard: "vorschlak #{index}",+ person: create(:person, organisation: organisation), project: open_project)+ end+ end+ end++ it 'renders the list of many terms without an N+1' do+ sign_in manager++ get organisation_glossary_terms_path(organisation)++ expect(response).to have_http_status(:ok)+ expect(Nokogiri::HTML(response.body).css('[data-glossary-row]').size).to eq(5)+ end++ it 'renders a lane with many heard forms without an N+1' do+ sign_in member_with(role_with('manage_glossary', 'people:view_people'))+ target = GlossaryTerm.find_by!(term: 'Vorschlag 0')+ create(:term_correction, organisation: organisation, glossary_term: target, heard: 'vor schlag 0', meeting: open_meeting,+ project: open_project, user: member_with(role_with))++ get organisation_glossary_term_path(organisation, target), headers: frame_headers++ expect(response).to have_http_status(:ok)+ expect(Nokogiri::HTML(response.body).css('.glossary-heard__row').size).to eq(3)+ end+ end++ %w[de en].each do |locale|+ it "renders the page and the lane in #{locale} without a missing text" do+ sign_in admin++ get organisation_glossary_terms_path(organisation, term_id: term.id, locale: locale)++ expect(response).to have_http_status(:ok)+ expect(response.body).not_to include('translation missing', 'Translation missing')+ I18n.with_locale(locale) do+ expect(response.body).to include(ERB::Util.html_escape(I18n.t('views.organisations.glossary.index.title')),+ ERB::Util.html_escape(I18n.t('views.organisations.glossary.show.heard_title')))+ end+ end+ end+end