Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW][FIX] project: hide create task stage option from the project kanban #159546

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.");
});
});