From 794ed0453ecfeee7c43852aae2934a0f71343847 Mon Sep 17 00:00:00 2001 From: SeongHo Park Date: Fri, 5 Jul 2024 14:48:01 +0700 Subject: [PATCH 1/2] add logic for demoting admin to user --- backend/LexBoxApi/GraphQL/UserMutations.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backend/LexBoxApi/GraphQL/UserMutations.cs b/backend/LexBoxApi/GraphQL/UserMutations.cs index 230b9021a..bcf7a7ce0 100644 --- a/backend/LexBoxApi/GraphQL/UserMutations.cs +++ b/backend/LexBoxApi/GraphQL/UserMutations.cs @@ -141,6 +141,7 @@ IEmailService emailService } bool wasPromotedToAdmin = false; + bool wasDemotedToUser = false; if (input is ChangeUserAccountByAdminInput adminInput) { permissionService.AssertIsAdmin(); @@ -154,6 +155,11 @@ IEmailService emailService } wasPromotedToAdmin = user.IsAdmin = true; } + if (user.IsAdmin && adminInput.Role == UserRole.user) + { + user.IsAdmin = false; + wasDemotedToUser = true; + } } } else if (input is ChangeUserAccountBySelfInput selfInput) @@ -181,6 +187,12 @@ IEmailService emailService await emailService.SendNewAdminEmail(admins, user.Name, user.Email); } + //TODO: Should we send an email when admin gets demoted to user status? + // if (wasDemotedToUser) + // { + // await emailService.SendDemotedToUserEmail(user); + // } + return user; } From 65d017706879a9ee56ec85ddda64bebb4a1efae6 Mon Sep 17 00:00:00 2001 From: SeongHo Park Date: Mon, 8 Jul 2024 15:56:08 +0700 Subject: [PATCH 2/2] delete comment about email --- backend/LexBoxApi/GraphQL/UserMutations.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/backend/LexBoxApi/GraphQL/UserMutations.cs b/backend/LexBoxApi/GraphQL/UserMutations.cs index bcf7a7ce0..8773f3d2a 100644 --- a/backend/LexBoxApi/GraphQL/UserMutations.cs +++ b/backend/LexBoxApi/GraphQL/UserMutations.cs @@ -141,7 +141,6 @@ IEmailService emailService } bool wasPromotedToAdmin = false; - bool wasDemotedToUser = false; if (input is ChangeUserAccountByAdminInput adminInput) { permissionService.AssertIsAdmin(); @@ -158,7 +157,6 @@ IEmailService emailService if (user.IsAdmin && adminInput.Role == UserRole.user) { user.IsAdmin = false; - wasDemotedToUser = true; } } } @@ -186,13 +184,6 @@ IEmailService emailService ArgumentException.ThrowIfNullOrEmpty(user.Email); await emailService.SendNewAdminEmail(admins, user.Name, user.Email); } - - //TODO: Should we send an email when admin gets demoted to user status? - // if (wasDemotedToUser) - // { - // await emailService.SendDemotedToUserEmail(user); - // } - return user; }