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

broke "User" into three distinct roles #22

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion backend/models/user.mgmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const UserSchema: Schema = new Schema({
role: {
type: String,
required: true,
enum: ["User", "Admin"],
enum: ["Administrator", "Facilitator", "Learner"],
},
});

Expand Down
2 changes: 1 addition & 1 deletion backend/rest/authRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ authRouter.post("/signup", signupRequestValidator, async (req, res) => {
firstName: req.body.firstName,
lastName: req.body.lastName,
email: req.body.email,
role: "User",
role: "Facilitator",
password: req.body.password,
});

Expand Down
4 changes: 3 additions & 1 deletion backend/rest/entityRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import { sendResponseByMimeType } from "../utilities/responseUtil";
const upload = multer({ dest: "uploads/" });

const entityRouter: Router = Router();
entityRouter.use(isAuthorizedByRole(new Set(["User", "Admin"])));
entityRouter.use(
isAuthorizedByRole(new Set(["Administrator", "Facilitator", "Learner"])),
);

const defaultBucket = process.env.FIREBASE_STORAGE_DEFAULT_BUCKET || "";
const fileStorageService: IFileStorageService = new FileStorageService(
Expand Down
2 changes: 1 addition & 1 deletion backend/rest/userRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { getErrorMessage } from "../utilities/errorUtils";
import { sendResponseByMimeType } from "../utilities/responseUtil";

const userRouter: Router = Router();
userRouter.use(isAuthorizedByRole(new Set(["Admin"])));
userRouter.use(isAuthorizedByRole(new Set(["Administrator"])));

const userService: IUserService = new UserService();
const emailService: IEmailService = new EmailService(nodemailerConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const testUsers = [
firstName: "Peter",
lastName: "Pan",
authId: "123",
role: "Admin",
role: "Administrator",
},
{
firstName: "Wendy",
lastName: "Darling",
authId: "321",
role: "User",
role: "Facilitator",
},
];

Expand Down
2 changes: 1 addition & 1 deletion backend/services/implementations/authService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AuthService implements IAuthService {
firstName: googleUser.firstName,
lastName: googleUser.lastName,
email: googleUser.email,
role: "User",
role: "Facilitator",
password: "",
},
googleUser.localId,
Expand Down
4 changes: 2 additions & 2 deletions backend/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ paths:
type: string
role:
type: string
enum: ["User", "Admin"]
enum: ["Administrator", "Facilitator", "Learner"]
email:
type: string
responses:
Expand Down Expand Up @@ -571,7 +571,7 @@ paths:
type: string
role:
type: string
enum: ["User", "Admin"]
enum: ["Administrator", "Facilitator", "Learner"]
email:
type: string
responses:
Expand Down
2 changes: 1 addition & 1 deletion backend/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Role = "User" | "Admin";
export type Role = "Administrator" | "Facilitator" | "Learner";

export type Token = {
accessToken: string;
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def signup_user(backend_url, body, access_token_field):
assert response.status_code == 200
data = response.json()
assert "role" in data
assert data["role"] == "User"
assert data["role"] == "Facilitator"
assert "id" in data
assert access_token_field in data
expected = {k: v for k, v in body.items() if k != "password"}
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/test_auth_gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def signup_user(backend_url, body, access_token_field):
assert "signup" in response.json()["data"]
data = response.json()["data"]["signup"]
assert "role" in data
assert data["role"] == "User"
assert data["role"] == "Facilitator"
assert "id" in data
assert access_token_field in data
expected = {k: v for k, v in body.items() if k != "password"}
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ def test_users(backend_url, auth_header, lang, api, new_user_email):
body1 = {
"firstName": "Test",
"lastName": "Script",
"role": "User",
"role": "Facilitator",
"email": new_user_email,
"password": "password",
}
body2 = {
"firstName": "Test2",
"lastName": "Script2",
"role": "User",
"role": "Facilitator",
"email": new_user_email,
}
if lang != "ts":
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/test_user_gql.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ def test_users_gql(backend_url, auth_header, lang, api, new_user_email):
body1 = {
"firstName": "Test",
"lastName": "Script",
"role": "User",
"role": "Facilitator",
"email": new_user_email,
"password": "password",
}
body2 = {
"firstName": "Test2",
"lastName": "Script2",
"role": "User",
"role": "Facilitator",
"email": new_user_email,
}
if lang != "ts":
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types/AuthTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type AuthenticatedUser = {
firstName: string;
lastName: string;
email: string;
role: "Admin" | "User";
role: "Administrator" | "Facilitator" | "Learner";
accessToken: string;
} | null;

Expand Down
Loading