Skip to content

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

Add service for assignee (#8270)

Oliver Günther3ea5b1c46235
diff --git a/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.ts b/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.ts
new file mode 100644
index 00000000000..71543abbd4a
--- /dev/null
+++ b/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-action.service.ts
@@ -0,0 +1,133 @@
+import {Injectable} from "@angular/core";
+import {BoardListsService} from "core-app/modules/boards/board/board-list/board-lists.service";
+import {Board} from "core-app/modules/boards/board/board";
+import {QueryResource} from "core-app/modules/hal/resources/query-resource";
+import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service";
+import {HalResource} from "core-app/modules/hal/resources/hal-resource";
+import {I18nService} from "core-app/modules/common/i18n/i18n.service";
+import {FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder";
+import {CreateAutocompleterComponent} from "core-app/modules/common/autocomplete/create-autocompleter.component";
+import {OpContextMenuItem} from "core-components/op-context-menu/op-context-menu.types";
+import {UserCacheService} from 'core-app/components/user/user-cache.service';
+import {UserResource} from 'core-app/modules/hal/resources/user-resource';
+import {CurrentProjectService} from 'core-app/components/projects/current-project.service';
+import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource';
+import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';
+import {AssigneeBoardHeaderComponent} from "core-app/modules/boards/board/board-actions/assignee/assignee-board-header.component";
+
+@Injectable()
+export class BoardAssigneeActionService implements BoardActionService {
+
+ constructor(protected boardListsService:BoardListsService,
+ protected I18n:I18nService,
+ protected userCache:UserCacheService,
+ protected halResourceService:HalResourceService,
+ protected currentProject:CurrentProjectService
+ ) {
+ }
+
+ public get localizedName() {
+ return this.I18n.t('js.work_packages.properties.assignee');
+ }
+
+ /**
+ * Returns the current filter value if any
+ * @param query
+ * @returns /api/v3/assignee/:id if a assignee filter exists
+ */
+ public getFilterHref(query:QueryResource):string|undefined {
+ const filter = _.find(query.filters, filter => filter.id === 'assignee');
+ if (filter) {
+ const value = filter.values[0] as string|HalResource;
+ return (value instanceof HalResource) ? value.href! : value;
+ }
+
+ return;
+ }
+
+ /**
+ * Returns the loaded assignee
+ * @param query
+ */
+ public getLoadedFilterValue(query:QueryResource):Promise<undefined|UserResource> {
+ const href = this.getFilterHref(query);
+
+ if (href) {
+ const id = HalResource.idFromLink(href);
+ return this.userCache.require(id);
+ } else {
+ return Promise.resolve(undefined);
+ }
+ }
+
+ public canAddToQuery(query:QueryResource):Promise<boolean> {
+ return Promise.resolve(true);
+ }
+
+ public addActionQueries(board:Board):Promise<Board> {
+ return Promise.resolve(board);
+ }
+
+ public addActionQuery(board:Board, value:HalResource):Promise<Board> {
+ let params:any = {
+ name: value.name,
+ };
+
+ let filter = {
+ assignee: {
+ operator: '=' as FilterOperator,
+ values: [value.id]
+ }
+ };
+
+ return this.boardListsService.addQuery(board, params, [filter]);
+ }
+
+ /**
+ * Return available assignees for new lists, given the list of active
+ * queries in the board.
+ *
+ * @param board The board we're looking at
+ * @param queries The active set of queries
+ */
+ public getAvailableValues(board:Board, queries:QueryResource[]):Promise<HalResource[]> {
+ const active = new Set(
+ queries.map(query => this.getFilterHref(query))
+ );
+
+ return this.getAssignees(board)
+ .then(results =>
+ results.filter(assignee => !active.has(assignee.href!))
+ );
+ }
+
+ public getAdditionalListMenuItems(query:QueryResource):Promise<OpContextMenuItem[]> {
+ return Promise.resolve([]);
+ }
+
+ dragIntoAllowed(query:QueryResource, value:HalResource|undefined) {
+ return true;
+ }
+
+ public autocompleterComponent() {
+ return CreateAutocompleterComponent;
+ }
+
+ public headerComponent() {
+ return AssigneeBoardHeaderComponent;
+ }
+
+ public disabledAddButtonPlaceholder(assignee:UserResource) {
+ return undefined;
+ }
+
+ private getAssignees(board:Board):Promise<UserResource[]> {
+ const projectIdentifier = this.currentProject.identifier!;
+ let myData = this.halResourceService.get('/api/v3/projects/' + projectIdentifier + '/available_assignees').toPromise();
+
+
+ return myData
+ .then((collection:CollectionResource<UserResource>) => collection.elements);
+ }
+
+}
diff --git a/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-board-header.component.ts b/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-board-header.component.ts
new file mode 100644
index 00000000000..e241a105153
--- /dev/null
+++ b/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-board-header.component.ts
@@ -0,0 +1,39 @@
+//-- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2020 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 docs/COPYRIGHT.rdoc for more details.
+//++
+import {Component, Input} from "@angular/core";
+import {UserResource} from "core-app/modules/hal/resources/user-resource";
+
+
+@Component({
+ templateUrl: './assignee-board-header.html',
+ styleUrls: ['./assignee-board-header.sass'],
+ host: { 'class': 'title-container -small' }
+})
+export class AssigneeBoardHeaderComponent {
+ @Input('resource') public user:UserResource;
+}
diff --git a/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-board-header.html b/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-board-header.html
new file mode 100644
index 00000000000..ad90fdb50ae
--- /dev/null
+++ b/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-board-header.html
@@ -0,0 +1,6 @@
+<div class="assignee-board-header" *ngIf="user">
+ <user-avatar [user]="user" data-class-list="avatar-mini"></user-avatar>
+ <h2 [textContent]="user.name"
+ class="editable-toolbar-title--fixed">
+ </h2>
+</div>
diff --git a/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-board-header.sass b/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-board-header.sass
new file mode 100644
index 00000000000..aaa8b8d3897
--- /dev/null
+++ b/frontend/src/app/modules/boards/board/board-actions/assignee/assignee-board-header.sass
@@ -0,0 +1,6 @@
+.assignee-board-header
+ display: flex
+
+ user-avatar
+ align-self: center
+ padding-right: 5px
diff --git a/frontend/src/app/modules/boards/boards-root/boards-root.component.ts b/frontend/src/app/modules/boards/boards-root/boards-root.component.ts
index 032fe66b87e..2746bd8a972 100644
--- a/frontend/src/app/modules/boards/boards-root/boards-root.component.ts
+++ b/frontend/src/app/modules/boards/boards-root/boards-root.component.ts
@@ -4,6 +4,7 @@ import {BoardActionsRegistryService} from "core-app/modules/boards/board/board-a
import {BoardStatusActionService} from "core-app/modules/boards/board/board-actions/status/status-action.service";
import {BoardVersionActionService} from "core-app/modules/boards/board/board-actions/version/version-action.service";
import {QueryUpdatedService} from "core-app/modules/boards/board/query-updated/query-updated.service";
+import {BoardAssigneeActionService} from "core-app/modules/boards/board/board-actions/assignee/assignee-action.service";
@Component({
selector: 'boards-entry',
@@ -12,7 +13,8 @@ import {QueryUpdatedService} from "core-app/modules/boards/board/query-updated/q
BoardConfigurationService,
BoardStatusActionService,
BoardVersionActionService,
- QueryUpdatedService
+ BoardAssigneeActionService,
+ QueryUpdatedService,
]
})
export class BoardsRootComponent {
@@ -23,8 +25,10 @@ export class BoardsRootComponent {
const registry = injector.get(BoardActionsRegistryService);
const statusAction = injector.get(BoardStatusActionService);
const versionAction = injector.get(BoardVersionActionService);
+ const assigneeAction = injector.get(BoardAssigneeActionService);
registry.add('status', statusAction);
+ registry.add('assignee', assigneeAction);
registry.add('version', versionAction);
}
}
diff --git a/frontend/src/app/modules/boards/openproject-boards.module.ts b/frontend/src/app/modules/boards/openproject-boards.module.ts
index aee74c02ea3..0f8f2bded5f 100644
--- a/frontend/src/app/modules/boards/openproject-boards.module.ts
+++ b/frontend/src/app/modules/boards/openproject-boards.module.ts
@@ -47,6 +47,7 @@ import {DragScrollModule} from "cdk-drag-scroll";
import {BoardListMenuComponent} from "core-app/modules/boards/board/board-list/board-list-menu.component";
import {VersionBoardHeaderComponent} from "core-app/modules/boards/board/board-actions/version/version-board-header.component";
import {DynamicModule} from "ng-dynamic-component";
+import {AssigneeBoardHeaderComponent} from "core-app/modules/boards/board/board-actions/assignee/assignee-board-header.component";
const menuItemClass = 'board-view-menu-item';
@@ -63,7 +64,7 @@ export const BOARDS_ROUTES:Ng2StateDeclaration[] = [
},
params: {
// Use custom encoder/decoder that ensures validity of URL string
- query_props: {type: 'opQueryString', dynamic: true}
+ query_props: { type: 'opQueryString', dynamic: true }
},
redirectTo: 'boards.list',
component: BoardsRootComponent
@@ -81,8 +82,8 @@ export const BOARDS_ROUTES:Ng2StateDeclaration[] = [
name: 'boards.show',
url: '{board_id}',
params: {
- board_id: {type: 'int'},
- isNew: {type: 'bool', inherit: false, dynamic: true}
+ board_id: { type: 'int' },
+ isNew: { type: 'bool', inherit: false, dynamic: true }
},
reloadOnSearch: false,
component: BoardComponent,
@@ -135,6 +136,7 @@ export function uiRouterBoardsConfiguration(uiRouter:UIRouter) {
BoardListMenuComponent,
BoardFilterComponent,
VersionBoardHeaderComponent,
+ AssigneeBoardHeaderComponent,
]
})
export class OpenprojectBoardsModule {
diff --git a/modules/boards/spec/features/action_boards/assignee_board_spec.rb b/modules/boards/spec/features/action_boards/assignee_board_spec.rb
new file mode 100644
index 00000000000..3f7dcce427c
--- /dev/null
+++ b/modules/boards/spec/features/action_boards/assignee_board_spec.rb
@@ -0,0 +1,132 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+require_relative './../support/board_index_page'
+require_relative './../support/board_page'
+
+describe 'Assignee action board',
+ type: :feature,
+ driver: :firefox_headless_en,
+ js: true do
+ let(:bobself_user) do
+ FactoryBot.create(:user,
+ firstname: 'Bob',
+ lastname: 'Self',
+ member_in_project: project,
+ member_through_role: role)
+ end
+ let(:type) { FactoryBot.create(:type_standard) }
+ let(:project) { FactoryBot.create(:project, types: [type], enabled_module_names: %i[work_package_tracking board_view]) }
+ let(:role) { FactoryBot.create(:role, permissions: permissions) }
+
+ let(:board_index) { Pages::BoardIndex.new(project) }
+
+ let(:permissions) {
+ %i[show_board_views manage_board_views add_work_packages
+ edit_work_packages view_work_packages manage_public_queries]
+ }
+
+ let!(:priority) { FactoryBot.create :default_priority }
+
+
+ # Set up other assignees
+
+ let!(:foobar_user) do
+ FactoryBot.create(:user,
+ firstname: 'Foo',
+ lastname: 'Bar',
+ member_in_project: project,
+ member_through_role: role)
+ end
+
+ let!(:work_package) { FactoryBot.create :work_package,
+ project: project,
+ assigned_to: bobself_user,
+ subject: 'Some Task' }
+
+ before do
+ with_enterprise_token :board_view
+ login_as(bobself_user)
+ end
+
+ it 'allows to move a task between two assignees' do
+ # Move to the board index page
+ board_index.visit!
+
+ # Create new board
+ board_page = board_index.create_board action: :Assignee, expect_empty: true
+
+ # Expect no assignees to be present
+ board_page.expect_empty
+
+ # Add myself to the board list
+ board_page.add_list option: 'Bob Self'
+ board_page.expect_list 'Bob Self'
+
+ # Add the other user to the board list
+ board_page.add_list option: 'Foo Bar'
+ board_page.expect_list 'Foo Bar'
+
+ board_page.board(reload: true) do |board|
+ expect(board.name).to eq 'Action board (assignee)'
+ queries = board.contained_queries
+ expect(queries.count).to eq(2)
+
+ bob = queries.first
+ foo = queries.last
+
+ expect(bob.name).to eq 'Bob Self'
+ expect(foo.name).to eq 'Foo Bar'
+
+ expect(bob.filters.first.name).to eq :assigned_to_id
+ expect(bob.filters.first.values).to eq [bobself_user.id.to_s]
+
+ expect(foo.filters.first.name).to eq :assigned_to_id
+ expect(foo.filters.first.values).to eq [foobar_user.id.to_s]
+ end
+
+ # First, expect work package to be assigned to "Bob self"
+ # For this, test the Bob self column to contain the work package
+ board_page.expect_card 'Bob Self', 'Some Task'
+
+ # Then, move the work package from one column to the next one
+ board_page.move_card(0, from: 'Bob Self', to: 'Foo Bar')
+
+ # Then, the work package should be in the other column
+ # and assigned to "Foo Bar" user
+ board_page.expect_card 'Foo Bar', 'Some Task'
+ board_page.expect_card 'Bob Self', 'Some Task', present: false
+
+ # Expect to have changed the avatar
+ expect(page).to have_selector('.wp-card--assignee .avatar-default', text: 'FB', wait: 10)
+
+ work_package.reload
+ expect(work_package.assigned_to).to eq(foobar_user)
+ end
+end
diff --git a/modules/boards/spec/features/support/board_index_page.rb b/modules/boards/spec/features/support/board_index_page.rb
index f00840efb98..e0980ea2710 100644
--- a/modules/boards/spec/features/support/board_index_page.rb
+++ b/modules/boards/spec/features/support/board_index_page.rb
@@ -56,7 +56,7 @@ module Pages
expect(page).to have_conditional_selector(present, 'td.name', text: name)
end
- def create_board(action: nil)
+ def create_board(action: nil, expect_empty: false)
page.find('.toolbar-item a', text: 'Board').click
if action == nil
@@ -66,7 +66,10 @@ module Pages
find('.button', text: 'Action board').click
end
- expect(page).to have_selector('.boards-list--item', wait: 10)
+ unless expect_empty
+ expect(page).to have_selector('.boards-list--item', wait: 10)
+ end
+
::Pages::Board.new ::Boards::Grid.last
end