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 all 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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ 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]

## [16.6.0] - 2023-11-23

### Added

- Added User roles and permissions feature to dashboard recipe.

## [16.5.2] - 2023-11-21

- Fixes issue with `passwordReset` in emailpassword recipe for custom frameworks ([#746](https://github.com/supertokens/supertokens-node/issues/746))
Expand Down
17 changes: 17 additions & 0 deletions lib/build/recipe/dashboard/api/userroles/addRoleToUser.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "../../types";
declare const addRoleToUser: (
_: APIInterface,
tenantId: string,
options: APIOptions,
__: any
) => Promise<
| {
status: "OK";
didUserAlreadyHaveRole: boolean;
}
| {
status: "UNKNOWN_ROLE_ERROR" | "FEATURE_NOT_ENABLED_ERROR";
}
>;
export default addRoleToUser;
37 changes: 37 additions & 0 deletions lib/build/recipe/dashboard/api/userroles/addRoleToUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use strict";
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
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;
if (role === undefined || typeof role !== "string") {
throw new error_1.default({
message: "Required parameter 'role' is missing or has an invalid type",
type: error_1.default.BAD_INPUT_ERROR,
});
}
if (userId === undefined || typeof userId !== "string") {
throw new error_1.default({
message: "Required parameter 'userId' is missing or has an invalid type",
type: error_1.default.BAD_INPUT_ERROR,
});
}
const response = await userroles_1.default.addRoleToUser(tenantId, userId, role);
return response;
};
exports.default = addRoleToUser;
17 changes: 17 additions & 0 deletions lib/build/recipe/dashboard/api/userroles/getRolesForUser.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "../../types";
declare const getRolesForUser: (
_: APIInterface,
tenantId: string,
options: APIOptions,
__: any
) => Promise<
| {
status: "OK";
roles: string[];
}
| {
status: "FEATURE_NOT_ENABLED_ERROR";
}
>;
export default getRolesForUser;
29 changes: 29 additions & 0 deletions lib/build/recipe/dashboard/api/userroles/getRolesForUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const userroles_1 = __importDefault(require("../../../userroles"));
const recipe_1 = __importDefault(require("../../../userroles/recipe"));
const error_1 = __importDefault(require("../../../../error"));
const getRolesForUser = async (_, tenantId, options, __) => {
const userId = options.req.getKeyValueFromQuery("userId");
try {
recipe_1.default.getInstanceOrThrowError();
} catch (_) {
return {
status: "FEATURE_NOT_ENABLED_ERROR",
};
}
if (userId === undefined || typeof userId !== "string") {
throw new error_1.default({
message: "Required parameter 'userId' is missing or has an invalid type",
type: error_1.default.BAD_INPUT_ERROR,
});
}
const response = await userroles_1.default.getRolesForUser(tenantId, userId);
return response;
};
exports.default = getRolesForUser;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "../../../types";
declare const getPermissionsForRole: (
_: APIInterface,
___: string,
options: APIOptions,
__: any
) => 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
@@ -0,0 +1,29 @@
"use strict";
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
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({
message: "Required parameter 'role' is missing or has an invalid type",
type: error_1.default.BAD_INPUT_ERROR,
});
}
const response = await userroles_1.default.getPermissionsForRole(role);
return response;
};
exports.default = getPermissionsForRole;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "../../../types";
declare const removePermissionsFromRole: (
_: APIInterface,
___: string,
options: APIOptions,
__: any
) => Promise<{
status: "OK" | "UNKNOWN_ROLE_ERROR" | "FEATURE_NOT_ENABLED_ERROR";
}>;
export default removePermissionsFromRole;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use strict";
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
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;
if (role === undefined || typeof role !== "string") {
throw new error_1.default({
message: "Required parameter 'role' is missing or has an invalid type",
type: error_1.default.BAD_INPUT_ERROR,
});
}
if (permissions === undefined || Array.isArray(permissions) === false)
if (role === undefined) {
throw new error_1.default({
message: "Required parameter 'role' is missing or has an invalid type",
type: error_1.default.BAD_INPUT_ERROR,
});
}
const response = await userroles_1.default.removePermissionsFromRole(role, permissions);
return response;
};
exports.default = removePermissionsFromRole;
17 changes: 17 additions & 0 deletions lib/build/recipe/dashboard/api/userroles/removeUserRole.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "../../types";
declare const removeUserRole: (
_: APIInterface,
tenantId: string,
options: APIOptions,
__: any
) => Promise<
| {
status: "OK";
didUserHaveRole: boolean;
}
| {
status: "UNKNOWN_ROLE_ERROR" | "FEATURE_NOT_ENABLED_ERROR";
}
>;
export default removeUserRole;
36 changes: 36 additions & 0 deletions lib/build/recipe/dashboard/api/userroles/removeUserRole.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"use strict";
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
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") {
throw new error_1.default({
message: "Required parameter 'role' is missing or has an invalid type",
type: error_1.default.BAD_INPUT_ERROR,
});
}
if (userId === undefined || typeof userId !== "string") {
throw new error_1.default({
message: "Required parameter 'userId' is missing or has an invalid type",
type: error_1.default.BAD_INPUT_ERROR,
});
}
const response = await userroles_1.default.removeUserRole(tenantId, userId, role);
return response;
};
exports.default = removeUserRole;
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
@@ -0,0 +1,37 @@
"use strict";
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
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 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;
if (role === undefined || typeof role !== "string") {
throw new error_1.default({
message: "Required parameter 'role' is missing or has an invalid type",
type: error_1.default.BAD_INPUT_ERROR,
});
}
if (permissions === undefined || Array.isArray(permissions) === false) {
throw new error_1.default({
message: "Required parameter 'permissions' is missing or has an invalid type",
type: error_1.default.BAD_INPUT_ERROR,
});
}
const response = await userroles_1.default.createNewRoleOrAddPermissions(role, permissions);
return response;
};
exports.default = createRoleOrAddPermissions;
17 changes: 17 additions & 0 deletions lib/build/recipe/dashboard/api/userroles/roles/deleteRole.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "../../../types";
declare const deleteRole: (
_: APIInterface,
___: string,
options: APIOptions,
__: any
) => Promise<
| {
status: "OK";
didRoleExist: boolean;
}
| {
status: "FEATURE_NOT_ENABLED_ERROR";
}
>;
export default deleteRole;
29 changes: 29 additions & 0 deletions lib/build/recipe/dashboard/api/userroles/roles/deleteRole.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
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({
message: "Required parameter 'role' is missing or has an invalid type",
type: error_1.default.BAD_INPUT_ERROR,
});
}
const response = await userroles_1.default.deleteRole(role);
return response;
};
exports.default = deleteRole;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-nocheck
import { APIFunction } from "../../../types";
declare const getAllRoles: APIFunction;
export default getAllRoles;
Loading
Loading