Files
huly-platform/plugins/setting-resources/src/hasRoleCapabilityAsync.ts
T
Artyom SavchenkoandGitHub 195d7dbff2 Reuse default invite settings in link generation (#10651)
* Reuse default invite settings in link generation

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Clean up

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Capability check

Signed-off-by: Artem Savchenko <armisav@gmail.com>

* Fix warning

Signed-off-by: Artem Savchenko <armisav@gmail.com>

---------

Signed-off-by: Artem Savchenko <armisav@gmail.com>
2026-03-19 14:35:06 +07:00

43 lines
2.0 KiB
TypeScript

//
// Copyright © 2026 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import type { InviteSettings, RoleCapabilityId, RoleCapabilitySettings } from '@hcengineering/setting'
import { getCurrentAccount } from '@hcengineering/core'
import { getClient } from '@hcengineering/presentation'
import setting, { RoleCapability } from '@hcengineering/setting'
import { hasRoleCapability } from './roleCapability'
import { resolveInviteSettings } from './inviteSettingsUtils'
/**
* Returns whether the current account has the given role capability.
* Fetches InviteSettings and RoleCapabilitySettings from the client.
* @public
*/
export async function hasRoleCapabilityAsync (capabilityId: RoleCapabilityId | string): Promise<boolean> {
const client = getClient()
const [inviteSettings, roleCapabilitySettings] = await Promise.all([
client.findAll(setting.class.InviteSettings, {}, { limit: 1 }),
client.findAll(setting.class.RoleCapabilitySettings, {}, { limit: 1 })
])
const firstInvite = inviteSettings[0] as InviteSettings | undefined
const firstRoleCap = roleCapabilitySettings[0] as RoleCapabilitySettings | undefined
const inviteLinkGeneratorRoles =
capabilityId === RoleCapability.GenerateInviteLink
? resolveInviteSettings(firstInvite).inviteLinkGeneratorRoles
: undefined
const roleByCapability = firstRoleCap?.roleByCapability
const account = getCurrentAccount()
return hasRoleCapability(account, capabilityId, roleByCapability, inviteLinkGeneratorRoles)
}