-
Notifications
You must be signed in to change notification settings - Fork 27
Refactor getEntry endpoint #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e98d3e3
Refactor getEntry endpoint
stepanenkoxx 09cb85c
Fixes
stepanenkoxx 6e3f066
Fix naming
stepanenkoxx 6a61e6a
Merge branch 'main' into DLAPI-248-refactor-get-entry-endpoint
stepanenkoxx 5a571a1
Merge branch 'main' into DLAPI-248-refactor-get-entry-endpoint
stepanenkoxx 9c68e95
Up gateway version
stepanenkoxx f58bed8
Add DLS.checkpermission timeout
stepanenkoxx dea1eb0
Add test routes
stepanenkoxx ac582a5
Fix log
stepanenkoxx fe8506b
Fix types
stepanenkoxx ef85bbf
Fix
stepanenkoxx 0a688c1
Review fixes
stepanenkoxx 47bb7a0
Merge branch 'main' into DLAPI-248-refactor-get-entry-endpoint
stepanenkoxx 3987903
Disable manualDecodeId
stepanenkoxx 4cc5251
Fix tenant check
stepanenkoxx 083b205
Merge branch 'main' into DLAPI-248-refactor-get-entry-endpoint
stepanenkoxx 3f117fe
Review fixes
stepanenkoxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import {Request, Response} from '@gravity-ui/expresskit'; | ||
|
|
||
| import {ApiTag} from '../../../components/api-docs'; | ||
| import {makeReqParser, z, zc} from '../../../components/zod'; | ||
| import {CONTENT_TYPE_JSON} from '../../../const'; | ||
| import {getEntryV2} from '../../../services/new/entry'; | ||
|
|
||
| import {getEntryResult} from './response-model'; | ||
|
|
||
| const requestSchema = { | ||
| params: z.object({ | ||
| entryId: zc.encodedId(), | ||
| }), | ||
| query: z.object({ | ||
| branch: z.enum(['saved', 'published']).optional(), | ||
| revId: zc.encodedId().optional(), | ||
| includePermissionsInfo: zc.stringBoolean().optional(), | ||
| includeLinks: zc.stringBoolean().optional(), | ||
| includeServicePlan: zc.stringBoolean().optional(), | ||
| includeTenantFeatures: zc.stringBoolean().optional(), | ||
| includeFavorite: zc.stringBoolean().optional(), | ||
| }), | ||
| }; | ||
|
|
||
| const parseReq = makeReqParser(requestSchema); | ||
|
|
||
| export const getEntryController = async (req: Request, res: Response) => { | ||
| const {query, params} = await parseReq(req); | ||
|
|
||
| const result = await getEntryV2( | ||
| {ctx: req.ctx}, | ||
| { | ||
| entryId: params.entryId, | ||
| branch: query.branch, | ||
| revId: query.revId, | ||
| includePermissionsInfo: query.includePermissionsInfo, | ||
| includeLinks: query.includeLinks, | ||
| includeServicePlan: query.includeServicePlan, | ||
| includeTenantFeatures: query.includeTenantFeatures, | ||
| includeFavorite: query.includeFavorite, | ||
| }, | ||
| ); | ||
|
|
||
| res.status(200).send(getEntryResult.format(req.ctx, result)); | ||
| }; | ||
|
|
||
| getEntryController.api = { | ||
| summary: 'Get entry', | ||
| tags: [ApiTag.Entries], | ||
| request: { | ||
| params: requestSchema.params, | ||
| query: requestSchema.query, | ||
| }, | ||
| responses: { | ||
| 200: { | ||
| description: getEntryResult.schema.description ?? '', | ||
| content: { | ||
| [CONTENT_TYPE_JSON]: { | ||
| schema: getEntryResult.schema, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| getEntryController.manualDecodeId = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import {AppContext} from '@gravity-ui/nodekit'; | ||
|
|
||
| import {z} from '../../../components/zod'; | ||
| import {EntryScope} from '../../../db/models/new/entry/types'; | ||
| import {GetEntryV2Result} from '../../../services/new/entry'; | ||
| import Utils from '../../../utils'; | ||
|
|
||
| const schema = z | ||
| .object({ | ||
| entryId: z.string(), | ||
| scope: z.nativeEnum(EntryScope), | ||
| type: z.string(), | ||
| key: z.string().nullable(), | ||
| unversionedData: z.record(z.string(), z.unknown()).optional(), | ||
| createdBy: z.string(), | ||
| createdAt: z.string(), | ||
| updatedBy: z.string(), | ||
| updatedAt: z.string(), | ||
| savedId: z.string().nullable(), | ||
| publishedId: z.string().nullable(), | ||
| revId: z.string(), | ||
| tenantId: z.string().nullable(), | ||
| data: z.record(z.string(), z.unknown()).nullable(), | ||
| meta: z.record(z.string(), z.unknown()).nullable(), | ||
| hidden: z.boolean(), | ||
| public: z.boolean(), | ||
| workbookId: z.string().nullable(), | ||
| links: z.record(z.string(), z.unknown()).optional().nullable(), | ||
| isFavorite: z.boolean().optional(), | ||
| permissions: z | ||
| .object({ | ||
| execute: z.boolean().optional(), | ||
| read: z.boolean().optional(), | ||
| edit: z.boolean().optional(), | ||
| admin: z.boolean().optional(), | ||
| }) | ||
| .optional(), | ||
| servicePlan: z.string().optional(), | ||
| tenantFeatures: z.record(z.string(), z.unknown()).optional(), | ||
| }) | ||
| .describe('Get entry result'); | ||
|
|
||
| const format = ( | ||
| ctx: AppContext, | ||
| { | ||
| entry, | ||
| revision, | ||
| includePermissionsInfo, | ||
| permissions, | ||
| includeLinks, | ||
| includeServicePlan, | ||
| servicePlan, | ||
| includeTenantFeatures, | ||
| tenantFeatures, | ||
| includeFavorite, | ||
| }: GetEntryV2Result, | ||
| ): z.infer<typeof schema> => { | ||
| const {privatePermissions, onlyPublic} = ctx.get('info'); | ||
|
|
||
| let isHiddenUnversionedData = false; | ||
| if (!privatePermissions.ownedScopes.includes(entry.scope)) { | ||
| isHiddenUnversionedData = true; | ||
| } | ||
|
|
||
| let isFavorite: boolean | undefined; | ||
|
|
||
| if (includeFavorite && !onlyPublic) { | ||
| isFavorite = Boolean(entry.favorite); | ||
| } | ||
|
|
||
| const registry = ctx.get('registry'); | ||
| const {getEntryAddFormattedFieldsHook} = registry.common.functions.get(); | ||
| const additionalFields = getEntryAddFormattedFieldsHook({ctx}); | ||
|
|
||
| return { | ||
| entryId: Utils.encodeId(entry.entryId), | ||
| scope: entry.scope, | ||
| type: entry.type, | ||
| key: entry.displayKey, | ||
| unversionedData: isHiddenUnversionedData ? undefined : entry.unversionedData, | ||
| createdBy: entry.createdBy, | ||
| createdAt: entry.createdAt, | ||
| updatedBy: revision.updatedBy, | ||
| updatedAt: revision.updatedAt, | ||
| savedId: entry.savedId ? Utils.encodeId(entry.savedId) : null, | ||
| publishedId: entry.publishedId ? Utils.encodeId(entry.publishedId) : null, | ||
| revId: Utils.encodeId(revision.revId), | ||
| tenantId: entry.tenantId, | ||
| data: revision.data, | ||
| meta: revision.meta, | ||
| hidden: entry.hidden, | ||
| public: entry.public, | ||
| workbookId: entry.workbookId ? Utils.encodeId(entry.workbookId) : null, | ||
| links: includeLinks ? revision.links : undefined, | ||
| isFavorite, | ||
| permissions: includePermissionsInfo ? permissions : undefined, | ||
| servicePlan: includeServicePlan ? servicePlan : undefined, | ||
| tenantFeatures: includeTenantFeatures ? tenantFeatures : undefined, | ||
| ...additionalFields, | ||
| }; | ||
| }; | ||
|
|
||
| export const getEntryResult = { | ||
| schema, | ||
| format, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,12 @@ | ||
| import type {AppContext} from '@gravity-ui/nodekit'; | ||
|
|
||
| import type {GetEntryResult} from '../../../../services/new/entry/get-entry'; | ||
|
|
||
| export type IsNeedBypassEntryByKey = (ctx: AppContext, key?: string) => boolean; | ||
|
|
||
| export type GetEntryBeforeDbRequestHook = (args: { | ||
| ctx: AppContext; | ||
| entryId: string; | ||
| }) => Promise<void>; | ||
|
|
||
| export type GetEntryAddFormattedFieldsHook = (args: { | ||
| ctx: AppContext; | ||
| result: GetEntryResult; | ||
| }) => Promise<Record<string, unknown>>; | ||
| export type GetEntryAddFormattedFieldsHook = (args: {ctx: AppContext}) => Record<string, unknown>; | ||
|
|
||
| export type GetEntryResolveUserLogin = (args: {ctx: AppContext}) => Promise<string | undefined>; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Operationis used for existing entity, can we useActionorRequesthere?