Skip to content
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

🕹 Manage root users #146

Merged
merged 14 commits into from
Aug 28, 2023
Merged

🕹 Manage root users #146

merged 14 commits into from
Aug 28, 2023

Conversation

MontaGhanmy
Copy link
Collaborator

No description provided.

@@ -175,6 +186,13 @@ export class DocumentsController {
)
: [],
};

if(id == "root" && companyUserRole < 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does 1 mean?

(Magic constant spotted).

I recommend to extract this as a global variable and give it a name.

Comment on lines 110 to 112
/* useEffect(() => {
props.onChangePassword(usePassword ? password : '');
}, [usePassword, password]); */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code?

Copy link
Member

@chibenwa chibenwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My 2 cents...

@@ -187,7 +189,7 @@ export class DocumentsController {
: [],
};

if(id == "root" && companyUserRole < 1) {
if (id == "root" && companyUserRole < 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the meaning of 1 here?
That's the magic constant syndrom. I would recommand to:

    1. Strong type. It looks like some kind of permissions is encoded as an int. This could be made explicit with a type, that could furthermore encapsulate and centralize right checking logic, that then could (must?) be unit tested?
    1. Extract constants to give them a name. Favor enums if supported in typescript.

{ id: update.company_id },
{ id: update.user_id },
);
if (companyUser) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the guy is not a company user?
We likely should return an HTTP error for this, no? 406 not acceptable ?

@github-actions
Copy link

github-actions bot commented Jul 26, 2023

Coverage Report

  • Status: ✅ Passed

Click to view remaining coverage report
Status File Stmts Branch Funcs Lines
total 66.57 47.29 61.78 66.4
/usr/src/app/src/version.ts 100 100 100 100
/usr/src/app/src/core/config/index.ts 100 100 100 100
/usr/src/app/src/core/crypto/index.ts 91.3 100 100 90.9
/usr/src/app/src/core/crypto/legacy.ts 85.71 57.14 50 85.71
/usr/src/app/src/core/crypto/v1.ts 86.36 71.42 100 86.36
/usr/src/app/src/core/crypto/v2.ts 88 71.42 100 88
/usr/src/app/src/core/platform/platform.ts 80 100 50 80
/usr/src/app/src/core/platform/framework/configuration.ts 100 100 100 100
/usr/src/app/src/core/platform/framework/event-bus.ts 93.75 83.33 100 93.75
/usr/src/app/src/core/platform/framework/factory.ts 100 100 100 100
/usr/src/app/src/core/platform/framework/index.ts 100 100 100 100
/usr/src/app/src/core/platform/framework/logger.ts 100 50 100 100
/usr/src/app/src/core/platform/framework/api/application-configuration.ts 100 100 100 100
/usr/src/app/src/core/platform/framework/api/component.ts 92.59 81.81 100 92.3
/usr/src/app/src/core/platform/framework/api/constants.ts 100 100 100 100
/usr/src/app/src/core/platform/framework/api/container.ts 70.37 50 66.66 76
/usr/src/app/src/core/platform/framework/api/crud-service.ts 92.59 75 81.81 91.11
/usr/src/app/src/core/platform/framework/api/index.ts 100 100 100 100
/usr/src/app/src/core/platform/framework/api/service-options.ts 100 100 100 100
/usr/src/app/src/core/platform/framework/api/service-state.ts 100 100 100 100
/usr/src/app/src/core/platform/framework/api/service.ts 58.73 68.75 77.77 58.73
/usr/src/app/src/core/platform/framework/decorators/consumes.ts 100 0 100 100
/usr/src/app/src/core/platform/framework/decorators/index.ts 100 100 100 100
/usr/src/app/src/core/platform/framework/decorators/prefix.ts 100 0 100 100
/usr/src/app/src/core/platform/framework/decorators/service-name.ts 100 100 100 100
/usr/src/app/src/core/platform/framework/decorators/skip.ts 92.85 66.66 100 92.3
/usr/src/app/src/core/platform/framework/decorators/realtime/created.ts 100 80 100 100
/usr/src/app/src/core/platform/framework/decorators/realtime/deleted.ts 100 100 100 100
/usr/src/app/src/core/platform/framework/decorators/realtime/index.ts 90 57.14 75 94.44
/usr/src/app/src/core/platform/framework/decorators/realtime/saved.ts 100 100 100 100
/usr/src/app/src/core/platform/framework/decorators/realtime/updated.ts 100 100 100 100
/usr/src/app/src/core/platform/framework/utils/component-utils.ts 73.8 11.11 100 75.6
/usr/src/app/src/core/platform/framework/utils/loader.ts 76.19 60 85.71 73.68
/usr/src/app/src/core/platform/services/auth/index.ts 100 100 100 100
/usr/src/app/src/core/platform/services/auth/service.ts 78.57 50 50 78.57
/usr/src/app/src/core/platform/services/auth/web/index.ts 100 100 100 100
/usr/src/app/src/core/platform/services/auth/web/jwt.ts 100 88.88 100 100
/usr/src/app/src/core/platform/services/auth/web/routes.ts 62.5 100 33.33 71.42
/usr/src/app/src/core/platform/services/counter/index.ts 100 100 100 100
/usr/src/app/src/core/platform/services/counter/provider.ts 85.71 80 100 85.71
/usr/src/app/src/core/platform/services/cron/index.ts 34.78 0 28.57 34.78
/usr/src/app/src/core/platform/services/database/index.ts 86.95 0 100 85.71
/usr/src/app/src/core/platform/services/database/services/connector-factory.ts 71.42 33.33 100 71.42
/usr/src/app/src/core/platform/services/database/services/index.ts 93.33 100 75 93.33
/usr/src/app/src/core/platform/services/database/services/orm/manager.ts 83.33 62.5 90 84.61
/usr/src/app/src/core/platform/services/database/services/orm/utils.ts 94.87 80.95 100 94.73
/usr/src/app/src/core/platform/services/database/services/orm/connectors/abstract-connector.ts 57.14 100 25 40
/usr/src/app/src/core/platform/services/database/services/orm/connectors/cassandra/cassandra.ts 78.26 58.73 74.13 78
/usr/src/app/src/core/platform/services/database/services/orm/connectors/cassandra/pagination.ts 22.22 0 0 25
/usr/src/app/src/core/platform/services/database/services/orm/connectors/cassandra/query-builder.ts 91.83 71.42 84.61 93.02
/usr/src/app/src/core/platform/services/database/services/orm/connectors/cassandra/typeTransforms.ts 82.5 80.3 100 83.11
/usr/src/app/src/core/platform/services/database/services/orm/connectors/mongodb/mongodb.ts 9.43 0 0 8.91
/usr/src/app/src/core/platform/services/database/services/orm/connectors/mongodb/pagination.ts 14.28 0 0 15.38
/usr/src/app/src/core/platform/services/database/services/orm/connectors/mongodb/query-builder.ts 14.7 0 0 15.62
/usr/src/app/src/core/platform/services/database/services/orm/connectors/mongodb/typeTransforms.ts 12.28 0 0 9.25
/usr/src/app/src/core/platform/services/database/services/orm/decorators/column.ts 100 100 100 100
/usr/src/app/src/core/platform/services/database/services/orm/decorators/entity.ts 100 50 100 100
/usr/src/app/src/core/platform/services/database/services/orm/decorators/index.ts 100 100 100 100
/usr/src/app/src/core/platform/services/database/services/orm/repository/manager.ts 84.61 100 100 84.61
/usr/src/app/src/core/platform/services/database/services/orm/repository/repository.ts 84.37 77.77 80 87.09
/usr/src/app/src/core/platform/services/email-pusher/index.ts 34.88 0 50 35.71
/usr/src/app/src/core/platform/services/message-queue/api.ts 81.25 57.14 77.77 82.6
/usr/src/app/src/core/platform/services/message-queue/bus.ts 83.33 100 66.66 83.33
/usr/src/app/src/core/platform/services/message-queue/factory.ts 83.33 50 100 83.33
/usr/src/app/src/core/platform/services/message-queue/index.ts 80.95 50 75 80
/usr/src/app/src/core/platform/services/message-queue/processor.ts 58.33 20 50 58.33
/usr/src/app/src/core/platform/services/message-queue/proxy.ts 52.63 23.8 40 53.57
/usr/src/app/src/core/platform/services/message-queue/amqp/client.ts 80.95 60 84.21 80.48
/usr/src/app/src/core/platform/services/message-queue/amqp/constants.ts 100 100 100 100
/usr/src/app/src/core/platform/services/message-queue/amqp/index.ts 73.07 100 55.55 73.07
/usr/src/app/src/core/platform/services/message-queue/amqp/manager.ts 76.74 33.33 66.66 76.74
/usr/src/app/src/core/platform/services/message-queue/amqp/pubsub.ts 84.21 52.17 83.33 84.21
/usr/src/app/src/core/platform/services/message-queue/amqp/pubsubclient.ts 74.19 61.11 84.61 75.86
/usr/src/app/src/core/platform/services/message-queue/local/index.ts 15.62 0 0 15.62
/usr/src/app/src/core/platform/services/push/index.ts 63.15 16.66 75 58.82
/usr/src/app/src/core/platform/services/push/connectors/fcm/service.ts 18.75 0 0 18.75
/usr/src/app/src/core/platform/services/realtime/bus.ts 100 100 100 100
/usr/src/app/src/core/platform/services/realtime/index.ts 80 100 50 78.57
/usr/src/app/src/core/platform/services/realtime/types.ts 94.44 66.66 75 94.11
/usr/src/app/src/core/platform/services/realtime/services/entity-manager.ts 81.81 0 66.66 81.81
/usr/src/app/src/core/platform/services/realtime/services/room-manager.ts 11.47 0 11.11 10.71
/usr/src/app/src/core/platform/services/search/api.ts 100 100 100 100
/usr/src/app/src/core/platform/services/search/index.ts 74.28 33.33 66.66 74.19
/usr/src/app/src/core/platform/services/search/repository.ts 88.88 33.33 100 88.46
/usr/src/app/src/core/platform/services/search/adapters/abstract.ts 60 100 33.33 60
/usr/src/app/src/core/platform/services/search/adapters/ascii-folder.ts 64.7 30 50 91.66
/usr/src/app/src/core/platform/services/search/adapters/utils.ts 76.92 0 77.77 77.27
/usr/src/app/src/core/platform/services/search/adapters/elasticsearch/index.ts 75.43 59.66 81.81 74.77
/usr/src/app/src/core/platform/services/search/adapters/elasticsearch/search.ts 90.16 81.6 100 90.16
/usr/src/app/src/core/platform/services/search/adapters/mongosearch/index.ts 11.11 0 0 11.11
/usr/src/app/src/core/platform/services/search/adapters/mongosearch/search.ts 11.11 0 0 11.42
/usr/src/app/src/core/platform/services/storage/index.ts 78.37 54 90 78.57
/usr/src/app/src/core/platform/services/storage/connectors/S3/service.ts 9.67 0 0 10.34
/usr/src/app/src/core/platform/services/storage/connectors/local/service.ts 75 66.66 66.66 75
/usr/src/app/src/core/platform/services/tracker/index.ts 30.43 0 30 28.57
/usr/src/app/src/core/platform/services/tracker/adapters/segment.ts 11.11 0 0 11.53
/usr/src/app/src/core/platform/services/webserver/error.ts 100 100 100 100
/usr/src/app/src/core/platform/services/webserver/index.ts 80.88 9.09 80 82.08
/usr/src/app/src/core/platform/services/websocket/index.ts 93.75 100 75 92.85
/usr/src/app/src/core/platform/services/websocket/services/index.ts 36.11 50 41.66 36.11
/usr/src/app/src/services/global-resolver.ts 97.43 50 100 97.43
/usr/src/app/src/services/applications/index.ts 92.3 100 75 90.9
/usr/src/app/src/services/applications/realtime.ts 50 100 0 50
/usr/src/app/src/services/applications-api/index.ts 57.5 50 50 56.75
/usr/src/app/src/services/applications-api/web/index.ts 100 100 100 100
/usr/src/app/src/services/applications-api/web/routes.ts 72.22 0 25 76.47
/usr/src/app/src/services/applications-api/web/schemas.ts 100 100 100 100
/usr/src/app/src/services/applications-api/web/controllers/index.ts 13.33 0 0 13.33
/usr/src/app/src/services/applications/entities/application.ts 45.45 100 0 33.33
/usr/src/app/src/services/applications/services/applications.ts 50 0 25 60
/usr/src/app/src/services/applications/services/company-applications.ts 21.05 0 25 21.05
/usr/src/app/src/services/applications/services/hooks.ts 25.8 0 25 25.8
/usr/src/app/src/services/applications/web/index.ts 100 100 100 100
/usr/src/app/src/services/applications/web/routes.ts 100 100 100 100
/usr/src/app/src/services/applications/web/schemas.ts 100 100 100 100
/usr/src/app/src/services/applications/web/controllers/applications.ts 17.39 0 0 17.39
/usr/src/app/src/services/applications/web/controllers/company-applications.ts 27.27 0 0 27.27
/usr/src/app/src/services/console/client-factory.ts 37.5 0 0 37.5
/usr/src/app/src/services/console/index.ts 92.3 100 75 90.9
/usr/src/app/src/services/console/service.ts 88.23 100 50 88.23
/usr/src/app/src/services/console/clients/internal.ts 16.21 0 0 16.66
/usr/src/app/src/services/console/clients/remote-jwks-verifier.ts 10.81 0 0 10.81
/usr/src/app/src/services/console/clients/remote.ts 9.87 0 0 10
/usr/src/app/src/services/console/web/controller.ts 9.52 0 5.88 9.52
/usr/src/app/src/services/console/web/index.ts 100 100 100 100
/usr/src/app/src/services/console/web/routes.ts 86.66 100 33.33 86.66
/usr/src/app/src/services/console/web/schemas.ts 100 100 100 100
/usr/src/app/src/services/documents/const.ts 100 100 100 100
/usr/src/app/src/services/documents/index.ts 93.75 100 80 92.3
/usr/src/app/src/services/documents/utils.ts 80.21 74.84 91.89 78.06
/usr/src/app/src/services/documents/entities/drive-file.search.ts 100 83.33 100 100
/usr/src/app/src/services/documents/entities/drive-file.ts 100 100 100 100
/usr/src/app/src/services/documents/entities/drive-tdrive-tab.ts 68.75 100 0 100
/usr/src/app/src/services/documents/entities/file-version.ts 63.33 100 0 100
/usr/src/app/src/services/documents/services/access-check.ts 74.71 66.51 85.18 74.82
/usr/src/app/src/services/documents/services/drive-file-dto-builder.ts 100 90.9 100 100
/usr/src/app/src/services/documents/services/index.ts 64.48 51.94 66.03 64.42
/usr/src/app/src/services/documents/services/engine/extract-keywords.ts 100 100 100 100
/usr/src/app/src/services/documents/services/engine/index.ts 100 100 100 100
/usr/src/app/src/services/documents/services/engine/save-keywords.ts 80.95 83.33 80 80.95
/usr/src/app/src/services/documents/web/index.ts 100 100 100 100
/usr/src/app/src/services/documents/web/routes.ts 100 100 100 100
/usr/src/app/src/services/documents/web/schemas.ts 100 100 100 100
/usr/src/app/src/services/documents/web/controllers/documents.ts 50.26 31.57 54.54 51.61
/usr/src/app/src/services/documents/web/controllers/index.ts 100 100 100 100
/usr/src/app/src/services/files/index.ts 92.3 100 75 90.9
/usr/src/app/src/services/files/entities/file.ts 86.36 100 50 100
/usr/src/app/src/services/files/services/index.ts 69.52 61.29 64.28 68.93
/usr/src/app/src/services/files/services/preview.ts 81.81 50 80 85
/usr/src/app/src/services/files/web/index.ts 100 100 100 100
/usr/src/app/src/services/files/web/routes.ts 88.88 100 33.33 87.5
/usr/src/app/src/services/files/web/controllers/files.ts 48.88 78.78 50 48.83
/usr/src/app/src/services/files/web/controllers/index.ts 100 100 100 100
/usr/src/app/src/services/general/index.ts 92.85 100 75 91.66
/usr/src/app/src/services/general/languages.ts 100 100 100 100
/usr/src/app/src/services/general/web/index.ts 100 100 100 100
/usr/src/app/src/services/general/web/routes.ts 58.82 0 14.28 58.82
/usr/src/app/src/services/i18n/i18n-service.ts 80 100 60 80
/usr/src/app/src/services/i18n/index.ts 100 100 100 100
/usr/src/app/src/services/online/constants.ts 100 100 100 100
/usr/src/app/src/services/online/index.ts 87.5 100 66.66 83.33
/usr/src/app/src/services/online/entities/user-online.ts 73.33 100 0 90
/usr/src/app/src/services/online/pubsub/index.ts 61.53 0 50 66.66
/usr/src/app/src/services/online/pubsub/processor.ts 58.82 0 20 58.82
/usr/src/app/src/services/online/service/index.ts 24.61 0 14.28 26.22
/usr/src/app/src/services/previews/utils.ts 100 100 100 100
/usr/src/app/src/services/previews/services/files/engine/clear.ts 40 0 25 42.85
/usr/src/app/src/services/previews/services/files/engine/index.ts 100 100 100 100
/usr/src/app/src/services/previews/services/files/engine/service.ts 95.23 66.66 83.33 95.12
/usr/src/app/src/services/previews/services/files/processing/image.ts 86.36 83.33 100 86.36
/usr/src/app/src/services/previews/services/files/processing/office.ts 84.61 50 100 84.61
/usr/src/app/src/services/previews/services/files/processing/pdf.ts 76.19 0 100 75
/usr/src/app/src/services/previews/services/files/processing/service.ts 79.41 100 100 79.41
/usr/src/app/src/services/previews/services/files/processing/video.ts 81.25 62.5 92.3 80.85
/usr/src/app/src/services/statistics/index.ts 83.33 100 66.66 83.33
/usr/src/app/src/services/statistics/types.ts 100 100 100 100
/usr/src/app/src/services/statistics/entities/statistics.ts 91.66 100 0 90
/usr/src/app/src/services/statistics/service/index.ts 47.05 44.44 50 47.05
/usr/src/app/src/services/tags/index.ts 93.33 100 80 91.66
/usr/src/app/src/services/tags/entities/index.ts 100 100 100 100
/usr/src/app/src/services/tags/entities/tags.ts 100 100 100 100
/usr/src/app/src/services/tags/services/tags.ts 91.66 100 100 91.66
/usr/src/app/src/services/tags/web/index.ts 100 100 100 100
/usr/src/app/src/services/tags/web/routes.ts 100 100 100 100
/usr/src/app/src/services/tags/web/controllers/index.ts 100 100 100 100
/usr/src/app/src/services/tags/web/controllers/tags.ts 85.29 83.33 100 85.29
/usr/src/app/src/services/user/index.ts 92.3 100 75 90.9
/usr/src/app/src/services/user/realtime.ts 71.42 100 42.85 71.42
/usr/src/app/src/services/user/utils.ts 100 62.71 100 100
/usr/src/app/src/services/user/entities/company.ts 100 100 100 100
/usr/src/app/src/services/user/entities/company_user.ts 100 100 100 100
/usr/src/app/src/services/user/entities/device.ts 100 100 100 100
/usr/src/app/src/services/user/entities/external_company.ts 100 100 100 100
/usr/src/app/src/services/user/entities/external_user.ts 100 100 100 100
/usr/src/app/src/services/user/entities/user.search.ts 100 88.88 100 100
/usr/src/app/src/services/user/entities/user.ts 88.09 40 75 87.5
/usr/src/app/src/services/user/services/companies.ts 50 27.05 41.66 51.81
/usr/src/app/src/services/user/services/external_links/index.ts 44 0 33.33 44
/usr/src/app/src/services/user/services/users/service.ts 50.96 42.37 51.28 52.81
/usr/src/app/src/services/user/web/controller.ts 78.65 73.33 80 77.38
/usr/src/app/src/services/user/web/index.ts 100 100 100 100
/usr/src/app/src/services/user/web/routes.ts 95.65 0 100 95.45
/usr/src/app/src/services/user/web/schemas.ts 100 100 100 100
/usr/src/app/src/services/user/web/types.ts 100 100 100 100
/usr/src/app/src/services/workspaces/index.ts 92.3 100 75 90.9
/usr/src/app/src/services/workspaces/realtime.ts 87.5 75 75 87.5
/usr/src/app/src/services/workspaces/entities/workspace.ts 100 100 100 100
/usr/src/app/src/services/workspaces/entities/workspace_counters.ts 100 100 100 100
/usr/src/app/src/services/workspaces/entities/workspace_invite_domain.ts 90.9 100 0 88.88
/usr/src/app/src/services/workspaces/entities/workspace_invite_tokens.ts 92.3 100 0 90.9
/usr/src/app/src/services/workspaces/entities/workspace_pending_users.ts 91.66 100 0 90
/usr/src/app/src/services/workspaces/entities/workspace_user.ts 100 66.66 100 100
/usr/src/app/src/services/workspaces/services/workspace.ts 54.89 37.79 62 55.02
/usr/src/app/src/services/workspaces/web/index.ts 100 100 100 100
/usr/src/app/src/services/workspaces/web/routes.ts 72.82 24.24 64.7 71.91
/usr/src/app/src/services/workspaces/web/schemas.ts 100 100 100 100
/usr/src/app/src/services/workspaces/web/controllers/workspace-invite-tokens.ts 8.33 0 0 8.47
/usr/src/app/src/services/workspaces/web/controllers/workspace-users.ts 55.47 44.64 62.85 57.14
/usr/src/app/src/services/workspaces/web/controllers/workspaces.ts 80.43 76.66 86.95 80.43
/usr/src/app/src/utils/coalesce.ts 25 0 0 25
/usr/src/app/src/utils/company.ts 82.6 75 50 82.6
/usr/src/app/src/utils/counters.ts 100 100 100 100
/usr/src/app/src/utils/files.ts 88.67 100 80 89.47
/usr/src/app/src/utils/handleError.ts 33.33 0 0 33.33
/usr/src/app/src/utils/mime.ts 100 100 100 100
/usr/src/app/src/utils/password-encoder.ts 50 0 50 50
/usr/src/app/src/utils/pick.ts 100 100 100 100
/usr/src/app/src/utils/types.ts 100 100 100 100
/usr/src/app/src/utils/users.ts 79.31 70.45 100 81.48
/usr/src/app/src/utils/uuid-reducer.ts 40 0 0 33.33
/usr/src/app/src/utils/workspace.ts 33.33 14.28 25 33.33
/usr/src/app/test/e2e/utils.prepare.db.ts 78.88 75 68.18 80.23
/usr/src/app/test/e2e/common/common_test_helpers.ts 100 69.23 100 100
/usr/src/app/test/e2e/common/entities/mock_entities.ts 100 100 100 100
/usr/src/app/test/e2e/documents/utils.ts 100 100 100 100
/usr/src/app/test/e2e/setup/index.ts 88.88 50 100 88.88

Total 66.4%
Change from base: 0%
Covered Lines: 4451
Total Lines: 6703

@@ -189,7 +189,7 @@ export class DocumentsController {
: [],
};

if (id == "root" && companyUserRole < 1) {
if (id == "root" && companyUserRole == 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create constants for each value user role?

Or even better use an enum: https://www.typescriptlang.org/docs/handbook/enums.html ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The snippet above is outdated.

@MontaGhanmy MontaGhanmy merged commit 84270a3 into main Aug 28, 2023
4 checks passed
@MontaGhanmy MontaGhanmy deleted the manage_root_users branch September 5, 2023 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants