Skip to content

Commit

Permalink
[FIX] project: hide create task stage option from the project kanban
Browse files Browse the repository at this point in the history
Due to the project user's inability to create a task stage, we have removed the
'create stage' option from the kanban view.

task-3511164

closes #140297

Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
  • Loading branch information
kusi-odoo authored and xavierbol committed Mar 27, 2024
1 parent 3abb836 commit cadf148
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import { KanbanRenderer } from '@web/views/kanban/kanban_renderer';
import { ProjectTaskKanbanRecord } from './project_task_kanban_record';
import { ProjectTaskKanbanHeader } from './project_task_kanban_header';
import { useService } from '@web/core/utils/hooks';
import { onWillStart } from "@odoo/owl";

export class ProjectTaskKanbanRenderer extends KanbanRenderer {
setup() {
super.setup();
this.action = useService('action');
const user = useService("user");

onWillStart(async () => {
this.isProjectManager = await user.hasGroup('project.group_project_manager');
});
}

get canMoveRecords() {
Expand All @@ -33,7 +38,7 @@ export class ProjectTaskKanbanRenderer extends KanbanRenderer {
}

canCreateGroup() {
return (super.canCreateGroup() && this.isProjectTasksContext() && this.props.list.isGroupedByStage) || this.props.list.isGroupedByPersonalStages;
return (super.canCreateGroup() && this.isProjectTasksContext() && this.props.list.isGroupedByStage && this.isProjectManager) || this.props.list.isGroupedByPersonalStages;
}

isProjectTasksContext() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* @odoo-module */

import { registry } from "@web/core/registry";
import { startServer } from "@bus/../tests/helpers/mock_python_environment";
import { addModelNamesToFetch } from "@bus/../tests/helpers/model_definitions_helpers";
import { makeFakeUserService } from "@web/../tests/helpers/mock_services";

import { start } from "@mail/../tests/helpers/test_utils";

import { getFixture, click } from "@web/../tests/helpers/utils";
import { setupViewRegistries } from "@web/../tests/views/helpers";

const serviceRegistry = registry.category("services");

addModelNamesToFetch(["project.project", "project.task", "project.task.type"]);

let target;

QUnit.module('Project', {
beforeEach: async function () {
const pyEnv = await startServer();
const projectId = pyEnv['project.project'].create([
{ name: "Project One" },
]);
const stageId = pyEnv['project.task.type'].create([
{ name: "New" },
]);
pyEnv['project.task'].create([
{ name: 'task one', project_id: projectId, stage_id: stageId },
]);
this.views = {
"project.task,false,kanban":
`<kanban js_class="project_task_kanban">
<templates>
<t t-name="kanban-box">
<div>
<field name="name"/>
</div>
</t>
</templates>
</kanban>`,
};
target = getFixture();
setupViewRegistries();
}
}, function () {
QUnit.test("quick create button is visible when the user has access rights.", async function (assert) {
serviceRegistry.add(
"user",
makeFakeUserService((group) => group === "project.group_project_manager"),
{ force: true },
);
const { views } = this;
const { openView } = await start({ serverData: { views } });
await openView({
res_model: "project.task",
views: [[false, "kanban"]],
context: {
active_model: "project.project",
default_project_id: 1,
group_by: ["stage_id"],
},
});

assert.containsOnce(target, ".o_column_quick_create", "The quick create button should be visible.");
await click(target, ".o_kanban_add_column");
});

QUnit.test("quick create button is not visible when the user not have access rights.", async function (assert) {
const { views } = this;
const { openView } = await start({ serverData: { views } });
await openView({
res_model: "project.task",
views: [[false, "kanban"]],
context: {
active_model: "project.project",
default_project_id: 1,
group_by: ["stage_id"],
},
});

assert.containsNone(target, ".o_column_quick_create", "The quick create button should be hidden.");
});
});

0 comments on commit cadf148

Please sign in to comment.