Skip to content

Commit

Permalink
fix: Recursive permissions to document manager folder are not properl…
Browse files Browse the repository at this point in the history
…y applied

Closes request #38675 Recursive permissions to document manager folder are not properly applied

How to test:
- Pick up a folder containing some folders and documents
- Open its permissions modal
- Set some permissions and click "Apply permissions to all sub-items"
- Submit
--> The permissions have been set on the current folder and all its
descendants.

Change-Id: Id10c3eb04677f21cb4b2ec237622022e84491e1e
  • Loading branch information
gorkat committed Jul 9, 2024
1 parent fc15304 commit 580161e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { shallowMount } from "@vue/test-utils";
import PermissionsUpdateFolderSubItems from "./PermissionsUpdateFolderSubItems.vue";
import { TYPE_FOLDER, TYPE_EMPTY } from "../../../constants";
import { getGlobalTestOptions } from "../../../helpers/global-options-for-test";
import emitter from "../../../helpers/emitter";
import type { Empty, Folder, Item } from "../../../type";

describe("PermissionsUpdateFolderSubItems", () => {
Expand Down Expand Up @@ -50,4 +51,24 @@ describe("PermissionsUpdateFolderSubItems", () => {

expect(wrapper.html()).toMatchInlineSnapshot(`<!--v-if-->`);
});

it.each([
["checked", true],
["unchecked", false],
])(
'When the checkbox is %s, then it should emit a "update-apply-permissions-on-children" event containing the checkbox state.',
(state, is_checked) => {
const emit = jest.spyOn(emitter, "emit");
const wrapper = getWrapper({ type: TYPE_FOLDER } as Folder);
const checkbox = wrapper.find<HTMLInputElement>(
"[data-test=checkbox-apply-permissions-on-children]",
);

checkbox.setValue(is_checked);
checkbox.trigger("input");
expect(emit).toHaveBeenCalledWith("update-apply-permissions-on-children", {
do_permissions_apply_on_children: is_checked,
});
},
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
<template>
<div class="tlp-form-element" v-if="is_item_a_folder">
<label class="tlp-label tlp-checkbox">
<input type="checkbox" v-bind:value="props.value" v-on:input="onInput" />
<input
type="checkbox"
v-on:input="onInput"
data-test="checkbox-apply-permissions-on-children"
/>
{{ $gettext("Apply same permissions to all sub-items of this folder") }}
</label>
</div>
Expand All @@ -29,18 +33,17 @@
import { isFolder } from "../../../helpers/type-check-helper";
import type { Folder } from "../../../type";
import { computed } from "vue";
import emitter from "../../../helpers/emitter";
const props = defineProps<{ item: Folder }>();
const emit = defineEmits<{
(e: "input", value: string): void;
}>();
function onInput($event: Event): void {
const event_target = $event.target;
if (event_target instanceof HTMLInputElement) {
emit("input", event_target.value);
emitter.emit("update-apply-permissions-on-children", {
do_permissions_apply_on_children: event_target.checked,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,34 @@ describe("PermissionsUpdateModal", () => {
};
expect(wrapper.vm.updated_permissions).toEqual(expected_permissions_to_update_state);
});

it('When an event "update-apply-permissions-on-children" is received, then it should update do_permissions_apply_on_children', () => {
const item = {
id: 104,
title: "My item",
permissions_for_groups: {
can_read: [],
can_write: [],
can_manage: [],
},
};

const wrapper = factory({ item });

wrapper.setData({
updated_permissions: {
...item.permissions_for_groups,
apply_permissions_on_children: false,
},
});

emitter.emit("update-apply-permissions-on-children", {
do_permissions_apply_on_children: true,
});

expect(wrapper.vm.updated_permissions).toStrictEqual({
...item.permissions_for_groups,
apply_permissions_on_children: true,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@
v-model="updated_permissions"
v-bind:value="updated_permissions"
/>
<permissions-update-folder-sub-items
v-bind:item="item"
v-model="updated_permissions.apply_permissions_on_children"
/>
<permissions-update-folder-sub-items v-bind:item="item" />
</div>
</div>
<modal-footer
Expand Down Expand Up @@ -119,6 +116,7 @@ export default {
this.modal = createModal(this.$el);
emitter.on("show-update-permissions-modal", this.show);
emitter.on("update-permissions", this.updateUGroup);
emitter.on("update-apply-permissions-on-children", this.setApplyPermissionsOnChildren);
this.modal.addEventListener("tlp-modal-hidden", this.reset);
this.show();
},
Expand Down Expand Up @@ -182,6 +180,13 @@ export default {
default:
}
},
setApplyPermissionsOnChildren(event) {
this.updated_permissions = {
...this.updated_permissions,
apply_permissions_on_children: event.do_permissions_apply_on_children,
};
},
},
};
</script>
5 changes: 5 additions & 0 deletions plugins/document/scripts/document/helpers/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export interface UpdateCriteriaDateEvent {
value: SearchDate;
}

export type UpdateApplyPermissionsOnChildren = {
do_permissions_apply_on_children: boolean;
};

export type Events = {
"update-status-property": string;
"update-status-recursion": boolean;
Expand Down Expand Up @@ -129,6 +133,7 @@ export type Events = {
"properties-recursion-list": UpdatePropertyListEvent;

"update-permissions": string;
"update-apply-permissions-on-children": UpdateApplyPermissionsOnChildren;
"update-global-criteria": string;

"update-criteria": UpdateCriteriaEvent;
Expand Down

0 comments on commit 580161e

Please sign in to comment.