mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-10 11:47:42 +02:00
EQMS-1650: External approvers (#9987)
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
@@ -67,6 +67,7 @@
|
||||
snapshots: 0,
|
||||
reviewers: [],
|
||||
approvers: [],
|
||||
externalApprovers: [],
|
||||
coAuthors: [],
|
||||
changeControl: '' as Ref<ChangeControl>,
|
||||
content: null
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { Mixin, DocumentQuery, Ref } from '@hcengineering/core'
|
||||
import { DocumentSpace, type DocumentTemplate } from '@hcengineering/controlled-documents'
|
||||
import { ActionContext, createQuery } from '@hcengineering/presentation'
|
||||
import { type DocumentTemplate } from '@hcengineering/controlled-documents'
|
||||
import { ActionContext } from '@hcengineering/presentation'
|
||||
import { Button, IconAdd, Loading, showPopup } from '@hcengineering/ui'
|
||||
import view, { ViewOptions, Viewlet, ViewletPreference } from '@hcengineering/view'
|
||||
import { TableBrowser, ViewletPanelHeader } from '@hcengineering/view-resources'
|
||||
@@ -34,22 +34,7 @@
|
||||
let loading = true
|
||||
const _class: Ref<Mixin<DocumentTemplate>> = documents.mixin.DocumentTemplate
|
||||
|
||||
let spaces: Ref<DocumentSpace>[] = []
|
||||
const spacesQuery = createQuery()
|
||||
$: spacesQuery.query(
|
||||
documents.class.DocumentSpace,
|
||||
{},
|
||||
(res) => {
|
||||
spaces = res.map((s) => s._id)
|
||||
},
|
||||
{
|
||||
projection: {
|
||||
_id: 1
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
$: srcQuery = { ...query, space: { $in: spaces } }
|
||||
$: srcQuery = { ...query }
|
||||
$: canAddTemplate = checkMyPermission(
|
||||
documents.permission.CreateDocument,
|
||||
documents.space.QualityDocuments,
|
||||
|
||||
@@ -17,11 +17,10 @@
|
||||
import { Class, DocumentQuery, Ref, Space } from '@hcengineering/core'
|
||||
import type { IntlString, Asset } from '@hcengineering/platform'
|
||||
import { IModeSelector, resolvedLocationStore } from '@hcengineering/ui'
|
||||
import documents, { type Document, type DocumentSpace, DocumentState } from '@hcengineering/controlled-documents'
|
||||
import { type Document, DocumentState } from '@hcengineering/controlled-documents'
|
||||
|
||||
import Documents from './Documents.svelte'
|
||||
import document from '../plugin'
|
||||
import { createQuery } from '@hcengineering/presentation'
|
||||
|
||||
export let _class: Ref<Class<Document>> = document.class.Document
|
||||
export let query: DocumentQuery<Document> = {}
|
||||
@@ -36,29 +35,13 @@
|
||||
let mode: string | undefined = undefined
|
||||
let modeSelectorProps: IModeSelector | undefined = undefined
|
||||
|
||||
let spaces: Ref<DocumentSpace>[] = []
|
||||
const spacesQuery = createQuery()
|
||||
|
||||
$: spacesQuery.query(
|
||||
documents.class.DocumentSpace,
|
||||
{},
|
||||
(res) => {
|
||||
spaces = res.map((s) => s._id)
|
||||
},
|
||||
{
|
||||
projection: {
|
||||
_id: 1
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// NOTE: we have to use "{ type: { $in:" queries below. Otherwise, it breaks when combined
|
||||
// with custom Filters added by State.
|
||||
$: inProgress = { state: { $in: [DocumentState.Draft] }, space: { $in: spaces } }
|
||||
$: effective = { state: { $in: [DocumentState.Effective] }, space: { $in: spaces } }
|
||||
$: archived = { state: { $in: [DocumentState.Archived, DocumentState.Deleted] }, space: { $in: spaces } }
|
||||
$: obsolete = { state: { $in: [DocumentState.Obsolete] }, space: { $in: spaces } }
|
||||
$: all = { space: { $in: spaces } }
|
||||
$: inProgress = { state: { $in: [DocumentState.Draft] } }
|
||||
$: effective = { state: { $in: [DocumentState.Effective] } }
|
||||
$: archived = { state: { $in: [DocumentState.Archived, DocumentState.Deleted] } }
|
||||
$: obsolete = { state: { $in: [DocumentState.Obsolete] } }
|
||||
$: all = {}
|
||||
|
||||
$: queries = { inProgress, effective, archived, obsolete, all }
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
ControlledDocumentState,
|
||||
DocumentRequest
|
||||
} from '@hcengineering/controlled-documents'
|
||||
import { Class, Ref } from '@hcengineering/core'
|
||||
import { Class, Ref, TxOperations } from '@hcengineering/core'
|
||||
import { getClient } from '@hcengineering/presentation'
|
||||
import { RequestStatus } from '@hcengineering/request'
|
||||
import { Label, ModernDialog, showPopup } from '@hcengineering/ui'
|
||||
@@ -21,6 +21,14 @@
|
||||
import { sendApprovalRequest, sendReviewRequest } from '../utils'
|
||||
import SignatureDialog from './SignatureDialog.svelte'
|
||||
|
||||
type SendRequestFunc = (
|
||||
client: TxOperations,
|
||||
controlledDoc: ControlledDocument,
|
||||
users: Array<Ref<Employee>>,
|
||||
externalUsers: Array<Ref<Employee>>,
|
||||
oldExternalUsers: Array<Ref<Employee>>
|
||||
) => Promise<void>
|
||||
|
||||
export let controlledDoc: ControlledDocument
|
||||
export let requestClass: Ref<Class<DocumentRequest>>
|
||||
export let readonly: boolean = false
|
||||
@@ -34,7 +42,7 @@
|
||||
|
||||
const docField: keyof ControlledDocument = isReviewRequest ? 'reviewers' : 'approvers'
|
||||
const label = isReviewRequest ? documentsRes.string.SelectReviewers : documentsRes.string.SelectApprovers
|
||||
const sendRequestFunc = isReviewRequest ? sendReviewRequest : sendApprovalRequest
|
||||
const sendRequestFunc: SendRequestFunc = isReviewRequest ? sendReviewRequest : sendApprovalRequest
|
||||
const permissionId = isReviewRequest ? documents.permission.ReviewDocument : documents.permission.ApproveDocument
|
||||
$: permissionsSpace =
|
||||
controlledDoc.space === documents.space.UnsortedTemplates ? documents.space.QualityDocuments : controlledDoc.space
|
||||
@@ -54,12 +62,14 @@
|
||||
})
|
||||
|
||||
let users: Ref<Employee>[] = controlledDoc[docField] ?? []
|
||||
let externalUsers: Ref<Employee>[] = isReviewRequest ? [] : controlledDoc.externalApprovers ?? []
|
||||
const existingExternalUsers = externalUsers
|
||||
|
||||
async function submit (): Promise<void> {
|
||||
const complete = async (): Promise<void> => {
|
||||
loading = true
|
||||
|
||||
await sendRequestFunc?.(client, controlledDoc, users)
|
||||
await sendRequestFunc?.(client, controlledDoc, users, isReviewRequest ? [] : externalUsers, existingExternalUsers)
|
||||
|
||||
loading = false
|
||||
|
||||
@@ -86,11 +96,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: canSubmit = docRequest === undefined && users.length > 0
|
||||
$: canSubmit = docRequest === undefined && (users.length > 0 || externalUsers.length > 0)
|
||||
</script>
|
||||
|
||||
<ModernDialog {loading} {label} {canSubmit} on:submit={submit} on:close>
|
||||
<div class="flex-col pt-2">
|
||||
<div class="flex-col pt-2 flex-gap-4">
|
||||
<div class="flex">
|
||||
<div class="flex labelContainer">
|
||||
<div class="label mr-1">
|
||||
@@ -113,6 +123,31 @@
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{#if !isReviewRequest}
|
||||
<div class="flex">
|
||||
<div class="flex labelContainer">
|
||||
<div class="label mr-1">
|
||||
<Label label={documentsRes.string.ExternalApprovers} />
|
||||
</div>
|
||||
{externalUsers?.length}
|
||||
</div>
|
||||
<div class="flex-col">
|
||||
<UserBoxItems
|
||||
items={externalUsers}
|
||||
label={documentsRes.string.ExternalApprovers}
|
||||
readonly={controlledDoc.controlledState === ControlledDocumentState.InReview ||
|
||||
controlledDoc.controlledState === ControlledDocumentState.InApproval ||
|
||||
readonly}
|
||||
docQuery={{
|
||||
active: true,
|
||||
role: 'GUEST',
|
||||
_id: { $nin: permittedEmployees }
|
||||
}}
|
||||
on:update={({ detail }) => (externalUsers = detail)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</ModernDialog>
|
||||
|
||||
|
||||
+10
@@ -53,6 +53,7 @@
|
||||
currentStepUpdated
|
||||
} from '../../stores/wizards/create-document'
|
||||
import FailedToCreateDocument from '../FailedToCreateDocument.svelte'
|
||||
import { updateExternalApproversAccess } from '../../utils'
|
||||
|
||||
export let _class: Ref<Class<ControlledDocument>> = documents.class.ControlledDocument
|
||||
|
||||
@@ -119,6 +120,7 @@
|
||||
requests: 0,
|
||||
reviewers: [],
|
||||
approvers: [],
|
||||
externalApprovers: [],
|
||||
coAuthors: [],
|
||||
plannedEffectiveDate: 0,
|
||||
reviewInterval: DEFAULT_PERIODIC_REVIEW_INTERVAL
|
||||
@@ -176,6 +178,14 @@
|
||||
|
||||
await createChangeControl(client, ccRecordId, ccRecord, _space)
|
||||
|
||||
if (docObject.externalApprovers.length > 0) {
|
||||
const controlledDoc = await client.findOne(documents.class.ControlledDocument, { _id: newDocId })
|
||||
|
||||
if (controlledDoc !== undefined) {
|
||||
await updateExternalApproversAccess(client, controlledDoc, docObject.externalApprovers, [])
|
||||
}
|
||||
}
|
||||
|
||||
const loc = getProjectDocumentLink(newDocId, $locationStep.project)
|
||||
navigate(loc)
|
||||
|
||||
|
||||
+10
@@ -52,6 +52,7 @@
|
||||
wizardClosed
|
||||
} from '../../stores/wizards/create-document'
|
||||
import FailedToCreateDocument from '../FailedToCreateDocument.svelte'
|
||||
import { updateExternalApproversAccess } from '../../utils'
|
||||
|
||||
export let _class: Ref<Class<ControlledDocument>> = documents.class.ControlledDocument
|
||||
export let _templateMixin: Ref<Mixin<DocumentTemplate>> = documents.mixin.DocumentTemplate
|
||||
@@ -114,6 +115,7 @@
|
||||
requests: 0,
|
||||
reviewers: [],
|
||||
approvers: [],
|
||||
externalApprovers: [],
|
||||
coAuthors: [],
|
||||
plannedEffectiveDate: 0,
|
||||
reviewInterval: DEFAULT_PERIODIC_REVIEW_INTERVAL
|
||||
@@ -178,6 +180,14 @@
|
||||
|
||||
await createChangeControl(client, ccRecordId, ccRecord, space)
|
||||
|
||||
if (docObject.externalApprovers.length > 0) {
|
||||
const controlledDoc = await client.findOne(documents.class.ControlledDocument, { _id: newDocId })
|
||||
|
||||
if (controlledDoc !== undefined) {
|
||||
await updateExternalApproversAccess(client, controlledDoc, docObject.externalApprovers, [])
|
||||
}
|
||||
}
|
||||
|
||||
const loc = getProjectDocumentLink(newDocId, $locationStep.project)
|
||||
navigate(loc)
|
||||
|
||||
|
||||
+11
-2
@@ -26,7 +26,7 @@
|
||||
async function handleUpdate ({
|
||||
detail
|
||||
}: {
|
||||
detail: { type: 'reviewers' | 'approvers', users: Ref<Employee>[] }
|
||||
detail: { type: 'reviewers' | 'approvers' | 'coAuthors' | 'externalApprovers', users: Ref<Employee>[] }
|
||||
}): Promise<void> {
|
||||
if (docObject === undefined) {
|
||||
return
|
||||
@@ -40,11 +40,20 @@
|
||||
$: reviewers = docObject?.reviewers ?? []
|
||||
$: approvers = docObject?.approvers ?? []
|
||||
$: coAuthors = docObject?.coAuthors ?? []
|
||||
$: externalApprovers = docObject?.externalApprovers ?? []
|
||||
</script>
|
||||
|
||||
{#if docObject !== undefined}
|
||||
<div class="root">
|
||||
<DocTeam controlledDoc={docObject} {space} on:update={handleUpdate} {approvers} {reviewers} {coAuthors} />
|
||||
<DocTeam
|
||||
controlledDoc={docObject}
|
||||
{space}
|
||||
on:update={handleUpdate}
|
||||
{approvers}
|
||||
{reviewers}
|
||||
{coAuthors}
|
||||
{externalApprovers}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
export let canChangeCoAuthors: boolean = true
|
||||
export let reviewers: Ref<Employee>[] = controlledDoc?.reviewers ?? []
|
||||
export let approvers: Ref<Employee>[] = controlledDoc?.approvers ?? []
|
||||
export let externalApprovers: Ref<Employee>[] = controlledDoc?.externalApprovers ?? []
|
||||
export let coAuthors: Ref<Employee>[] = controlledDoc?.coAuthors ?? []
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
@@ -52,7 +53,10 @@
|
||||
$permissionsStore
|
||||
).filter((person) => person !== currentEmployee) as Ref<Employee>[]
|
||||
|
||||
function handleUsersUpdated (type: 'reviewers' | 'approvers' | 'coAuthors', users: Ref<Employee>[]): void {
|
||||
function handleUsersUpdated (
|
||||
type: 'reviewers' | 'approvers' | 'coAuthors' | 'externalApprovers',
|
||||
users: Ref<Employee>[]
|
||||
): void {
|
||||
dispatch('update', { type, users })
|
||||
}
|
||||
</script>
|
||||
@@ -120,6 +124,28 @@
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div class="mt-6 mb-6 divider" />
|
||||
<div class="flex labelContainer">
|
||||
<div class="label mr-1">
|
||||
<Label label={documents.string.ExternalApprovers} />
|
||||
</div>
|
||||
{externalApprovers?.length}
|
||||
</div>
|
||||
<div class="flex-col mt-4">
|
||||
<UserBoxItems
|
||||
items={externalApprovers}
|
||||
docQuery={{
|
||||
active: true,
|
||||
role: 'GUEST',
|
||||
_id: { $nin: permittedApprovers }
|
||||
}}
|
||||
label={documents.string.ExternalApprovers}
|
||||
readonly={!canChangeApprovers}
|
||||
on:update={({ detail }) => {
|
||||
handleUsersUpdated('externalApprovers', detail)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
|
||||
@@ -13,19 +13,20 @@
|
||||
// limitations under the License.
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { Employee, Person } from '@hcengineering/contact'
|
||||
import {
|
||||
import contact, { Employee, Person } from '@hcengineering/contact'
|
||||
import documents, {
|
||||
ControlledDocument,
|
||||
ControlledDocumentState,
|
||||
DocumentApprovalRequest,
|
||||
DocumentReviewRequest,
|
||||
DocumentState
|
||||
} from '@hcengineering/controlled-documents'
|
||||
import { DocumentUpdate, Ref } from '@hcengineering/core'
|
||||
import core, { AccountUuid, DocumentUpdate, notEmpty, PersonUuid, Ref } from '@hcengineering/core'
|
||||
import { getClient } from '@hcengineering/presentation'
|
||||
import { Scroller } from '@hcengineering/ui'
|
||||
|
||||
import DocTeam from './DocTeam.svelte'
|
||||
import { updateExternalApproversAccess } from '../../utils'
|
||||
|
||||
export let controlledDoc: ControlledDocument
|
||||
export let editable: boolean = true
|
||||
@@ -46,7 +47,8 @@
|
||||
$: canChangeApprovers = isEditableDraft && (inCleanState || inApproval || inReview || isReviewed)
|
||||
|
||||
$: reviewers = (reviewRequest?.requested as Ref<Employee>[]) ?? controlledDoc.reviewers
|
||||
$: approvers = (approvalRequest?.requested as Ref<Employee>[]) ?? controlledDoc.approvers
|
||||
$: approvers = controlledDoc.approvers
|
||||
$: externalApprovers = controlledDoc.externalApprovers
|
||||
$: coAuthors = controlledDoc.coAuthors
|
||||
|
||||
const client = getClient()
|
||||
@@ -54,13 +56,22 @@
|
||||
async function handleUpdate ({
|
||||
detail
|
||||
}: {
|
||||
detail: { type: 'reviewers' | 'approvers', users: Ref<Person>[] }
|
||||
detail: { type: 'reviewers' | 'approvers' | 'externalApprovers', users: Ref<Person>[] }
|
||||
}): Promise<void> {
|
||||
const { type, users } = detail
|
||||
|
||||
const request = detail.type === 'reviewers' ? reviewRequest : approvalRequest
|
||||
let requestUsers: Ref<Person>[] = []
|
||||
|
||||
const ops = client.apply()
|
||||
if (type === 'reviewers') {
|
||||
requestUsers = users
|
||||
} else if (type === 'externalApprovers') {
|
||||
requestUsers = [...controlledDoc.approvers, ...users]
|
||||
} else if (type === 'approvers') {
|
||||
requestUsers = [...users, ...controlledDoc.externalApprovers]
|
||||
}
|
||||
|
||||
const ops = client.apply(controlledDoc._id)
|
||||
|
||||
if (request?._id !== undefined) {
|
||||
const requested = request.requested?.slice() ?? []
|
||||
@@ -69,7 +80,7 @@
|
||||
const addedPersons = new Set<Ref<Person>>()
|
||||
const removedPersons = new Set<Ref<Person>>(requested)
|
||||
|
||||
for (const u of users) {
|
||||
for (const u of requestUsers) {
|
||||
if (requestedSet.has(u)) {
|
||||
removedPersons.delete(u)
|
||||
} else {
|
||||
@@ -87,7 +98,7 @@
|
||||
approvedDates.splice(idx, 1)
|
||||
}
|
||||
|
||||
const requiredApprovesCount = users.length
|
||||
const requiredApprovesCount = requestUsers.length
|
||||
const requestedQuery: DocumentUpdate<DocumentReviewRequest | DocumentApprovalRequest> = {}
|
||||
|
||||
if (addedPersons.size > 0) {
|
||||
@@ -107,8 +118,8 @@
|
||||
})
|
||||
}
|
||||
|
||||
const added = new Set()
|
||||
const removed = new Set()
|
||||
const added = new Set<Ref<Person>>()
|
||||
const removed = new Set<Ref<Person>>()
|
||||
|
||||
for (const user of users) {
|
||||
if (!controlledDoc[type].includes(user as Ref<Employee>)) {
|
||||
@@ -133,6 +144,11 @@
|
||||
if (Object.keys(updateQuery).length > 0) {
|
||||
await ops.update(controlledDoc, updateQuery)
|
||||
}
|
||||
|
||||
if (type === 'externalApprovers') {
|
||||
await updateExternalApproversAccess(client, controlledDoc, Array.from(added), Array.from(removed))
|
||||
}
|
||||
|
||||
await ops.commit()
|
||||
}
|
||||
</script>
|
||||
@@ -148,6 +164,7 @@
|
||||
{canChangeApprovers}
|
||||
{reviewers}
|
||||
{approvers}
|
||||
{externalApprovers}
|
||||
{coAuthors}
|
||||
on:update={handleUpdate}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user