Skip to content

Commit

Permalink
Сleanup UseLimitedView feature flag (#234)
Browse files Browse the repository at this point in the history
* cleanup UseLimitedView feature flag
  • Loading branch information
sjorobekov authored Jan 17, 2025
1 parent f35a595 commit e92c4ab
Show file tree
Hide file tree
Showing 19 changed files with 15 additions and 67 deletions.
1 change: 0 additions & 1 deletion src/components/features/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export enum Feature {
CollectionsEnabled = 'CollectionsEnabled',
ColorPalettesEnabled = 'ColorPalettesEnabled',
UseIpV6 = 'UseIpV6',
UseLimitedView = 'UseLimitedView',
WorkbookIsolationEnabled = 'WorkbookIsolationEnabled',
}

Expand Down
1 change: 0 additions & 1 deletion src/configs/opensource/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const features: FeaturesConfig = {
[Feature.CollectionsEnabled]: true,
[Feature.ColorPalettesEnabled]: true,
[Feature.UseIpV6]: false,
[Feature.UseLimitedView]: true,
[Feature.WorkbookIsolationEnabled]: true,
};

Expand Down
5 changes: 1 addition & 4 deletions src/db/models/lock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {DBError, transaction} from 'objection';
import PG_ERRORS from 'pg-error-constants';

import {Model} from '../..';
import {Feature, isEnabledFeature} from '../../../components/features';
import {CURRENT_TIMESTAMP} from '../../../const';
import US_ERRORS from '../../../const/us-error-constants';
import {WorkbookPermission} from '../../../entities/workbook';
Expand Down Expand Up @@ -444,9 +443,7 @@ class Lock extends Model {
if (permission === 'edit') {
workbookPermission = WorkbookPermission.Update;
} else {
workbookPermission = isEnabledFeature(ctx, Feature.UseLimitedView)
? WorkbookPermission.LimitedView
: WorkbookPermission.View;
workbookPermission = WorkbookPermission.LimitedView;
}

await checkWorkbookPermission({
Expand Down
1 change: 0 additions & 1 deletion src/services/entry/actions/create-in-workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ export async function createEntryInWorkbook(

if (includePermissionsInfo) {
permissions = getEntryPermissionsByWorkbook({
ctx,
workbook,
scope: resultEntry.scope,
});
Expand Down
1 change: 0 additions & 1 deletion src/services/entry/actions/get-entry-relations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ export async function getEntryRelations(
return {
...item,
permissions: getEntryPermissionsByWorkbook({
ctx,
workbook,
scope: item.scope,
}),
Expand Down
5 changes: 1 addition & 4 deletions src/services/new/collection/get-collection-breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {AppError} from '@gravity-ui/nodekit';

import {Feature, isEnabledFeature} from '../../../components/features';
import {US_ERRORS} from '../../../const';
import {CollectionPermission} from '../../../entities/collection';
import Utils from '../../../utils';
Expand Down Expand Up @@ -59,9 +58,7 @@ export const getCollectionBreadcrumbs = async (

await collectionInstance.checkPermission({
parentIds,
permission: isEnabledFeature(ctx, Feature.UseLimitedView)
? CollectionPermission.LimitedView
: CollectionPermission.View,
permission: CollectionPermission.LimitedView,
});

if (includePermissionsInfo) {
Expand Down
9 changes: 2 additions & 7 deletions src/services/new/collection/get-collection-content.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {AppError} from '@gravity-ui/nodekit';

import {Feature, isEnabledFeature} from '../../../components/features';
import {US_ERRORS} from '../../../const';
import {CollectionModel, CollectionModelColumn} from '../../../db/models/new/collection';
import {CollectionPermission} from '../../../entities/collection';
Expand Down Expand Up @@ -93,9 +92,7 @@ export const getCollectionContent = async (

await collection.checkPermission({
parentIds,
permission: isEnabledFeature(ctx, Feature.UseLimitedView)
? CollectionPermission.LimitedView
: CollectionPermission.View,
permission: CollectionPermission.LimitedView,
});
}
}
Expand Down Expand Up @@ -149,9 +146,7 @@ export const getCollectionContent = async (
try {
await collection.checkPermission({
parentIds: contentParentIds,
permission: isEnabledFeature(ctx, Feature.UseLimitedView)
? CollectionPermission.LimitedView
: CollectionPermission.View,
permission: CollectionPermission.LimitedView,
});

return collection;
Expand Down
5 changes: 1 addition & 4 deletions src/services/new/collection/get-collections-list-by-ids.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Feature, isEnabledFeature} from '../../../components/features';
import {CollectionModel, CollectionModelColumn} from '../../../db/models/new/collection';
import {CollectionPermission} from '../../../entities/collection';
import {CollectionInstance} from '../../../registry/common/entities/collection/types';
Expand Down Expand Up @@ -60,9 +59,7 @@ export const getCollectionsListByIds = async (
const promise = collection
.checkPermission({
parentIds,
permission: isEnabledFeature(ctx, Feature.UseLimitedView)
? CollectionPermission.LimitedView
: CollectionPermission.View,
permission: CollectionPermission.LimitedView,
})
.then(() => {
acceptedCollectionsMap.set(collection.model, parentIds);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Feature, isEnabledFeature} from '../../../../components/features';
import {CollectionPermission} from '../../../../entities/collection';
import {CollectionInstance} from '../../../../registry/common/entities/collection/types';
import {ServiceArgs} from '../../types';
Expand Down Expand Up @@ -38,10 +37,8 @@ export const checkAndSetCollectionPermission = async (

if (permission) {
localPermission = permission;
} else if (isEnabledFeature(ctx, Feature.UseLimitedView)) {
localPermission = CollectionPermission.LimitedView;
} else {
localPermission = CollectionPermission.View;
localPermission = CollectionPermission.LimitedView;
}

if (collectionInstance.model.parentId !== null) {
Expand Down
1 change: 0 additions & 1 deletion src/services/new/entry/get-entry-by-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export const getEntryByKey = async (

if (includePermissionsInfo) {
iamPermissions = getEntryPermissionsByWorkbook({
ctx,
workbook,
scope: joinedEntryRevision[EntryColumn.Scope],
});
Expand Down
1 change: 0 additions & 1 deletion src/services/new/entry/get-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ export const getEntry = async (

if (includePermissionsInfo) {
iamPermissions = getEntryPermissionsByWorkbook({
ctx,
workbook,
scope: joinedEntryRevisionFavorite[EntryColumn.Scope],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export const filterEntriesByPermission = async <T extends PartialEntry>(

if (workbook) {
const permissions = getEntryPermissionsByWorkbook({
ctx,
workbook,
scope: entry.scope,
});
Expand Down
5 changes: 1 addition & 4 deletions src/services/new/structure-item/get-structure-items.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Feature, isEnabledFeature} from '../../../components/features';
import {makeSchemaValidator} from '../../../components/validation-schema-compiler';
import {CollectionModel} from '../../../db/models/new/collection';
import {CollectionPermission} from '../../../entities/collection';
Expand Down Expand Up @@ -118,9 +117,7 @@ export const getStructureItems = async (

await collection.checkPermission({
parentIds,
permission: isEnabledFeature(ctx, Feature.UseLimitedView)
? CollectionPermission.LimitedView
: CollectionPermission.View,
permission: CollectionPermission.LimitedView,
});
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/services/new/structure-item/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {AppContext, AppError} from '@gravity-ui/nodekit';
import {raw} from 'objection';

import {Feature, isEnabledFeature} from '../../../components/features';
import {US_ERRORS} from '../../../const';
import {CollectionModel, CollectionModelColumn} from '../../../db/models/new/collection';
import {WorkbookModel, WorkbookModelColumn} from '../../../db/models/new/workbook';
Expand Down Expand Up @@ -140,16 +139,12 @@ export const processPermissions = async ({
if (isWorkbookInstance(item)) {
await item.checkPermission({
parentIds,
permission: isEnabledFeature(ctx, Feature.UseLimitedView)
? WorkbookPermission.LimitedView
: WorkbookPermission.View,
permission: WorkbookPermission.LimitedView,
});
} else {
await item.checkPermission({
parentIds,
permission: isEnabledFeature(ctx, Feature.UseLimitedView)
? CollectionPermission.LimitedView
: CollectionPermission.View,
permission: CollectionPermission.LimitedView,
});
}

Expand Down
4 changes: 1 addition & 3 deletions src/services/new/workbook/get-workbook-content.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Feature, isEnabledFeature} from '../../../components/features';
import {makeSchemaValidator} from '../../../components/validation-schema-compiler';
import {DEFAULT_PAGE, DEFAULT_PAGE_SIZE} from '../../../const';
import {EntryScope} from '../../../db/models/new/entry/types';
Expand Down Expand Up @@ -131,7 +130,7 @@ export const getWorkbookContent = async (
isDeleted: false,
});

if (isEnabledFeature(ctx, Feature.UseLimitedView) && !workbook.permissions?.view) {
if (!workbook.permissions?.view) {
builder.whereNotIn('scope', ['dataset', 'connection']);
}
if (createdBy) {
Expand Down Expand Up @@ -178,7 +177,6 @@ export const getWorkbookContent = async (

if (includePermissionsInfo) {
permissions = getEntryPermissionsByWorkbook({
ctx,
workbook,
scope: entry.scope,
});
Expand Down
5 changes: 1 addition & 4 deletions src/services/new/workbook/get-workbook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {AppError} from '@gravity-ui/nodekit';

import {Feature, isEnabledFeature} from '../../../components/features';
import {makeSchemaValidator} from '../../../components/validation-schema-compiler';
import {US_ERRORS} from '../../../const';
import {WorkbookModel, WorkbookModelColumn} from '../../../db/models/new/workbook';
Expand Down Expand Up @@ -93,9 +92,7 @@ export const getWorkbook = async <T extends WorkbookInstance = WorkbookInstance>

await workbook.checkPermission({
parentIds,
permission: isEnabledFeature(ctx, Feature.UseLimitedView)
? WorkbookPermission.LimitedView
: WorkbookPermission.View,
permission: WorkbookPermission.LimitedView,
});

if (includePermissionsInfo) {
Expand Down
5 changes: 1 addition & 4 deletions src/services/new/workbook/get-workbooks-list-by-ids.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Feature, isEnabledFeature} from '../../../components/features';
import {makeSchemaValidator} from '../../../components/validation-schema-compiler';
import {WorkbookModel, WorkbookModelColumn} from '../../../db/models/new/workbook';
import {WorkbookPermission} from '../../../entities/workbook';
Expand Down Expand Up @@ -82,9 +81,7 @@ export const getWorkbooksListByIds = async (
const promise = workbook
.checkPermission({
parentIds,
permission: isEnabledFeature(ctx, Feature.UseLimitedView)
? WorkbookPermission.LimitedView
: WorkbookPermission.View,
permission: WorkbookPermission.LimitedView,
})
.then(() => {
acceptedWorkbooksMap.set(workbook.model, parentIds);
Expand Down
9 changes: 2 additions & 7 deletions src/services/new/workbook/get-workbooks-list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {AppError} from '@gravity-ui/nodekit';

import {Feature, isEnabledFeature} from '../../../components/features';
import {makeSchemaValidator} from '../../../components/validation-schema-compiler';
import {DEFAULT_PAGE, DEFAULT_PAGE_SIZE, US_ERRORS} from '../../../const';
import {CollectionModel} from '../../../db/models/new/collection';
Expand Down Expand Up @@ -123,9 +122,7 @@ export const getWorkbooksList = async (

await collection.checkPermission({
parentIds: parents.slice(1).map((model) => model.collectionId),
permission: isEnabledFeature(ctx, Feature.UseLimitedView)
? CollectionPermission.LimitedView
: CollectionPermission.View,
permission: CollectionPermission.LimitedView,
});
}
}
Expand Down Expand Up @@ -177,9 +174,7 @@ export const getWorkbooksList = async (
try {
await workbook.checkPermission({
parentIds,
permission: isEnabledFeature(ctx, Feature.UseLimitedView)
? WorkbookPermission.LimitedView
: WorkbookPermission.View,
permission: WorkbookPermission.LimitedView,
});

return workbook;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import {AppContext} from '@gravity-ui/nodekit';

import {Feature, isEnabledFeature} from '../../../../components/features';
import {EntryScope} from '../../../../db/models/new/entry/types';
import {Permissions} from '../../../../entities/workbook';
import type {WorkbookInstance} from '../../../../registry/common/entities/workbook/types';
import type {EntryScope as EntryScopeType} from '../../../../types/models';

export const getEntryPermissionsByWorkbook = ({
ctx,
workbook,
scope,
}: {
ctx: AppContext;
workbook: WorkbookInstance;
scope?: EntryScopeType | null;
}) => {
const permissions = workbook.permissions as Permissions;

const view = isEnabledFeature(ctx, Feature.UseLimitedView)
? permissions.limitedView
: permissions.view;
const view = permissions.limitedView;

const mappedPermission = {
execute: view,
Expand Down

0 comments on commit e92c4ab

Please sign in to comment.