From e3a4494721ed024ee3b4430150913b88b285c1cf Mon Sep 17 00:00:00 2001 From: acanas Date: Thu, 18 Nov 2021 22:06:06 +0100 Subject: [PATCH] Version 21.57.5: Nov 18, 2021 Code refactoring related to check if user logged is me. --- swad_API.c | 4 +--- swad_ID.c | 22 ++++++---------------- swad_agenda.c | 8 ++------ swad_changelog.h | 3 ++- swad_enrolment.c | 22 +++++++--------------- swad_exam_result.c | 5 +---- swad_follow.c | 10 +++------- swad_forum.c | 5 ++--- swad_group.c | 9 ++------- swad_mail.c | 11 ++++------- swad_match_result.c | 9 +++------ swad_photo.c | 13 +++++-------- swad_privacy.c | 4 +--- swad_profile.c | 4 ++-- swad_project.c | 7 ++----- swad_record.c | 15 +++------------ swad_string.c | 6 +----- swad_test_print.c | 3 +-- swad_user.c | 38 ++++++++++---------------------------- 19 files changed, 58 insertions(+), 140 deletions(-) diff --git a/swad_API.c b/swad_API.c index e2d65136..e3a9e5c8 100644 --- a/swad_API.c +++ b/swad_API.c @@ -3199,7 +3199,6 @@ int swad__sendMessage (struct soap *soap, MYSQL_ROW row; unsigned NumUsrs; unsigned NumUsr; - bool ItsMe; bool NotifyByEmail; /***** Initializations *****/ @@ -3268,8 +3267,7 @@ int swad__sendMessage (struct soap *soap, Usr_DONT_GET_ROLE_IN_CURRENT_CRS)) { /* This received message must be notified by email? */ - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); - NotifyByEmail = (!ItsMe && + NotifyByEmail = (!Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod) && (Gbl.Usrs.Other.UsrDat.NtfEvents.SendEmail & (1 << Ntf_EVENT_MESSAGE))); /* Send message to this user */ diff --git a/swad_ID.c b/swad_ID.c index 3f846675..4b9fc3fb 100644 --- a/swad_ID.c +++ b/swad_ID.c @@ -341,9 +341,7 @@ void ID_WriteUsrIDs (struct UsrData *UsrDat,const char *Anchor) bool ID_ICanSeeOtherUsrIDs (const struct UsrData *UsrDat) { - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); - - if (ItsMe) + if (Usr_ItsMe (UsrDat->UsrCod)) return true; /***** Check if I have permission to see another user's IDs *****/ @@ -677,16 +675,14 @@ void ID_RemoveMyUsrID (void) void ID_RemoveOtherUsrID (void) { - bool ItsMe; - /***** Get other user's code from form and get user's data *****/ if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) { if (Usr_ICanEditOtherUsr (&Gbl.Usrs.Other.UsrDat)) { /***** Remove user's ID *****/ - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); - ID_RemoveUsrID (&Gbl.Usrs.Other.UsrDat,ItsMe); + ID_RemoveUsrID (&Gbl.Usrs.Other.UsrDat, + Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)); /***** Update list of IDs *****/ ID_GetListIDsFromUsrCod (&Gbl.Usrs.Other.UsrDat); @@ -769,16 +765,14 @@ void ID_NewMyUsrID (void) void ID_NewOtherUsrID (void) { - bool ItsMe; - /***** Get other user's code from form and get user's data *****/ if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) { if (Usr_ICanEditOtherUsr (&Gbl.Usrs.Other.UsrDat)) { /***** New user's ID *****/ - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); - ID_NewUsrID (&Gbl.Usrs.Other.UsrDat,ItsMe); + ID_NewUsrID (&Gbl.Usrs.Other.UsrDat, + Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)); /***** Update list of IDs *****/ ID_GetListIDsFromUsrCod (&Gbl.Usrs.Other.UsrDat); @@ -881,7 +875,6 @@ void ID_ConfirmOtherUsrID (void) long OriginalActCod; char UsrID[ID_MAX_BYTES_USR_ID + 1]; bool ICanConfirm; - bool ItsMe; bool Found; unsigned NumID; unsigned NumIDFound = 0; // Initialized to avoid warning @@ -893,9 +886,7 @@ void ID_ConfirmOtherUsrID (void) /***** Get other user's code from form and get user's data *****/ ICanConfirm = false; if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) - { - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); - if (!ItsMe) // Not me + if (!Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) // Not me { /* If user is a student in current course, check if he/she has accepted */ @@ -906,7 +897,6 @@ void ID_ConfirmOtherUsrID (void) if (ID_ICanSeeOtherUsrIDs (&Gbl.Usrs.Other.UsrDat)) ICanConfirm = true; } - } if (ICanConfirm) { diff --git a/swad_agenda.c b/swad_agenda.c index 26a0bb99..8376e077 100644 --- a/swad_agenda.c +++ b/swad_agenda.c @@ -372,7 +372,6 @@ void Agd_ShowUsrAgenda (void) extern const char *Hlp_PROFILE_Agenda_public_agenda; extern const char *Txt_Public_agenda_USER; struct Agd_Agenda Agenda; - bool ItsMe; bool Error = true; /***** Get user *****/ @@ -385,8 +384,7 @@ void Agd_ShowUsrAgenda (void) Agd_ResetAgenda (&Agenda); /***** Begin box *****/ - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); - if (ItsMe) + if (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) Box_BoxBegin ("100%",Str_BuildStringStr (Txt_Public_agenda_USER, Gbl.Usrs.Me.UsrDat.FullName), Agd_PutIconsMyPublicAgenda,Gbl.Usrs.Me.UsrDat.EnUsrCod, @@ -423,7 +421,6 @@ void Agd_ShowOtherAgendaAfterLogIn (void) extern const char *Txt_Public_agenda_USER; extern const char *Txt_Switching_to_LANGUAGE[1 + Lan_NUM_LANGUAGES]; struct Agd_Agenda Agenda; - bool ItsMe; if (Gbl.Usrs.Me.Logged) { @@ -439,8 +436,7 @@ void Agd_ShowOtherAgendaAfterLogIn (void) Agd_ResetAgenda (&Agenda); /***** Begin box *****/ - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); - if (ItsMe) + if (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) Box_BoxBegin ("100%",Str_BuildStringStr (Txt_Public_agenda_USER, Gbl.Usrs.Me.UsrDat.FullName), Agd_PutIconToViewEditMyFullAgenda,Gbl.Usrs.Me.UsrDat.EnUsrCod, diff --git a/swad_changelog.h b/swad_changelog.h index f439425b..5f8b1200 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. */ -#define Log_PLATFORM_VERSION "SWAD 21.57.4 (2021-11-18)" +#define Log_PLATFORM_VERSION "SWAD 21.57.5 (2021-11-18)" #define CSS_FILE "swad21.57.css" #define JS_FILE "swad21.57.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 21.57.5: Nov 18, 2021 Code refactoring related to check if user logged is me. (319174 lines) Version 21.57.4: Nov 17, 2021 Code refactoring in timeline. (319235 lines) Version 21.57.3: Nov 17, 2021 Code refactoring in timeline. (319225 lines) Version 21.57.2: Nov 14, 2021 Code refactoring in timeline. (319257 lines) diff --git a/swad_enrolment.c b/swad_enrolment.c index 745c9215..e5c35538 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -297,7 +297,6 @@ static void Enr_NotifyAfterEnrolment (const struct UsrData *UsrDat, }; bool CreateNotif; bool NotifyByEmail; - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); /***** Check if user's role is allowed *****/ if (!NotifyEvent[NewRole]) @@ -313,7 +312,7 @@ static void Enr_NotifyAfterEnrolment (const struct UsrData *UsrDat, /***** Create new notification ******/ CreateNotif = (UsrDat->NtfEvents.CreateNotif & (1 << NotifyEvent[NewRole])); - NotifyByEmail = CreateNotif && !ItsMe && + NotifyByEmail = CreateNotif && !Usr_ItsMe (UsrDat->UsrCod) && (UsrDat->NtfEvents.SendEmail & (1 << NotifyEvent[NewRole])); if (CreateNotif) Ntf_DB_StoreNotifyEventToUsr (NotifyEvent[NewRole],UsrDat->UsrCod,-1L, @@ -2676,25 +2675,22 @@ void Enr_RemUsrFromCrs2 (void) static bool Enr_CheckIfICanRemUsrFromCrs (void) { - bool ItsMe; - - /* Check if I can remove another user from current course */ switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: case Rol_NET: - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); - return ItsMe; // A student or non-editing teacher can remove herself/himself + // A student or non-editing teacher can remove herself/himself + return Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); case Rol_TCH: case Rol_DEG_ADM: case Rol_CTR_ADM: case Rol_INS_ADM: case Rol_SYS_ADM: - return true; // A teacher or administrator can remove anyone + // A teacher or administrator can remove anyone + return true; default: return false; } - return false; } /*****************************************************************************/ @@ -3086,7 +3082,6 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat, Cns_QuietOrVerbose_t QuietOrVerbose) { extern const char *Txt_THE_USER_X_has_been_removed_from_the_course_Y; - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); if (Enr_CheckIfUsrBelongsToCurrentCrs (UsrDat)) { @@ -3130,7 +3125,7 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat, Usr_FlushCachesUsr (); /***** If it's me, change my roles *****/ - if (ItsMe) + if (Usr_ItsMe (UsrDat->UsrCod)) { /* Now I don't belong to current course */ Gbl.Usrs.Me.IBelongToCurrentCrs = @@ -3383,8 +3378,6 @@ void Enr_FlushCacheUsrSharesAnyOfMyCrs (void) bool Enr_CheckIfUsrSharesAnyOfMyCrs (struct UsrData *UsrDat) { - bool ItsMe; - /***** 1. Fast check: Am I logged? *****/ if (!Gbl.Usrs.Me.Logged) return false; @@ -3394,8 +3387,7 @@ bool Enr_CheckIfUsrSharesAnyOfMyCrs (struct UsrData *UsrDat) return false; /***** 3. Fast check: It's me? *****/ - ItsMe = Usr_ItsMe (UsrDat->UsrCod); - if (ItsMe) + if (Usr_ItsMe (UsrDat->UsrCod)) return true; /***** 4. Fast check: Is already calculated if user shares any course with me? *****/ diff --git a/swad_exam_result.c b/swad_exam_result.c index 323cbfcb..21140412 100644 --- a/swad_exam_result.c +++ b/swad_exam_result.c @@ -1369,15 +1369,12 @@ static void ExaRes_CheckIfICanViewResult (const struct Exa_Exam *Exam, long UsrCod, struct ExaRes_ICanView *ICanView) { - bool ItsMe; - /***** Check if I can view print result and score *****/ switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: // Depends on visibility of exam, session and result (eye icons) - ItsMe = Usr_ItsMe (UsrCod); - ICanView->Result = (ItsMe && // The result is mine + ICanView->Result = (Usr_ItsMe (UsrCod) && // The result is mine !Exam->Hidden && // The exam is visible !Session->Hidden && // The session is visible Session->ShowUsrResults); // The results of the session are visible to users diff --git a/swad_follow.c b/swad_follow.c index 5db6efaf..e45bd6ca 100644 --- a/swad_follow.c +++ b/swad_follow.c @@ -319,7 +319,6 @@ void Fol_ShowFollowingAndFollowers (const struct UsrData *UsrDat, extern const char *Txt_Followers; extern const char *Txt_Following_unfollow; extern const char *Txt_Follow; - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); /***** Begin section *****/ HTM_SECTION_Begin (Fol_FOLLOW_SECTION_ID); @@ -355,7 +354,7 @@ void Fol_ShowFollowingAndFollowers (const struct UsrData *UsrDat, /* I follow user? */ HTM_DIV_Begin ("id=\"follow_usr\""); if (Gbl.Usrs.Me.Logged && // Logged - !ItsMe) // Not me! + !Usr_ItsMe (UsrDat->UsrCod)) // Not me! { Frm_BeginForm (IFollowUsr ? ActUnfUsr : ActFolUsr); @@ -614,7 +613,6 @@ static void Fol_ShowFollowedOrFollower (struct UsrData *UsrDat) { extern const char *Txt_Another_user_s_profile; bool Visible = Pri_ShowingIsAllowed (UsrDat->BaPrfVisibility,UsrDat); - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); /***** Show user's photo *****/ HTM_TD_Begin ("class=\"FOLLOW_PHOTO\""); @@ -638,9 +636,8 @@ static void Fol_ShowFollowedOrFollower (struct UsrData *UsrDat) Frm_EndForm (); } - ItsMe = Usr_ItsMe (UsrDat->UsrCod); if (!Gbl.Usrs.Me.Logged || // Not logged - ItsMe) // It's me + Usr_ItsMe (UsrDat->UsrCod)) // It's me /* Inactive icon to follow/unfollow */ Fol_PutInactiveIconToFollowUnfollow (); else // It's not me @@ -666,7 +663,6 @@ static void Fol_WriteRowUsrToFollowOnRightColumn (struct UsrData *UsrDat) { extern const char *Txt_Another_user_s_profile; bool Visible = Pri_ShowingIsAllowed (UsrDat->BaPrfVisibility,UsrDat); - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); /***** Show user's photo *****/ HTM_TR_Begin (NULL); @@ -696,7 +692,7 @@ static void Fol_WriteRowUsrToFollowOnRightColumn (struct UsrData *UsrDat) /***** Icon to follow *****/ HTM_TD_Begin ("class=\"CON_ICON_FOLLOW RM COLOR%u\"",Gbl.RowEvenOdd); if (!Gbl.Usrs.Me.Logged || // Not logged - ItsMe) // It's me + Usr_ItsMe (UsrDat->UsrCod)) // It's me /* Inactive icon to follow/unfollow */ Fol_PutInactiveIconToFollowUnfollow (); else // It's not me diff --git a/swad_forum.c b/swad_forum.c index acf03815..f3f23e13 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -2866,7 +2866,6 @@ void For_RemovePost (void) char Subject[Cns_MAX_BYTES_SUBJECT + 1]; char OriginalContent[Cns_MAX_BYTES_LONG_TEXT + 1]; struct Med_Media Media; - bool ItsMe; bool ThreadDeleted = false; /***** Reset forum *****/ @@ -2888,8 +2887,7 @@ void For_RemovePost (void) Err_WrongPostExit (); /* Check if I am the author of the message */ - ItsMe = Usr_ItsMe (UsrDat.UsrCod); - if (!ItsMe) + if (!Usr_ItsMe (UsrDat.UsrCod)) Err_NoPermissionExit (); /* Check if the message is the last message in the thread */ @@ -2927,6 +2925,7 @@ void For_RemovePost (void) { /***** Show threads again *****/ For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,NULL); + /***** Show the remaining posts *****/ For_ShowPostsOfAThread (&Forums,Ale_SUCCESS,Txt_FORUM_Post_removed); } diff --git a/swad_group.c b/swad_group.c index 42e3337f..ee3254ad 100644 --- a/swad_group.c +++ b/swad_group.c @@ -1211,14 +1211,12 @@ void Grp_RemUsrFromAllGrps (long UsrCod) static void Grp_RemoveUsrFromGroup (long UsrCod,long GrpCod) { - bool ItsMe = Usr_ItsMe (UsrCod); - /***** Remove user from group *****/ Grp_DB_RemoveUsrFromGrp (UsrCod,GrpCod); /***** Flush caches *****/ Grp_FlushCacheUsrSharesAnyOfMyGrpsInCurrentCrs (); - if (ItsMe) + if (Usr_ItsMe (UsrCod)) Grp_FlushCacheIBelongToGrp (); } @@ -3022,8 +3020,6 @@ void Grp_FlushCacheUsrSharesAnyOfMyGrpsInCurrentCrs (void) bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat) { - bool ItsMe; - /***** 1. Fast check: Am I logged? *****/ if (!Gbl.Usrs.Me.Logged) return false; @@ -3041,8 +3037,7 @@ bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat) return false; /***** 5. Fast check: It's me? *****/ - ItsMe = Usr_ItsMe (UsrDat->UsrCod); - if (ItsMe) + if (Usr_ItsMe (UsrDat->UsrCod)) return true; /***** 6. Fast check: Is already calculated if user shares diff --git a/swad_mail.c b/swad_mail.c index cda3eea2..ab8ede73 100644 --- a/swad_mail.c +++ b/swad_mail.c @@ -1308,16 +1308,14 @@ void May_NewMyUsrEmail (void) void Mai_NewOtherUsrEmail (void) { - bool ItsMe; - /***** Get other user's code from form and get user's data *****/ if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) { if (Usr_ICanEditOtherUsr (&Gbl.Usrs.Other.UsrDat)) { /***** New user's ID *****/ - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); - Mai_NewUsrEmail (&Gbl.Usrs.Other.UsrDat,ItsMe); + Mai_NewUsrEmail (&Gbl.Usrs.Other.UsrDat, + Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)); /***** Show form again *****/ Acc_ShowFormChgOtherUsrAccount (); @@ -1625,9 +1623,8 @@ void Mai_WriteFootNoteEMail (FILE *FileMail,Lan_Language_t Language) bool Mai_ICanSeeOtherUsrEmail (const struct UsrData *UsrDat) { - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); - - if (ItsMe) + /***** I can see my email *****/ + if (Usr_ItsMe (UsrDat->UsrCod)) return true; /***** Check if I have permission to see another user's email *****/ diff --git a/swad_match_result.c b/swad_match_result.c index 7687cc07..afbc5782 100644 --- a/swad_match_result.c +++ b/swad_match_result.c @@ -1260,17 +1260,14 @@ static void MchRes_CheckIfICanSeeMatchResult (const struct Gam_Game *Game, long UsrCod, struct MchRes_ICanView *ICanView) { - bool ItsMe; - /***** Check if I can view print result and score *****/ switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: // Depends on visibility of game and result (eye icons) - ItsMe = Usr_ItsMe (UsrCod); - ICanView->Result = (ItsMe && // The result is mine - !Game->Hidden && // The game is visible - Match->Status.ShowUsrResults); // The results of the match are visible to users + ICanView->Result = (!Game->Hidden && // The game is visible + Match->Status.ShowUsrResults && // The results of the match are visible to users + Usr_ItsMe (UsrCod)); // The result is mine // Whether I belong or not to groups of match is not checked here... // ...because I should be able to see old matches made in old groups to which I belonged diff --git a/swad_photo.c b/swad_photo.c index 81263ddc..9731019a 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -139,12 +139,11 @@ static void Pho_ComputePhotoSize (const struct Pho_DegPhotos *DegPhotos, bool Pho_ICanChangeOtherUsrPhoto (struct UsrData *UsrDat) { - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); - - if (ItsMe) + /***** I can change my photo *****/ + if (Usr_ItsMe (UsrDat->UsrCod)) return true; - /* Check if I have permission to change user's photo */ + /***** Check if I have permission to change user's photo *****/ switch (Gbl.Usrs.Me.Role.Logged) { case Rol_TCH: @@ -154,8 +153,7 @@ bool Pho_ICanChangeOtherUsrPhoto (struct UsrData *UsrDat) /* It's a student in this course, check if he/she has accepted registration */ - UsrDat->Accepted = Enr_CheckIfUsrHasAcceptedInCurrentCrs (UsrDat); - return UsrDat->Accepted; + return (UsrDat->Accepted = Enr_CheckIfUsrHasAcceptedInCurrentCrs (UsrDat)); case Rol_DEG_ADM: case Rol_CTR_ADM: case Rol_INS_ADM: @@ -190,10 +188,9 @@ void Pho_PutIconToChangeUsrPhoto (void) [Rol_INS_ADM] = ActReqOthPho, [Rol_SYS_ADM] = ActReqOthPho, }; - bool ItsMe = Usr_ItsMe (Gbl.Record.UsrDat->UsrCod); /***** Link for changing / uploading the photo *****/ - if (ItsMe) + if (Usr_ItsMe (Gbl.Record.UsrDat->UsrCod)) { TitleText = Gbl.Usrs.Me.MyPhotoExists ? Txt_Change_photo : Txt_Upload_photo; diff --git a/swad_privacy.c b/swad_privacy.c index cd7be2c4..68378656 100644 --- a/swad_privacy.c +++ b/swad_privacy.c @@ -241,10 +241,8 @@ Pri_Visibility_t Pri_GetParamVisibility (const char *ParamName, bool Pri_ShowingIsAllowed (Pri_Visibility_t Visibility,struct UsrData *UsrDat) { - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); - /***** I always can see my things *****/ - if (ItsMe) + if (Usr_ItsMe (UsrDat->UsrCod)) return true; /***** System admins always can see others' profiles *****/ diff --git a/swad_profile.c b/swad_profile.c index 913f383d..c8ec8dce 100644 --- a/swad_profile.c +++ b/swad_profile.c @@ -1190,7 +1190,7 @@ void Prf_ShowRankingFigure (MYSQL_RES **mysql_res,unsigned NumUsrs) Usr_GetAllUsrDataFromUsrCod (&UsrDat, Usr_DONT_GET_PREFS, Usr_DONT_GET_ROLE_IN_CURRENT_CRS); - ItsMe = (UsrDat.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod); + ItsMe = Usr_ItsMe (UsrDat.UsrCod); /* Get figure (row[1]) */ if (sscanf (row[1],"%ld",&Figure) != 1) @@ -1260,7 +1260,7 @@ void Prf_GetAndShowRankingClicksPerDay (void) Usr_GetAllUsrDataFromUsrCod (&UsrDat, Usr_DONT_GET_PREFS, Usr_DONT_GET_ROLE_IN_CURRENT_CRS); - ItsMe = (UsrDat.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod); + ItsMe = Usr_ItsMe (UsrDat.UsrCod); /* Get average number of clicks per day (row[1]) */ NumClicksPerDay = Str_GetDoubleFromStr (row[1]); diff --git a/swad_project.c b/swad_project.c index d9afbebd..c3f85793 100644 --- a/swad_project.c +++ b/swad_project.c @@ -2530,7 +2530,6 @@ static void Prj_ReqRemUsrFromPrj (struct Prj_Projects *Projects, [Prj_ROLE_EVL] = ActRemEvlPrj, // Evaluator }; struct Prj_Project Prj; - bool ItsMe; /***** Allocate memory for the project *****/ Prj_AllocMemProject (&Prj); @@ -2548,12 +2547,10 @@ static void Prj_ReqRemUsrFromPrj (struct Prj_Projects *Projects, { if (Prj_CheckIfICanEditProject (&Prj)) { - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); - /***** Show question and button to remove user as a role from project *****/ /* Begin alert */ - Ale_ShowAlertAndButton1 (Ale_QUESTION,ItsMe ? Txt_Do_you_really_want_to_be_removed_as_a_X_from_the_project_Y : - Txt_Do_you_really_want_to_remove_the_following_user_as_a_X_from_the_project_Y, + Ale_ShowAlertAndButton1 (Ale_QUESTION,Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod) ? Txt_Do_you_really_want_to_be_removed_as_a_X_from_the_project_Y : + Txt_Do_you_really_want_to_remove_the_following_user_as_a_X_from_the_project_Y, Txt_PROJECT_ROLES_SINGUL_abc[RoleInPrj][Gbl.Usrs.Other.UsrDat.Sex], Prj.Title); diff --git a/swad_record.c b/swad_record.c index 7082fee8..ca7161c1 100644 --- a/swad_record.c +++ b/swad_record.c @@ -968,8 +968,6 @@ void Rec_GetUsrAndShowRecOneStdCrs (void) static void Rec_ShowRecordOneStdCrs (void) { - bool ItsMe; - /***** Get if student has accepted enrolment in current course *****/ Gbl.Usrs.Other.UsrDat.Accepted = Enr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat); @@ -1013,8 +1011,7 @@ static void Rec_ShowRecordOneStdCrs (void) switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: - ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod); - if (ItsMe) + if (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) { HTM_DIV_Begin ("class=\"REC_RIGHT\""); Rec_ShowCrsRecord (Rec_CRS_MY_RECORD_AS_STUDENT_FORM,&Gbl.Usrs.Other.UsrDat,NULL); @@ -1065,7 +1062,6 @@ static void Rec_ListRecordsStds (Rec_SharedRecordViewType_t ShaTypeOfView, unsigned NumUsr = 0; const char *Ptr; struct UsrData UsrDat; - bool ItsMe; char RecordSectionId[32]; /***** Get list of selected users if not already got *****/ @@ -1140,19 +1136,16 @@ static void Rec_ListRecordsStds (Rec_SharedRecordViewType_t ShaTypeOfView, /* Record of the student in the course */ if (Gbl.Crs.Records.LstFields.Num) // There are fields in the record - { - ItsMe = Usr_ItsMe (UsrDat.UsrCod); if ( Gbl.Usrs.Me.Role.Logged == Rol_NET || Gbl.Usrs.Me.Role.Logged == Rol_TCH || Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM || (Gbl.Usrs.Me.Role.Logged == Rol_STD && // I am student in this course... - ItsMe)) // ...and it's me + Usr_ItsMe (UsrDat.UsrCod))) // ...and it's me { HTM_DIV_Begin ("class=\"REC_RIGHT\""); Rec_ShowCrsRecord (CrsTypeOfView,&UsrDat,RecordSectionId); HTM_DIV_End (); } - } /* End container for this user */ HTM_DIV_End (); @@ -1585,7 +1578,6 @@ static void Rec_ShowCrsRecord (Rec_CourseRecordViewType_t TypeOfView, [Rec_CRS_PRINT_SEVERAL_RECORDS ] = NULL, }; char StrRecordWidth[Cns_MAX_DECIMAL_DIGITS_UINT + 1]; - bool ItsMe; bool ICanEdit = false; unsigned NumField; MYSQL_RES *mysql_res; @@ -1598,8 +1590,7 @@ static void Rec_ShowCrsRecord (Rec_CourseRecordViewType_t TypeOfView, switch (Gbl.Usrs.Me.Role.Logged) { case Rol_STD: // I am a student - ItsMe = Usr_ItsMe (UsrDat->UsrCod); - if (ItsMe) + if (Usr_ItsMe (UsrDat->UsrCod)) { switch (TypeOfView) { diff --git a/swad_string.c b/swad_string.c index 30d4d53e..02b8a09f 100644 --- a/swad_string.c +++ b/swad_string.c @@ -692,7 +692,6 @@ void Str_AnalyzeTxtAndStoreNotifyEventToMentionedUsrs (long PubCod,const char *T size_t Length; // Length of the nickname } Nickname; struct UsrData UsrDat; - bool ItsMe; bool CreateNotif; bool NotifyByEmail; @@ -735,9 +734,7 @@ void Str_AnalyzeTxtAndStoreNotifyEventToMentionedUsrs (long PubCod,const char *T UsrDat.Nickname[Nickname.Length] = '\0'; if ((UsrDat.UsrCod = Nck_GetUsrCodFromNickname (UsrDat.Nickname)) > 0) - { - ItsMe = Usr_ItsMe (UsrDat.UsrCod); - if (!ItsMe) // Not me + if (!Usr_ItsMe (UsrDat.UsrCod)) // Not me { /* Get user's data */ Usr_GetAllUsrDataFromUsrCod (&UsrDat, @@ -758,7 +755,6 @@ void Str_AnalyzeTxtAndStoreNotifyEventToMentionedUsrs (long PubCod,const char *T Gbl.Hierarchy.Crs.CrsCod); } } - } } } /* The next char is not the start of a nickname */ diff --git a/swad_test_print.c b/swad_test_print.c index e2f1ffb5..be454953 100644 --- a/swad_test_print.c +++ b/swad_test_print.c @@ -1840,7 +1840,6 @@ static void TstPrn_ShowUsrPrints (struct UsrData *UsrDat) struct TstPrn_NumQuestions NumTotalQsts; double TotalScore; unsigned NumPrintsVisibleByTchs = 0; - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); struct TstRes_ICanView ICanView; char *ClassDat; @@ -1990,7 +1989,7 @@ static void TstPrn_ShowUsrPrints (struct UsrData *UsrDat) } /***** Write totals for this user *****/ - TstPrn_ShowPrintsSummaryRow (ItsMe,NumPrintsVisibleByTchs, + TstPrn_ShowPrintsSummaryRow (Usr_ItsMe (UsrDat->UsrCod),NumPrintsVisibleByTchs, &NumTotalQsts,TotalScore); } else diff --git a/swad_user.c b/swad_user.c index b3d67bcf..1c77f254 100644 --- a/swad_user.c +++ b/swad_user.c @@ -800,9 +800,8 @@ bool Usr_CheckIfUsrIsSuperuser (long UsrCod) bool Usr_ICanChangeOtherUsrData (const struct UsrData *UsrDat) { - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); - - if (ItsMe) + /***** I can change my data *****/ + if (Usr_ItsMe (UsrDat->UsrCod)) return true; /***** Check if I have permission to see another user's IDs *****/ @@ -834,9 +833,8 @@ bool Usr_ICanChangeOtherUsrData (const struct UsrData *UsrDat) bool Usr_ICanEditOtherUsr (const struct UsrData *UsrDat) { - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); - - if (ItsMe) + /***** I can edit me *****/ + if (Usr_ItsMe (UsrDat->UsrCod)) return true; switch (Gbl.Usrs.Me.Role.Logged) @@ -878,8 +876,6 @@ bool Usr_ICanEditOtherUsr (const struct UsrData *UsrDat) bool Usr_CheckIfICanViewRecordStd (const struct UsrData *UsrDat) { - bool ItsMe; - /***** 1. Fast check: Am I logged? *****/ if (!Gbl.Usrs.Me.Logged) return false; @@ -905,8 +901,7 @@ bool Usr_CheckIfICanViewRecordStd (const struct UsrData *UsrDat) return false; /***** 7. Fast check: It's me? *****/ - ItsMe = Usr_ItsMe (UsrDat->UsrCod); - if (ItsMe) + if (Usr_ItsMe (UsrDat->UsrCod)) return true; /***** 8. Fast / slow check: Does he/she belong to the current course? *****/ @@ -958,8 +953,6 @@ bool Usr_CheckIfICanViewRecordTch (struct UsrData *UsrDat) bool Usr_CheckIfICanViewTstExaMchResult (const struct UsrData *UsrDat) { - bool ItsMe; - /***** 1. Fast check: Am I logged? *****/ if (!Gbl.Usrs.Me.Logged) return false; @@ -981,8 +974,7 @@ bool Usr_CheckIfICanViewTstExaMchResult (const struct UsrData *UsrDat) return false; /***** 6. Fast check: It's me? *****/ - ItsMe = Usr_ItsMe (UsrDat->UsrCod); - if (ItsMe) + if (Usr_ItsMe (UsrDat->UsrCod)) return true; /***** 7. Fast check: Does he/she belong to the current course? *****/ @@ -1007,8 +999,6 @@ bool Usr_CheckIfICanViewTstExaMchResult (const struct UsrData *UsrDat) bool Usr_CheckIfICanViewAsgWrk (const struct UsrData *UsrDat) { - bool ItsMe; - /***** 1. Fast check: Am I logged? *****/ if (!Gbl.Usrs.Me.Logged) return false; @@ -1035,8 +1025,7 @@ bool Usr_CheckIfICanViewAsgWrk (const struct UsrData *UsrDat) return false; /***** 7. Fast check: It's me? *****/ - ItsMe = Usr_ItsMe (UsrDat->UsrCod); - if (ItsMe) + if (Usr_ItsMe (UsrDat->UsrCod)) return true; /***** 8. Fast / slow check depending on roles *****/ @@ -1057,8 +1046,6 @@ bool Usr_CheckIfICanViewAsgWrk (const struct UsrData *UsrDat) bool Usr_CheckIfICanViewAtt (const struct UsrData *UsrDat) { - bool ItsMe; - /***** 1. Fast check: Am I logged? *****/ if (!Gbl.Usrs.Me.Logged) return false; @@ -1080,8 +1067,7 @@ bool Usr_CheckIfICanViewAtt (const struct UsrData *UsrDat) return false; /***** 6. Fast check: It's me? *****/ - ItsMe = Usr_ItsMe (UsrDat->UsrCod); - if (ItsMe) + if (Usr_ItsMe (UsrDat->UsrCod)) return true; /***** 7. Fast / slow check depending on roles *****/ @@ -1102,15 +1088,12 @@ bool Usr_CheckIfICanViewAtt (const struct UsrData *UsrDat) bool Usr_CheckIfICanViewUsrAgenda (struct UsrData *UsrDat) { - bool ItsMe; - /***** 1. Fast check: Am I logged? *****/ if (!Gbl.Usrs.Me.Logged) return false; /***** 2. Fast check: It's me? *****/ - ItsMe = Usr_ItsMe (UsrDat->UsrCod); - if (ItsMe) + if (Usr_ItsMe (UsrDat->UsrCod)) return true; /***** 3. Fast check: Am I logged as system admin? *****/ @@ -2460,8 +2443,7 @@ static void Usr_WriteRowTchAllData (struct UsrData *UsrDat) struct Ins_Instit Ins; struct Ctr_Center Ctr; struct Dpt_Department Dpt; - bool ItsMe = Usr_ItsMe (UsrDat->UsrCod); - bool ShowData = (ItsMe || UsrDat->Accepted || + bool ShowData = (Usr_ItsMe (UsrDat->UsrCod) || UsrDat->Accepted || Gbl.Usrs.Me.Role.Logged == Rol_DEG_ADM || Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM);