UBERF-8425: Global accounts (#7573)

This commit is contained in:
Alexey Zinoviev
2025-02-04 10:31:03 +07:00
committed by GitHub
parent 83e5b16392
commit 2c64ceadb8
765 changed files with 19134 additions and 17955 deletions
@@ -15,12 +15,10 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte'
import { Label } from '@hcengineering/ui'
import { Account, TypedSpace, type Data, type Ref, getCurrentAccount, type Permission } from '@hcengineering/core'
import contact, { PersonAccount, type Employee } from '@hcengineering/contact'
import { TypedSpace, type Data, type Ref, type Permission } from '@hcengineering/core'
import { type Employee, type PermissionsStore, getCurrentEmployee } from '@hcengineering/contact'
import documents, { type ControlledDocument } from '@hcengineering/controlled-documents'
import { UserBoxItems } from '@hcengineering/contact-resources'
import { type PermissionsStore, permissionsStore } from '@hcengineering/view-resources'
import { createQuery } from '@hcengineering/presentation'
import { UserBoxItems, permissionsStore } from '@hcengineering/contact-resources'
export let controlledDoc: Data<ControlledDocument>
export let space: Ref<TypedSpace>
@@ -29,7 +27,7 @@
export let canChangeCoAuthors: boolean = true
const dispatch = createEventDispatcher()
const currentAccount = getCurrentAccount()
const currentEmployee = getCurrentEmployee()
$: reviewers = controlledDoc.reviewers
$: approvers = controlledDoc.approvers
@@ -37,76 +35,23 @@
$: permissionsSpace = space === documents.space.UnsortedTemplates ? documents.space.QualityDocuments : space
function getPermittedAccounts (
function getPermittedPersons (
permission: Ref<Permission>,
space: Ref<TypedSpace>,
permissionsStore: PermissionsStore
): Array<Ref<Account>> {
return Array.from(permissionsStore.ap[space]?.[permission] ?? [])
): Ref<Employee>[] {
return Array.from(permissionsStore.ap[space]?.[permission] ?? []) as Ref<Employee>[]
}
let permittedReviewers: Array<Ref<Employee>> = []
$: permittedReviewerAccounts = getPermittedAccounts(
documents.permission.ReviewDocument,
permissionsSpace,
$permissionsStore
)
const prQuery = createQuery()
$: if (permittedReviewerAccounts.length > 0) {
prQuery.query(
contact.class.PersonAccount,
{
_id: { $in: Array.from(permittedReviewerAccounts) as Array<Ref<PersonAccount>> }
},
(res) => {
permittedReviewers = res.map((pa) => pa.person) as Array<Ref<Employee>>
}
)
} else {
permittedReviewers = []
}
$: permittedReviewers = getPermittedPersons(documents.permission.ReviewDocument, permissionsSpace, $permissionsStore)
let permittedApprovers: Array<Ref<Employee>> = []
$: permittedApproverAccounts = getPermittedAccounts(
documents.permission.ApproveDocument,
permissionsSpace,
$permissionsStore
)
const paQuery = createQuery()
$: if (permittedApproverAccounts.length > 0) {
paQuery.query(
contact.class.PersonAccount,
{
_id: { $in: Array.from(permittedApproverAccounts) as Array<Ref<PersonAccount>> }
},
(res) => {
permittedApprovers = res.map((pa) => pa.person) as Array<Ref<Employee>>
}
)
} else {
permittedApprovers = []
}
$: permittedApprovers = getPermittedPersons(documents.permission.ApproveDocument, permissionsSpace, $permissionsStore)
let permittedCoAuthors: Array<Ref<Employee>> = []
$: permittedCoAuthorAccounts = getPermittedAccounts(
$: permittedCoAuthors = getPermittedPersons(
documents.permission.CoAuthorDocument,
permissionsSpace,
$permissionsStore
).filter((acc) => acc !== currentAccount._id)
const pcaQuery = createQuery()
$: if (permittedCoAuthorAccounts.length > 0) {
pcaQuery.query(
contact.class.PersonAccount,
{
_id: { $in: Array.from(permittedCoAuthorAccounts) as Array<Ref<PersonAccount>> }
},
(res) => {
permittedCoAuthors = res.map((pa) => pa.person) as Array<Ref<Employee>>
}
)
} else {
permittedCoAuthors = []
}
).filter((person) => person !== currentEmployee)
function handleUsersUpdated (type: 'reviewers' | 'approvers' | 'coAuthors', users: Ref<Employee>[]): void {
dispatch('update', { type, users })
@@ -15,8 +15,8 @@
<script lang="ts">
import documents, { Document } from '@hcengineering/controlled-documents'
import { Employee, PersonAccount } from '@hcengineering/contact'
import { EmployeeBox, EmployeePresenter, personAccountByIdStore } from '@hcengineering/contact-resources'
import { Employee } from '@hcengineering/contact'
import { EmployeeBox, EmployeePresenter, personRefByPersonIdStore } from '@hcengineering/contact-resources'
import core, { Ref, Space } from '@hcengineering/core'
import presentation, { createQuery, getClient } from '@hcengineering/presentation'
import { Button, Icon, Label } from '@hcengineering/ui'
@@ -60,9 +60,7 @@
$: isOwner = isDocOwner(object)
$: members = space?.members ?? []
$: employees = members
.map((m) => $personAccountByIdStore.get(m as Ref<PersonAccount>)?.person as Ref<Employee>)
.filter((p) => p !== undefined)
$: employees = members.map((m) => $personRefByPersonIdStore.get(m) as Ref<Employee>).filter((p) => p !== undefined)
$: docQuery = space?.private ?? false ? { active: true, _id: { $in: employees } } : { active: true }
</script>
@@ -28,7 +28,7 @@
import { type Doc, type Ref, type Space } from '@hcengineering/core'
import presentation, { getClient, SpaceSelector } from '@hcengineering/presentation'
import { Button, Label } from '@hcengineering/ui'
import { permissionsStore } from '@hcengineering/view-resources'
import { permissionsStore } from '@hcengineering/contact-resources'
import { createEventDispatcher } from 'svelte'
import documentsRes from '../../../plugin'
@@ -14,17 +14,15 @@
-->
<script lang="ts">
import documents, { Document } from '@hcengineering/controlled-documents'
import { Employee } from '@hcengineering/contact'
import { PersonPresenter } from '@hcengineering/contact-resources'
import { Employee, getCurrentEmployee } from '@hcengineering/contact'
import { PersonPresenter, checkMyPermission, permissionsStore } from '@hcengineering/contact-resources'
import { Ref } from '@hcengineering/core'
import { IntlString } from '@hcengineering/platform'
import { getClient } from '@hcengineering/presentation'
import { eventToHTMLElement, showPopup } from '@hcengineering/ui'
import { checkMyPermission, permissionsStore } from '@hcengineering/view-resources'
import document from '../../../plugin'
import ChangeOwnerPopup from '../popups/ChangeOwnerPopup.svelte'
import { getCurrentEmployee } from '../../../utils'
export let _id: Ref<Employee> | undefined
export let value: Employee | null | undefined
@@ -3,7 +3,7 @@
import documents, { DocumentRequest } from '@hcengineering/controlled-documents'
import chunter from '@hcengineering/chunter'
import { type Person } from '@hcengineering/contact'
import { PersonRefPresenter, personAccountByIdStore } from '@hcengineering/contact-resources'
import { PersonRefPresenter } from '@hcengineering/contact-resources'
import { Ref } from '@hcengineering/core'
import { getClient } from '@hcengineering/presentation'
import { Chevron, Label, tooltip } from '@hcengineering/ui'
@@ -44,7 +44,7 @@
return
}
approvals = await getApprovals(req, $personAccountByIdStore)
approvals = await getApprovals(req)
const rejectingComment = await client.findOne(chunter.class.ChatMessage, {
attachedTo: req?._id,
attachedToClass: req?._class
@@ -52,10 +52,7 @@
rejectingMessage = rejectingComment?.message
}
async function getApprovals (
req: DocumentRequest,
accountById: typeof $personAccountByIdStore
): Promise<PersonalApproval[]> {
async function getApprovals (req: DocumentRequest): Promise<PersonalApproval[]> {
const rejectedBy: PersonalApproval[] =
req.rejected !== undefined
? [
@@ -14,9 +14,9 @@
-->
<script lang="ts">
import { type Ref, SortingOrder, getCurrentAccount } from '@hcengineering/core'
import { type Ref, SortingOrder, notEmpty } from '@hcengineering/core'
import { createQuery } from '@hcengineering/presentation'
import { type PersonAccount } from '@hcengineering/contact'
import { getCurrentEmployee } from '@hcengineering/contact'
import documents, {
type ControlledDocument,
type DocumentMeta,
@@ -25,14 +25,13 @@
type ProjectMeta
} from '@hcengineering/controlled-documents'
import { compareDocs, notEmpty } from '../../../../utils'
import { compareDocs } from '../../../../utils'
import DocumentFlatTreeElement from './DocumentFlatTreeElement.svelte'
export let document: HierarchyDocument | undefined
export let project: Ref<Project>
const currentUser = getCurrentAccount() as PersonAccount
const currentPerson = currentUser.person
const currentPerson = getCurrentEmployee()
let meta: ProjectMeta | undefined
const projectMetaQuery = createQuery()