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

feat: userroles and permission on dashboard recipe #718

Merged
merged 27 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cc81759
init userroles and permission on dashboard
Chakravarthy7102 Oct 16, 2023
b773e22
prog: added new endpoints for handling role and permissions
Chakravarthy7102 Oct 16, 2023
d33534b
feat: add permisions handlers
Chakravarthy7102 Oct 16, 2023
e7e9f1a
build files
Chakravarthy7102 Oct 16, 2023
4cacf26
Merge branch '16.3' of github.com:supertokens/supertokens-node into f…
Chakravarthy7102 Oct 16, 2023
23d6312
progress
Chakravarthy7102 Oct 16, 2023
641e4f0
add feature not enabled checks
Chakravarthy7102 Oct 17, 2023
03a49a5
fix: handle diffrent routes
Chakravarthy7102 Oct 18, 2023
f445d15
fixes
Chakravarthy7102 Oct 18, 2023
3a6503f
use util function provided tenantId
Chakravarthy7102 Oct 18, 2023
f11cfcc
fix wrong request methods and payload access pattern
Chakravarthy7102 Oct 19, 2023
5811643
Add feature not enabled check to all the API's
Chakravarthy7102 Nov 7, 2023
dd9ee0c
Fix returing types and merge create update roles to one single api
Chakravarthy7102 Nov 8, 2023
53aa598
update getAllRoles api to return non paginated results as well
Chakravarthy7102 Nov 9, 2023
a76b756
Updata Changelog and version bump
Chakravarthy7102 Nov 10, 2023
be4c3b2
bump version v16.5.0
Chakravarthy7102 Nov 10, 2023
3cb4c2e
Merge branch 'master' of github.com:supertokens/supertokens-node into…
Chakravarthy7102 Nov 10, 2023
362da88
fix: send latest created roles first
Chakravarthy7102 Nov 14, 2023
62e26c7
change return type
Chakravarthy7102 Nov 15, 2023
39a6f9a
fixes conflicts
rishabhpoddar Nov 16, 2023
0b72990
remove default check
Chakravarthy7102 Nov 16, 2023
7ff2320
Merge branch 'feat/dashboard-userroles' of github.com:supertokens/sup…
Chakravarthy7102 Nov 16, 2023
5171485
add role validation check in permissions api
Chakravarthy7102 Nov 16, 2023
dbfab57
refactor code
Chakravarthy7102 Nov 16, 2023
252c2f0
Merge branch 'master' of github.com:supertokens/supertokens-node into…
Chakravarthy7102 Nov 23, 2023
1f97fac
bump version v16.6.0
Chakravarthy7102 Nov 23, 2023
fa30d32
fix: version
Chakravarthy7102 Nov 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

## [unreleased]

### Added

- Added User roles and permissions feature to dashboard recipe.

## [16.5.1] - 2023-11-15

