OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Only show create team planner if user has the correct rights
Benjamin Bädorf0c525649127b
diff --git a/frontend/src/app/shared/components/op-view-select/op-view-select.component.ts b/frontend/src/app/shared/components/op-view-select/op-view-select.component.tsindex ec45d5a5ff7..68466a9420c 100644--- a/frontend/src/app/shared/components/op-view-select/op-view-select.component.ts+++ b/frontend/src/app/shared/components/op-view-select/op-view-select.component.ts@@ -52,6 +52,8 @@ import { ViewsResourceService } from 'core-app/core/state/views/views.service';import { IView } from 'core-app/core/state/views/view.model';import idFromLink from 'core-app/features/hal/helpers/id-from-link';import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';+import { CurrentUserService } from 'core-app/core/current-user/current-user.service';+import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';export type ViewType = 'WorkPackagesTable'|'Bim'|'TeamPlanner';@@ -75,7 +77,7 @@ export class ViewSelectComponent extends UntilDestroyedMixin implements OnInit {no_results: this.I18n.t('js.work_packages.query.text_no_results'),};- public $views:Observable<IOpSidemenuItem[]>;+ public views$:Observable<IOpSidemenuItem[]>;@Input() menuItems:string[] = [];@@ -87,9 +89,9 @@ export class ViewSelectComponent extends UntilDestroyedMixin implements OnInit {private apiViewType:string;- private $viewCategories = new BehaviorSubject<IOpSidemenuItem[]>([]);+ private viewCategories$ = new BehaviorSubject<IOpSidemenuItem[]>([]);- private $search = new BehaviorSubject<string>('');+ private search$ = new BehaviorSubject<string>('');private initialized = false;@@ -102,13 +104,15 @@ export class ViewSelectComponent extends UntilDestroyedMixin implements OnInit {readonly mainMenuService:MainMenuNavigationService,readonly cdRef:ChangeDetectorRef,readonly viewsService:ViewsResourceService,+ readonly currentUserService:CurrentUserService,+ readonly currentProjectService:CurrentProjectService,) {super();}public set search(input:string) {- if (this.$search.value !== input) {- this.$search.next(input);+ if (this.search$.value !== input) {+ this.search$.next(input);}}@@ -121,9 +125,9 @@ export class ViewSelectComponent extends UntilDestroyedMixin implements OnInit {.onActivate(...this.menuItems).subscribe(() => this.initializeAutocomplete());- this.$views = combineLatest(- this.$search,- this.$viewCategories,+ this.views$ = combineLatest(+ this.search$,+ this.viewCategories$,).pipe(map(([searchText, categories]) => categories@@ -183,10 +187,15 @@ export class ViewSelectComponent extends UntilDestroyedMixin implements OnInit {);}- this.viewsService- .fetchViews(params)+ combineLatest(+ this.viewsService.fetchViews(params),+ this.currentUserService.hasCapabilities$(+ 'team_planners/create',+ this.currentProjectService.id || undefined,+ ),+ ).pipe(this.untilDestroyed())- .subscribe((queryCollection) => {+ .subscribe(([queryCollection, canAddTeamPlanners]) => {queryCollection._embedded.elements.forEach((view) => {let cat = 'private';if (view.public) {@@ -201,13 +210,17 @@ export class ViewSelectComponent extends UntilDestroyedMixin implements OnInit {const staticQueries = this.opStaticQueries.getStaticQueriesForView(this.viewType);const newQueryLink = this.opStaticQueries.getCreateNewQueryForView(this.viewType);- this.$viewCategories.next([+ const viewCategories = [{ title: this.text.scope_starred, children: categories.starred, collapsible: true },{ title: this.text.scope_default, children: staticQueries, collapsible: true },{ title: this.text.scope_global, children: categories.public, collapsible: true },{ title: this.text.scope_private, children: categories.private, collapsible: true },- { title: this.text.scope_new, children: newQueryLink, collapsible: true },- ]);+ ];++ if (canAddTeamPlanners) {+ viewCategories.push({ title: this.text.scope_new, children: newQueryLink, collapsible: true });+ }+ this.viewCategories$.next(viewCategories);});}diff --git a/frontend/src/app/shared/components/op-view-select/op-view-select.template.html b/frontend/src/app/shared/components/op-view-select/op-view-select.template.htmlindex 9ce874ed6d6..f486c921136 100644--- a/frontend/src/app/shared/components/op-view-select/op-view-select.template.html+++ b/frontend/src/app/shared/components/op-view-select/op-view-select.template.html@@ -14,12 +14,12 @@</div><p class="searchable-menu--no-results-container"- [hidden]="($views | async).length > 0"+ [hidden]="(views$ | async).length > 0"[textContent]="text.no_results"></p><op-sidemenuclass="op-view-select--search-results"- [items]="$views | async"+ [items]="views$ | async"[collapsible]="true"[searchable]="true">diff --git a/modules/team_planner/spec/features/team_planner_menu_spec.rb b/modules/team_planner/spec/features/team_planner_menu_spec.rbnew file mode 100644index 00000000000..aa9ba331fc5--- /dev/null+++ b/modules/team_planner/spec/features/team_planner_menu_spec.rb@@ -0,0 +1,86 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'+require_relative '../support/pages/team_planner'++describe 'Team planner sidemenu', type: :feature, js: true do+ shared_let(:project) do+ FactoryBot.create(:project, enabled_module_names: %w[work_package_tracking team_planner_view])+ end+ shared_let(:team_planner) { ::Pages::TeamPlanner.new project }++ context 'with a user that does not have create rights' do+ shared_let(:user_without_rights) do+ FactoryBot.create :user,+ member_in_project: project,+ member_with_permissions: %w[+ view_work_packages edit_work_packages add_work_packages+ view_team_planner+ ]+ end++ current_user { user_without_rights }++ it 'hides the create team planner option if you do not have rights' do+ visit project_path(project)++ within '#main-menu' do+ click_link 'Team planner'+ end++ team_planner.expect_no_menu_item('Create new planner')+ end+ end++ context 'with a user that has create rights' do+ shared_let(:user_with_rights) do+ FactoryBot.create :user,+ member_in_project: project,+ member_with_permissions: %w[+ view_work_packages edit_work_packages add_work_packages+ view_team_planner manage_team_planner+ ]+ end+++ current_user { user_with_rights }++ it 'hides the create team planner option if you do not have rights' do+ visit project_path(project)++ within '#main-menu' do+ click_link 'Team planner'+ end++ team_planner.expect_menu_item('Create new planner')+ end+ end+enddiff --git a/modules/team_planner/spec/support/pages/team_planner.rb b/modules/team_planner/spec/support/pages/team_planner.rbindex 3a7f7bf21b0..48f377888a6 100644--- a/modules/team_planner/spec/support/pages/team_planner.rb+++ b/modules/team_planner/spec/support/pages/team_planner.rb@@ -176,5 +176,17 @@ module Pagesdef expect_wp_not_draggable(work_package)expect(page).to have_selector('.fc-event:not(.fc-event-draggable)', text: work_package.subject)end++ def expect_menu_item(name)+ expect(page).to have_selector('.op-sidemenu--item-title', text: name)+ end++ def click_menu_item(name)+ page.find('.op-sidemenu--item-title', text: name).click+ end++ def expect_no_menu_item(name)+ expect(page).to_not have_selector('.op-sidemenu--item-title', text: name)+ endendend