From b034ab5a8eb8f3478e51244761649954f0ffe918 Mon Sep 17 00:00:00 2001 From: 0ko <0ko@noreply.codeberg.org> Date: Sun, 5 May 2024 23:14:57 +0500 Subject: [PATCH] [UI] Allow org members to navigate between the org and the dashboard - add a new button to the org view that is only shown to the org members - add integration test to verify the expected navigatability - add a new translation string to that button - fix display style of "View " button on the dashboard - fix gap size between buttons on the org view by utilizing the common class top-right-buttons --- options/locale/locale_en-US.ini | 1 + release-notes/8.0.0/feat/3642.md | 1 + templates/org/header.tmpl | 5 ++- templates/user/dashboard/navbar.tmpl | 2 +- tests/integration/org_nav_test.go | 51 ++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 release-notes/8.0.0/feat/3642.md create mode 100644 tests/integration/org_nav_test.go diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 9148d57a2..9547ba1c0 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2733,6 +2733,7 @@ org_name_holder = Organization name org_full_name_holder = Organization full name org_name_helper = Organization names should be short and memorable. create_org = Create organization +open_dashboard = Open dashboard repo_updated = Updated members = Members teams = Teams diff --git a/release-notes/8.0.0/feat/3642.md b/release-notes/8.0.0/feat/3642.md new file mode 100644 index 000000000..2a93b15b7 --- /dev/null +++ b/release-notes/8.0.0/feat/3642.md @@ -0,0 +1 @@ +Allow navigating to the organization dashboard from the organization view diff --git a/templates/org/header.tmpl b/templates/org/header.tmpl index 7361df99e..3da3be895 100644 --- a/templates/org/header.tmpl +++ b/templates/org/header.tmpl @@ -7,7 +7,7 @@ {{if .Org.Visibility.IsLimited}}{{ctx.Locale.Tr "org.settings.visibility.limited_shortname"}}{{end}} {{if .Org.Visibility.IsPrivate}}{{ctx.Locale.Tr "org.settings.visibility.private_shortname"}}{{end}} - + {{if .EnableFeed}} {{svg "octicon-rss" 24}} @@ -16,6 +16,9 @@ {{if .IsSigned}} {{template "org/follow_unfollow" .}} {{end}} + {{if .IsOrganizationMember}} + {{ctx.Locale.Tr "org.open_dashboard"}} + {{end}} {{if .RenderedDescription}}
{{.RenderedDescription}}
{{end}} diff --git a/templates/user/dashboard/navbar.tmpl b/templates/user/dashboard/navbar.tmpl index b2ee198b0..1fa356f95 100644 --- a/templates/user/dashboard/navbar.tmpl +++ b/templates/user/dashboard/navbar.tmpl @@ -92,7 +92,7 @@ {{end}} diff --git a/tests/integration/org_nav_test.go b/tests/integration/org_nav_test.go new file mode 100644 index 000000000..6fe3a9d2c --- /dev/null +++ b/tests/integration/org_nav_test.go @@ -0,0 +1,51 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package integration + +import ( + "net/http" + "testing" + + "code.gitea.io/gitea/tests" +) + +// This test makes sure that organization members are able to navigate between `/` and `/org//
` freely. +// The `/org//
` page is only accessible to the members of the organization. It doesn't have +// a special logic to show the button or not. +// The `/` page utilizes the `IsOrganizationMember` function to show the button for navigation to +// the organization dashboard. That function is covered by a test and is supposed to be true for the +// owners/admins/members of the organization. +func TestOrgNavigationDashboard(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + // Login as the future organization admin and create an organization + session1 := loginUser(t, "user2") + session1.MakeRequest(t, NewRequestWithValues(t, "POST", "/org/create", map[string]string{ + "_csrf": GetCSRF(t, session1, "/org/create"), + "org_name": "org_navigation_test", + "visibility": "0", + "repo_admin_change_team_access": "on", + }), http.StatusSeeOther) + + // Check if the "Open dashboard" button is available to the org admin (member) + resp := session1.MakeRequest(t, NewRequest(t, "GET", "/org_navigation_test"), http.StatusOK) + doc := NewHTMLParser(t, resp.Body) + doc.AssertElement(t, "#org-info a[href='/org/org_navigation_test/dashboard']", true) + + // Check if the "View " button is available on dashboard for the org admin (member) + resp = session1.MakeRequest(t, NewRequest(t, "GET", "/org/org_navigation_test/dashboard"), http.StatusOK) + doc = NewHTMLParser(t, resp.Body) + doc.AssertElement(t, ".dashboard .secondary-nav a[href='/org_navigation_test']", true) + + // Login a non-member user + session2 := loginUser(t, "user4") + + // Check if the "Open dashboard" button is available to non-member + resp = session2.MakeRequest(t, NewRequest(t, "GET", "/org_navigation_test"), http.StatusOK) + doc = NewHTMLParser(t, resp.Body) + doc.AssertElement(t, "#org-info a[href='/org/org_navigation_test/dashboard']", false) + + // There's no need to test "View " button on dashboard as non-member + // because this page is not supposed to be visitable for this user +}