Skip to content

Commit 1784b01

Browse files
check role on update
1 parent ee233e2 commit 1784b01

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

exercise.wwwapi/Endpoints/UserEndpoints.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ private static async Task<IResult> UpdateUser(IRepository<User> repository, Clai
193193
var user = repository.GetById(id);
194194

195195
if (user == null) return TypedResults.NotFound(new ResponseDTO<string> { Message = "User not found" });
196+
197+
if (user.Id != claims.UserRealId() && claims.Role() == (int)Roles.student)
198+
{
199+
var forbiddenResponse = new ResponseDTO<object>
200+
{
201+
Message = "You are not authorized to edit this post."
202+
};
203+
return TypedResults.Json(forbiddenResponse, statusCode: StatusCodes.Status403Forbidden);
204+
}
196205

197206
if (userPatch.Username != null && userPatch.Username != user.Username)
198207
{

0 commit comments

Comments
 (0)