- Fixes issue with `createResetPasswordLink` and `sendResetPasswordEmail` in thirdpartyemailpassword recipe.
Expand Down
11 changes: 4 additions & 7 deletions lib/build/framework/fastify/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
// @ts-nocheck
/// <reference types="node" />
export type { SessionRequest } from "./framework";
export declare const plugin: import("fastify").FastifyPluginCallback<
Record<never, never>,
import("fastify").RawServerDefault
>;
export declare const plugin: import("fastify").FastifyPluginCallback<Record<never, never>, import("http").Server>;
export declare const errorHandler: () => (
err: any,
req: import("fastify").FastifyRequest<
import("fastify/types/route").RouteGenericInterface,
import("fastify").RawServerDefault,
import("http").Server,
import("http").IncomingMessage
>,
res: import("fastify").FastifyReply<
import("fastify").RawServerDefault,
import("http").Server,
import("http").IncomingMessage,
import("http").ServerResponse<import("http").IncomingMessage>,
import("http").ServerResponse,
import("fastify/types/route").RouteGenericInterface,
unknown
>
Expand Down
2 changes: 1 addition & 1 deletion lib/build/framework/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export declare function setCookieForServerResponse(
expires: number,
path: string,
sameSite: "strict" | "lax" | "none"
): ServerResponse<IncomingMessage>;
): ServerResponse;
export declare function getCookieValueToSetInHeader(
prev: string | string[] | undefined,
val: string | string[],
Expand Down
12 changes: 9 additions & 3 deletions lib/build/recipe/dashboard/api/userroles/addRoleToUser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ declare const addRoleToUser: (
tenantId: string,
options: APIOptions,
__: any
) => Promise<{
status: "OK" | "UNKNOWN_ROLE_ERROR" | "ROLE_ALREADY_ASSIGNED";
}>;
) => Promise<
| {
status: "OK";
didUserAlreadyHaveRole: boolean;
}
| {
status: "UNKNOWN_ROLE_ERROR" | "FEATURE_NOT_ENABLED_ERROR";
}
>;
export default addRoleToUser;
22 changes: 9 additions & 13 deletions lib/build/recipe/dashboard/api/userroles/addRoleToUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ var __importDefault =
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const recipe_1 = __importDefault(require("../../../userroles/recipe"));
const userroles_1 = __importDefault(require("../../../userroles"));
const error_1 = __importDefault(require("../../../../error"));
const addRoleToUser = async (_, tenantId, options, __) => {
try {
recipe_1.default.getInstanceOrThrowError();
} catch (_) {
return {
status: "FEATURE_NOT_ENABLED_ERROR",
};
}
const requestBody = await options.req.getJSONBody();
const userId = requestBody.userId;
const role = requestBody.role;
Expand All @@ -24,18 +32,6 @@ const addRoleToUser = async (_, tenantId, options, __) => {
});
}
const response = await userroles_1.default.addRoleToUser(tenantId, userId, role);
if (response.status === "OK" && response.didUserAlreadyHaveRole === true) {
return {
status: "ROLE_ALREADY_ASSIGNED",
};
}
if (response.status === "UNKNOWN_ROLE_ERROR") {
return {
status: "UNKNOWN_ROLE_ERROR",
};
}
return {
status: "OK",
};
return response;
};
exports.default = addRoleToUser;

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ declare const getPermissionsForRole: (
___: string,
options: APIOptions,
__: any
) => Promise<{
status: "OK";
permissions: string[];
}>;
) => Promise<
| {
status: "OK";
permissions: string[];
}
| {
status: "FEATURE_NOT_ENABLED_ERROR" | "UNKNOWN_ROLE_ERROR";
}
>;
export default getPermissionsForRole;
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ var __importDefault =
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const recipe_1 = __importDefault(require("../../../../userroles/recipe"));
const userroles_1 = __importDefault(require("../../../../userroles"));
const error_1 = __importDefault(require("../../../../../error"));
const getPermissionsForRole = async (_, ___, options, __) => {
try {
recipe_1.default.getInstanceOrThrowError();
} catch (_) {
return {
status: "FEATURE_NOT_ENABLED_ERROR",
};
}
const role = options.req.getKeyValueFromQuery("role");
if (role === undefined || typeof role !== "string") {
throw new error_1.default({
Expand All @@ -16,12 +24,6 @@ const getPermissionsForRole = async (_, ___, options, __) => {
});
}
const response = await userroles_1.default.getPermissionsForRole(role);
if (response.status === "UNKNOWN_ROLE_ERROR") {
return {
status: "OK",
permissions: [],
};
}
return response;
};
exports.default = getPermissionsForRole;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ declare const removePermissionsFromRole: (
options: APIOptions,
__: any
) => Promise<{
status: "OK" | "UNKNOWN_ROLE_ERROR";
status: "OK" | "UNKNOWN_ROLE_ERROR" | "FEATURE_NOT_ENABLED_ERROR";
}>;
export default removePermissionsFromRole;
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ var __importDefault =
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const recipe_1 = __importDefault(require("../../../../userroles/recipe"));
const userroles_1 = __importDefault(require("../../../../userroles"));
const error_1 = __importDefault(require("../../../../../error"));
const removePermissionsFromRole = async (_, ___, options, __) => {
try {
recipe_1.default.getInstanceOrThrowError();
} catch (_) {
return {
status: "FEATURE_NOT_ENABLED_ERROR",
};
}
const requestBody = await options.req.getJSONBody();
const role = requestBody.role;
const permissions = requestBody.permissions;
Expand Down
3 changes: 2 additions & 1 deletion lib/build/recipe/dashboard/api/userroles/removeUserRole.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ declare const removeUserRole: (
) => Promise<
| {
status: "OK";
didUserHaveRole: boolean;
}
| {
status: "UNKNOWN_ROLE_ERROR";
status: "UNKNOWN_ROLE_ERROR" | "FEATURE_NOT_ENABLED_ERROR";
}
>;
export default removeUserRole;
8 changes: 8 additions & 0 deletions lib/build/recipe/dashboard/api/userroles/removeUserRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ var __importDefault =
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const recipe_1 = __importDefault(require("../../../userroles/recipe"));
const userroles_1 = __importDefault(require("../../../userroles"));
const error_1 = __importDefault(require("../../../../error"));
const removeUserRole = async (_, tenantId, options, __) => {
try {
recipe_1.default.getInstanceOrThrowError();
} catch (_) {
return {
status: "FEATURE_NOT_ENABLED_ERROR",
};
}
const userId = options.req.getKeyValueFromQuery("userId");
const role = options.req.getKeyValueFromQuery("role");
if (role === undefined || typeof role !== "string") {
Expand Down
11 changes: 0 additions & 11 deletions lib/build/recipe/dashboard/api/userroles/roles/createRole.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "../../../types";
declare const createRoleOrAddPermissions: (
_: APIInterface,
__: string,
options: APIOptions,
___: any
) => Promise<
| {
status: "OK";
createdNewRole: boolean;
}
| {
status: "FEATURE_NOT_ENABLED_ERROR";
}
>;
export default createRoleOrAddPermissions;
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ var __importDefault =
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const recipe_1 = __importDefault(require("../../../../userroles/recipe"));
const userroles_1 = __importDefault(require("../../../../userroles"));
const error_1 = __importDefault(require("../../../../../error"));
const createRole = async (_, __, options, ___) => {
const createRoleOrAddPermissions = async (_, __, options, ___) => {
try {
recipe_1.default.getInstanceOrThrowError();
} catch (_) {
return {
status: "FEATURE_NOT_ENABLED_ERROR",
};
}
const requestBody = await options.req.getJSONBody();
const permissions = requestBody.permissions;
const role = requestBody.role;
Expand All @@ -23,15 +31,7 @@ const createRole = async (_, __, options, ___) => {
type: error_1.default.BAD_INPUT_ERROR,
});
}
//TODO: check for a is this role already exists or not before creating the new role.
const response = await userroles_1.default.createNewRoleOrAddPermissions(role, permissions);
if (response.status === "OK" && response.createdNewRole === false) {
return {
status: "ROLE_ALREADY_EXITS",
};
}
return {
status: "OK",
};
return response;
};
exports.default = createRole;
exports.default = createRoleOrAddPermissions;
12 changes: 9 additions & 3 deletions lib/build/recipe/dashboard/api/userroles/roles/deleteRole.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ declare const deleteRole: (
___: string,
options: APIOptions,
__: any
) => Promise<{
status: "OK" | "ROLE_DO_NOT_EXISTS";
}>;
) => Promise<
| {
status: "OK";
didRoleExist: boolean;
}
| {
status: "FEATURE_NOT_ENABLED_ERROR";
}
>;
export default deleteRole;
17 changes: 9 additions & 8 deletions lib/build/recipe/dashboard/api/userroles/roles/deleteRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ var __importDefault =
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const recipe_1 = __importDefault(require("../../../../userroles/recipe"));
const userroles_1 = __importDefault(require("../../../../userroles"));
const error_1 = __importDefault(require("../../../../../error"));
const deleteRole = async (_, ___, options, __) => {
try {
recipe_1.default.getInstanceOrThrowError();
} catch (_) {
return {
status: "FEATURE_NOT_ENABLED_ERROR",
};
}
const role = options.req.getKeyValueFromQuery("role");
if (role === undefined || typeof role !== "string") {
throw new error_1.default({
Expand All @@ -16,13 +24,6 @@ const deleteRole = async (_, ___, options, __) => {
});
}
const response = await userroles_1.default.deleteRole(role);
if (response.status === "OK" && response.didRoleExist === false) {
return {
status: "ROLE_DO_NOT_EXISTS",
};
}
return {
status: "OK",
};
return response;
};
exports.default = deleteRole;
Loading
Loading