Skip to content

Commit

Permalink
Disable tag editing on non-owned Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Jan 22, 2024
1 parent ac6fe73 commit d1eaff9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
42 changes: 20 additions & 22 deletions client/src/components/Page/PageList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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" });
Expand Down Expand Up @@ -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();
});

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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();
});

Expand Down Expand Up @@ -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();
});

Expand Down
10 changes: 9 additions & 1 deletion client/src/components/Page/PageList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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";
Expand All @@ -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>
Expand Down Expand Up @@ -155,8 +158,10 @@ export default {
},
setup() {
const router = useRouter();
const { currentUser } = storeToRefs(useUserStore());
return {
router,
currentUser,
};
},
data() {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d1eaff9

Please sign in to comment.