Unverified Commit 1fe37b09 authored by John Chilton's avatar John Chilton Committed by GitHub
Browse files

Merge pull request #17337 from davelopez/23.1_fix_tag_edit_on_shared_pages

[23.1] Disable tag editing on non-owned Pages
parents ac6fe733 d1eaff9b
Loading
Loading
Loading
Loading
+20 −22
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import flushPromises from "flush-promises";
import { PiniaVuePlugin } from "pinia";
import { createTestingPinia } from "@pinia/testing";
import { parseISO, formatDistanceToNow } from "date-fns";
import { useUserStore } from "stores/userStore";

jest.mock("app");

@@ -95,13 +96,26 @@ describe("PgeList.vue", () => {
    const mockPublishedPageData = [publishedPage];
    const mockTwoPageData = [privatePage, pageA];

    function mountPersonalGrid() {
    function mountGrid(propsData) {
        const pinia = createTestingPinia();
        const userStore = useUserStore();
        userStore.currentUser = { username: "jimmyPage", tags_used: [] };

        wrapper = mount(PageList, {
            propsData: propsDataPersonalGrid,
            propsData,
            localVue,
            pinia,
        });
    }

    function mountPersonalGrid() {
        mountGrid(propsDataPersonalGrid);
    }

    function mountPublishedGrid() {
        mountGrid(propsDataPublishedGrid);
    }

    describe(" with empty page list", () => {
        beforeEach(async () => {
            axiosMock.onAny().reply(200, [], { total_matches: "0" });
@@ -135,11 +149,7 @@ describe("PgeList.vue", () => {
            jest.spyOn(PageList.methods, "decorateData").mockImplementation((page) => {
                page.shared = false;
            });
            wrapper = mount(PageList, {
                propsData: propsDataPersonalGrid,
                localVue,
                pinia: createTestingPinia(),
            });
            mountPersonalGrid();
            await flushPromises();
        });

@@ -202,11 +212,7 @@ describe("PgeList.vue", () => {
            jest.spyOn(PageList.methods, "decorateData").mockImplementation((page) => {
                page.shared = true;
            });
            wrapper = mount(PageList, {
                propsData: propsDataPersonalGrid,
                localVue,
                pinia: createTestingPinia(),
            });
            mountPersonalGrid();
            await flushPromises();
        });
        it("updates filter when published icon is clicked", async () => {
@@ -241,11 +247,7 @@ describe("PgeList.vue", () => {
            jest.spyOn(PageList.methods, "decorateData").mockImplementation((page) => {
                page.shared = false;
            });
            wrapper = mount(PageList, {
                propsData: propsDataPublishedGrid,
                localVue,
                pinia: createTestingPinia(),
            });
            mountPublishedGrid();
            await flushPromises();
        });

@@ -282,11 +284,7 @@ describe("PgeList.vue", () => {
            jest.spyOn(PageList.methods, "decorateData").mockImplementation((page) => {
                page.shared = false;
            });
            wrapper = mount(PageList, {
                propsData: propsDataPublishedGrid,
                localVue,
                pinia: createTestingPinia(),
            });
            mountPublishedGrid();
            await flushPromises();
        });

+9 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@
                <StatelessTags
                    :value="row.item.tags"
                    :index="row.index"
                    :disabled="published"
                    :disabled="published || !currentUserOwnsItem(row.item)"
                    @input="(tags) => onTags(tags, row.index)"
                    @tag-click="onTagClick" />
            </template>
@@ -80,6 +80,7 @@
<script>
import _l from "utils/localization";
import { getAppRoot } from "onload/loadConfig";
import { storeToRefs } from "pinia";
import { updateTags } from "./services";
import { pagesProvider } from "components/providers/PageProvider";
import StatelessTags from "components/TagsMultiselect/StatelessTags";
@@ -94,6 +95,8 @@ import { absPath } from "@/utils/redirect";
import { useRouter } from "vue-router/composables";
import { getGalaxyInstance } from "app";

import { useUserStore } from "@/stores/userStore";

import SharingIndicators from "components/Indices/SharingIndicators";

const helpHtml = `<div>
@@ -155,8 +158,10 @@ export default {
    },
    setup() {
        const router = useRouter();
        const { currentUser } = storeToRefs(useUserStore());
        return {
            router,
            currentUser,
        };
    },
    data() {
@@ -229,6 +234,9 @@ export default {
        shareLink: function (item) {
            this.router.push(`sharing?id=${item.id}`);
        },
        currentUserOwnsItem: function (item) {
            return item.username === this.currentUser.username;
        },
        decorateData(page) {
            const Galaxy = getGalaxyInstance();
            page.shared = page.username !== Galaxy.user.attributes.username;