mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-08 17:18:48 +00:00
fix: use readonly connections for guests (#8221)
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / uitest-workspaces (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / uitest-workspaces (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
parent
88357fe68a
commit
31bf564ffc
@ -19,7 +19,7 @@ import { decodeToken } from '@hcengineering/server-token'
|
||||
import { Extension, onAuthenticatePayload } from '@hocuspocus/server'
|
||||
|
||||
import { Context, buildContext } from '../context'
|
||||
import { getWorkspaceIds } from '../utils'
|
||||
import { getWorkspaceIds, isGuest } from '../utils'
|
||||
|
||||
export interface AuthenticationConfiguration {
|
||||
ctx: MeasureContext
|
||||
@ -38,8 +38,13 @@ export class AuthenticationExtension implements Extension {
|
||||
|
||||
return await ctx.with('authenticate', { workspaceId }, async () => {
|
||||
const token = decodeToken(data.token)
|
||||
const readonly = isGuest(token)
|
||||
|
||||
ctx.info('authenticate', { workspaceId, mode: token.extra?.mode ?? '' })
|
||||
ctx.info('authenticate', { workspaceId, mode: token.extra?.mode ?? '', readonly })
|
||||
|
||||
if (readonly) {
|
||||
data.connection.readOnly = true
|
||||
}
|
||||
|
||||
// verify workspace can be accessed with the token
|
||||
const ids = await getWorkspaceIds(data.token)
|
||||
|
@ -12,11 +12,17 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
import { type WorkspaceIds } from '@hcengineering/core'
|
||||
import { GUEST_ACCOUNT } from '@hcengineering/account'
|
||||
import { getClient as getAccountClient } from '@hcengineering/account-client'
|
||||
import { type WorkspaceIds } from '@hcengineering/core'
|
||||
import { type Token } from '@hcengineering/server-token'
|
||||
|
||||
import config from './config'
|
||||
|
||||
export function isGuest (token: Token): boolean {
|
||||
return token.account === GUEST_ACCOUNT && token.extra?.guest === 'true'
|
||||
}
|
||||
|
||||
// TODO: consider storing this in a cache for some short period of time
|
||||
export async function getWorkspaceIds (token: string): Promise<WorkspaceIds> {
|
||||
const workspaceInfo = await getAccountClient(config.AccountsUrl, token).getWorkspaceInfo()
|
||||
|
Loading…
Reference in New Issue
Block a user