mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-18 14:08:21 +00:00
Some checks failed
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Vote Gate / Gate (push) Waiting to run
Codegraph E2E Votes / vote (shard 1/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 10/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 2/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 3/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 4/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 5/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 6/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 7/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 8/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 9/10) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/chat (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled
- GET /resolved resolves a group or user profile in the partition its document belongs to, as
writes judge it: for an admin without a tenant reading a tenant's profile, that tenant's
librechat.yaml and __base__. GET /catalog resolves such a scope there too, instead of
answering 404, and GET /effective finds a user by id the way profiles are addressed and
resolves them in their own tenant: their role, groups and documents there.
- findPartitionUser becomes findPrincipalUser, which also returns the user's tenant.
- Admin role operations address the role of the caller's tenant partition: the role lookup
(getPartitionRole), listing, creation's name check, the members a rename migrates or a deletion
reassigns, the members listed and counted, and the ACL entries (deletePrincipalAclEntries) and
grants a deletion removes. A member added or removed by id must be a user of that partition.
- getRoleByName, which every request's permission checks read, reads the role of the caller's
partition too: outside a tenant and under the system context the platform-level one, never an
older tenant role of the same name. updateRoleByName without an id and updateAccessPermissions
for a role read without its _id write that role, so the legacy permission route changes the
platform role. The grants route checks a role exists with getPartitionRole.
- runInPartition moves a read into another partition only from outside a tenant, and rejects
leaving an active one.
- deleteGrantsForPrincipal and findGrantsForPrincipal without a tenantId reach only
platform-level grants, as moveGrantsToPrincipal does.
- updateRoleByName takes { id } to change one role document; renames, their rollback,
description updates and updateAccessPermissions write the document they read.
- The exported keyed rename helpers (applyConfigChange rename, renameConfigEntryTombstones)
refuse a new name no keyed path can address, as the admin routes do.
48 lines
1.9 KiB
JavaScript
48 lines
1.9 KiB
JavaScript
const express = require('express');
|
|
const {
|
|
createAdminGrantsHandlers,
|
|
getCachedPrincipals,
|
|
isAuditFailClosed,
|
|
} = require('@librechat/api');
|
|
const { SystemCapabilities } = require('@librechat/data-schemas');
|
|
const { requireCapability } = require('~/server/middleware/roles/capabilities');
|
|
const configMiddleware = require('~/server/middleware/config/app');
|
|
const { requireJwtAuth } = require('~/server/middleware');
|
|
const db = require('~/models');
|
|
|
|
const router = express.Router();
|
|
|
|
const requireAdminAccess = requireCapability(SystemCapabilities.ACCESS_ADMIN);
|
|
|
|
const handlers = createAdminGrantsHandlers({
|
|
listGrants: db.listGrants,
|
|
countGrants: db.countGrants,
|
|
getCapabilitiesForPrincipal: db.getCapabilitiesForPrincipal,
|
|
getCapabilitiesForPrincipals: db.getCapabilitiesForPrincipals,
|
|
grantCapability: db.grantCapability,
|
|
revokeCapability: db.revokeCapability,
|
|
getUserPrincipals: db.getUserPrincipals,
|
|
hasCapabilityForPrincipals: db.hasCapabilityForPrincipals,
|
|
getHeldCapabilities: db.getHeldCapabilities,
|
|
getCachedPrincipals,
|
|
checkRoleExists: async (name) => (await db.getPartitionRole(name)) != null,
|
|
recordAuditEntry: db.recordAuditEntry,
|
|
auditFailClosed: isAuditFailClosed(),
|
|
lease: {
|
|
acquireResourceLock: db.acquireResourceLock,
|
|
renewResourceLock: db.renewResourceLock,
|
|
releaseResourceLock: db.releaseResourceLock,
|
|
},
|
|
});
|
|
|
|
router.use(requireJwtAuth, requireAdminAccess);
|
|
|
|
router.get('/', handlers.listGrants);
|
|
router.get('/effective', handlers.getEffectiveCapabilities);
|
|
router.get('/:principalType/:principalId', handlers.getPrincipalGrants);
|
|
/** Only the mutations read `permissions.lease*` from the loaded config. */
|
|
router.post('/', configMiddleware, handlers.assignGrant);
|
|
/** Callers should encodeURIComponent the capability for client compatibility (e.g. manage%3Aconfigs%3Aendpoints). */
|
|
router.delete('/:principalType/:principalId/:capability', configMiddleware, handlers.revokeGrant);
|
|
|
|
module.exports = router;
|