[FIX] project: hide create task stage option from the project kanban
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 odoo/odoo#159557 X-original-commit: cadf1483948295397137284a01ddf219169bcecd Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
committed by
Xavier Bol (xbo)
parent
1a1c59095d
commit
8a1f1354f9
@@ -4,17 +4,23 @@ 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');
|
||||
});
|
||||
}
|
||||
|
||||
canCreateGroup() {
|
||||
// This restrict the creation of project stages to the kanban view of a given project
|
||||
return super.canCreateGroup() && (this.isProjectTasksContext() == this.props.list.isGroupedByStage);
|
||||
return super.canCreateGroup() && (this.isProjectTasksContext() == this.props.list.isGroupedByStage
|
||||
&& this.isProjectManager || this.props.list.groupByField.name === 'personal_stage_type_id');
|
||||
}
|
||||
|
||||
isProjectTasksContext() {
|
||||
|
||||
+84
@@ -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.");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user