Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
front(component): add type guard for update tag in post
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo Magtoto committed Nov 23, 2022
1 parent af2df9f commit db75b27
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions components/post/multiviewer/viewer/update_post_form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<ReceivedSuccessMessages
v-if="successMessages.length"
:received-success-messages="successMessages"/>

<DraftForm
:id="postID"
v-model="content"
Expand All @@ -21,6 +20,7 @@
:options="roleNames"/>
</div>
<SearchableChip
v-if="mayUpdateTag"
v-model:model-value="tags"
header="Optional tags"
:maximum-tags="MAX_TAGS"
Expand Down Expand Up @@ -127,8 +127,9 @@
</style>

<script setup lang="ts">
import { computed, ref, watch } from "vue"
import { computed, ref, watch, inject } from "vue"
import type { PageContext } from "$/types/renderer"
import type { OptionInfo } from "$@/types/component"
import type { DeserializedTagResource } from "$/types/documents/tag"
import type { DeserializedRoleResource } from "$/types/documents/role"
Expand All @@ -148,6 +149,8 @@ import specializePath from "$/helpers/specialize_path"
import PostAttachmentFetcher from "$@/fetchers/post_attachment"
import fillSuccessMessages from "$@/helpers/fill_success_messages"
import extractAllErrorDetails from "$@/helpers/extract_all_error_details"
import { UPDATE } from "$/permissions/tag_combinations"
import { post as permissionGroup } from "$/permissions/permission_list"
import Overlay from "@/helpers/overlay.vue"
import DraftForm from "@/post/draft_form.vue"
Expand All @@ -159,6 +162,10 @@ import ReceivedSuccessMessages from "@/helpers/message_handlers/received_success
const userFetcher = new UserFetcher()
const pageContext = inject("pageContext") as PageContext<"deserialized">
const { pageProps } = pageContext
const { userProfile } = pageProps
type AssociatedPostResource = "poster"|"posterRole"|"department"|"postAttachments"|"tags"
const props = defineProps<{
isShown: boolean,
Expand Down Expand Up @@ -352,6 +359,13 @@ function updateTags() {
hasUpdatedTags.value = true
}
const mayUpdateTag = computed<boolean>(() => {
const canCreate = permissionGroup.hasOneRoleAllowed(userProfile.data.roles.data, [
UPDATE
])
return canCreate
})
watch(isShown, newValue => {
if (newValue && !hasLoadedCompletePosterInfo.value) {
userFetcher.read(props.modelValue.poster.data.id).then(({ body }) => {
Expand Down

0 comments on commit db75b27

Please sign in to comment.