From 024de153de7aa73a5ef318b55c2d173f7a8cb048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Fri, 9 Jun 2017 15:04:02 +0200 Subject: [PATCH] Version 16.237 --- swad_attendance.c | 22 ++++++++-------- swad_changelog.h | 4 ++- swad_enrolment.c | 48 +++++++++++------------------------ swad_file_browser.c | 6 ++--- swad_group.c | 4 +-- swad_photo.c | 4 +-- swad_profile.c | 4 +-- swad_record.c | 30 ++++++---------------- swad_role.c | 4 +-- swad_test.c | 6 ++--- swad_user.c | 61 +++++++++++++++++++++++++++++++++++++++------ swad_user.h | 1 + swad_web_service.c | 4 +-- swad_zip.c | 4 +-- 14 files changed, 102 insertions(+), 100 deletions(-) diff --git a/swad_attendance.c b/swad_attendance.c index 754b705f8..bace77a85 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -3223,12 +3223,11 @@ static void Att_ListStdsAttendanceTable (Att_TypeOfView_t TypeOfView, { UsrDat.UsrCod = LstSelectedUsrCods[NumStd]; if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // Get from the database the data of the student - { - UsrDat.Accepted = Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - true); - Att_WriteRowStdSeveralAttEvents (NumStd,&UsrDat); - } + if (Usr_CheckIfICanViewWrkTstAtt (&UsrDat)) + { + UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&UsrDat); + Att_WriteRowStdSeveralAttEvents (NumStd,&UsrDat); + } } /***** Last row with the total of students present in each event *****/ @@ -3437,12 +3436,11 @@ static void Att_ListStdsWithAttEventsDetails (Att_TypeOfView_t TypeOfView, { UsrDat.UsrCod = LstSelectedUsrCods[NumStd]; if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // Get from the database the data of the student - { - UsrDat.Accepted = Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - true); - Att_ListAttEventsForAStd (NumStd,&UsrDat); - } + if (Usr_CheckIfICanViewWrkTstAtt (&UsrDat)) + { + UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&UsrDat); + Att_ListAttEventsForAStd (NumStd,&UsrDat); + } } /***** End frame *****/ diff --git a/swad_changelog.h b/swad_changelog.h index 178298163..67075ad9a 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -242,13 +242,15 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.236 (2017-06-08)" +#define Log_PLATFORM_VERSION "SWAD 16.237 (2017-06-09)" #define CSS_FILE "swad16.235.1.css" #define JS_FILE "swad16.206.3.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1 /* + Version 16.237: Jun 09, 2017 Code refactoring related to users belonging to a course. + Changes in permissions to access students by non-editing teachers. (221303 lines) Version 16.236: Jun 08, 2017 Changes in permissions related to record card contextual commands. Code refactoring related to roles. (221306 lines) Version 16.235.3: Jun 04, 2017 Non-editing teachers can not select/unselect groups to which they don't belong. (221107 lines) diff --git a/swad_enrolment.c b/swad_enrolment.c index 1f7e24d99..df24fb7ef 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -963,9 +963,7 @@ bool Enr_PutActionsRegRemOneUsr (bool ItsMe) /***** Check if the other user belongs to the current course *****/ if (Gbl.CurrentCrs.Crs.CrsCod > 0) - UsrBelongsToCrs = Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - false); + UsrBelongsToCrs = Usr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat); if (Gbl.CurrentIns.Ins.InsCod > 0) { @@ -1806,15 +1804,13 @@ static void Enr_RegisterUsr (struct UsrData *UsrDat,Rol_Role_t RegRemRole, /***** Register user in current course in database *****/ if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected { - if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - false)) // User does belong to current course + if (Usr_CheckIfUsrBelongsToCurrentCrs (UsrDat)) { if (RegRemRole != UsrDat->Roles.InCurrentCrs.Role) // The role must be updated /* Modify role */ Enr_ModifyRoleInCurrentCrs (UsrDat,RegRemRole); } - else + else // User does not belong to this course /* Register user */ Enr_RegisterUsrInCurrentCrs (UsrDat,RegRemRole, Enr_SET_ACCEPTED_TO_FALSE); @@ -2130,9 +2126,7 @@ void Enr_AskIfRejectSignUp (void) if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) // If user's data exist... { - if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - false)) + if (Usr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat)) { /* User already belongs to this course */ sprintf (Gbl.Alert.Txt,Txt_THE_USER_X_is_already_enroled_in_the_course_Y, @@ -2189,9 +2183,7 @@ void Enr_RejectSignUp (void) if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) // If user's data exist... { - if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - false)) + if (Usr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat)) { /* User already belongs to this course */ sprintf (Gbl.Alert.Txt,Txt_THE_USER_X_is_already_enroled_in_the_course_Y, @@ -3251,13 +3243,9 @@ static void Enr_AskIfRegRemUsr (struct ListUsrCods *ListUsrCods,Rol_Role_t Role) if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected { /* Check if this user belongs to the current course */ - if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - false)) + if (Usr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat)) { - Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - true); + Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat); if (Gbl.Usrs.Other.UsrDat.Accepted) sprintf (Gbl.Alert.Txt,Txt_THE_USER_X_is_already_enroled_in_the_course_Y, Gbl.Usrs.Other.UsrDat.FullName,Gbl.CurrentCrs.Crs.FullName); @@ -3768,9 +3756,7 @@ void Enr_CreateNewUsr1 (void) /***** Register user in current course in database *****/ if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected { - if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - false)) // User does belong to current course + if (Usr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat)) { OldRole = Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs.Role; // Remember old role before changing it if (NewRole != OldRole) // The role must be updated @@ -3786,7 +3772,7 @@ void Enr_CreateNewUsr1 (void) Txt_ROLES_SINGUL_abc[NewRole][Gbl.Usrs.Other.UsrDat.Sex]); } } - else + else // User does not belong to current course { /* Register user */ Enr_RegisterUsrInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole, @@ -3893,9 +3879,7 @@ void Enr_ModifyUsr1 (void) NewRole = Rec_GetRoleFromRecordForm (); /***** Register user in current course in database *****/ - if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - false)) // User does belong to current course + if (Usr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Other.UsrDat)) { OldRole = Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs.Role; // Remember old role before changing it if (NewRole != OldRole) // The role must be updated @@ -3911,7 +3895,7 @@ void Enr_ModifyUsr1 (void) Txt_ROLES_SINGUL_abc[NewRole][Gbl.Usrs.Other.UsrDat.Sex]); } } - else + else // User does not belong to current course { /* Register user */ Enr_RegisterUsrInCurrentCrs (&Gbl.Usrs.Other.UsrDat,NewRole, @@ -4092,9 +4076,7 @@ static void Enr_AskIfRemoveUsrFromCrs (struct UsrData *UsrDat) bool ItsMe; Act_Action_t NextAction; - if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - false)) + if (Usr_CheckIfUsrBelongsToCurrentCrs (UsrDat)) { ItsMe = (Gbl.Usrs.Me.UsrDat.UsrCod == Gbl.Usrs.Other.UsrDat.UsrCod); @@ -4136,7 +4118,7 @@ static void Enr_AskIfRemoveUsrFromCrs (struct UsrData *UsrDat) /* End alert */ Ale_ShowAlertAndButton2 (ActUnk,NULL,NULL,NULL,Lay_NO_BUTTON,NULL); } - else + else // User does not belong to current course Ale_ShowAlert (Ale_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); } @@ -4152,9 +4134,7 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat,struct Course * char Query[1024]; bool ItsMe; - if (Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod, - Crs->CrsCod, - false)) // User belongs to the course + if (Usr_CheckIfUsrBelongsToCurrentCrs (UsrDat)) { /***** Remove user from all the attendance events in course *****/ Att_RemoveUsrFromCrsAttEvents (UsrDat->UsrCod,Crs->CrsCod); diff --git a/swad_file_browser.c b/swad_file_browser.c index 865bbfd30..b00fe6dd0 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -3225,9 +3225,7 @@ static void Brw_ShowFileBrowsersAsgWrkCrs (void) Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64); Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat); if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) // Get of the database the data of the user - if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - false)) + if (Usr_CheckIfICanViewWrkTstAtt (&Gbl.Usrs.Other.UsrDat)) { /***** Show a row with the data of the owner of the works *****/ fprintf (Gbl.F.Out,""); @@ -3246,7 +3244,7 @@ static void Brw_ShowFileBrowsersAsgWrkCrs (void) Brw_ShowFileBrowser (); fprintf (Gbl.F.Out,"" - ""); + ""); } } diff --git a/swad_group.c b/swad_group.c index 9b481aa3e..ad7f47fd9 100644 --- a/swad_group.c +++ b/swad_group.c @@ -4688,7 +4688,7 @@ void Grp_GetParamWhichGrps (void) bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat) { - char Query[256]; + char Query[512]; static struct { long UsrCod; @@ -4731,6 +4731,7 @@ bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat) /***** 8. Slow check: Get if user shares any group in this course with me from database *****/ /* Check if user shares any group with me */ + Cached.UsrCod = UsrDat->UsrCod; sprintf (Query,"SELECT COUNT(*) FROM crs_grp_usr" " WHERE UsrCod=%ld" " AND GrpCod IN" @@ -4746,6 +4747,5 @@ bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat) Cached.UsrSharesAnyOfMyGrpsInCurrentCrs = DB_QueryCOUNT (Query,"can not check" " if a user shares any group" " in the current course with you") != 0; - Cached.UsrCod = UsrDat->UsrCod; return Cached.UsrSharesAnyOfMyGrpsInCurrentCrs; } diff --git a/swad_photo.c b/swad_photo.c index 2586247cf..4ea4a6dca 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -390,9 +390,7 @@ void Pho_SendPhotoUsr (void) { if (Pho_ICanChangeOtherUsrPhoto (&Gbl.Usrs.Other.UsrDat)) // If I have permission to change user's photo... { - Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - true); + Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat); if (Gbl.Usrs.Other.UsrDat.UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // It's me /***** Form to send my photo *****/ Pho_ReqMyPhotoWithContextLinks (); diff --git a/swad_profile.c b/swad_profile.c index f96ec984d..ff26bbf67 100644 --- a/swad_profile.c +++ b/swad_profile.c @@ -287,9 +287,7 @@ bool Prf_ShowUserProfile (struct UsrData *UsrDat) UsrDat->Roles.InCurrentCrs.UsrCod = UsrDat->UsrCod; /* Get if user has accepted enrolment in current course */ - UsrDat->Accepted = Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - true); + UsrDat->Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (UsrDat); } Rec_ShowSharedUsrRecord (Rec_SHA_RECORD_PUBLIC,UsrDat,NULL); diff --git a/swad_record.c b/swad_record.c index 4628e9304..82049e35e 100644 --- a/swad_record.c +++ b/swad_record.c @@ -1098,9 +1098,7 @@ void Rec_GetUsrAndShowRecordOneStdCrs (void) static void Rec_ShowRecordOneStdCrs (void) { /***** Get if student has accepted enrolment in current course *****/ - Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - true); + Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat); /***** Assign users listing type depending on current action *****/ Gbl.Usrs.Listing.RecsUsrs = Rec_RECORD_USERS_STUDENTS; @@ -1236,15 +1234,11 @@ static void Rec_ListRecordsStds (Rec_SharedRecordViewType_t ShaTypeOfView, Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64); Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat); if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // Get from the database the data of the student - if (Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - false)) + if (Usr_CheckIfUsrBelongsToCurrentCrs (&UsrDat)) { /* Check if this user has accepted his/her inscription in the current course */ - UsrDat.Accepted = Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - true); + UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&UsrDat); /* Start container for this user */ sprintf (RecordSectionId,"record_%u",NumUsr); @@ -1326,9 +1320,7 @@ static void Rec_ShowRecordOneTchCrs (void) sprintf (Width,"%upx",Rec_RECORD_WIDTH); /***** Get if teacher has accepted enrolment in current course *****/ - Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - true); + Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat); /***** Assign users listing type depending on current action *****/ Gbl.Usrs.Listing.RecsUsrs = Rec_RECORD_USERS_TEACHERS; @@ -1459,15 +1451,11 @@ static void Rec_ListRecordsTchs (Rec_SharedRecordViewType_t TypeOfView) Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64); Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat); if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // Get from the database the data of the student - if (Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - false)) + if (Usr_CheckIfUsrBelongsToCurrentCrs (&UsrDat)) { /* Check if this user has accepted his/her inscription in the current course */ - UsrDat.Accepted = Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - true); + UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&UsrDat); /* Start container for this user */ sprintf (RecordSectionId,"record_%u",NumUsr); @@ -2168,9 +2156,7 @@ void Rec_ShowSharedRecordUnmodifiable (struct UsrData *UsrDat) { /***** Get password, user type and user's data from database *****/ Usr_GetAllUsrDataFromUsrCod (UsrDat); - UsrDat->Accepted = Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - true); + UsrDat->Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (UsrDat); /***** Show user's record *****/ fprintf (Gbl.F.Out,"
"); @@ -2332,7 +2318,7 @@ void Rec_ShowSharedUsrRecord (Rec_SharedRecordViewType_t TypeOfView, Rec_ShowPhoto (UsrDat); fprintf (Gbl.F.Out,""); - /***** Commands and full name *****/ + /***** Full name *****/ fprintf (Gbl.F.Out,""); Rec_ShowFullName (UsrDat); fprintf (Gbl.F.Out,""); diff --git a/swad_role.c b/swad_role.c index f0353d1cc..e440b391f 100644 --- a/swad_role.c +++ b/swad_role.c @@ -108,9 +108,7 @@ void Rol_SetMyRoles (void) { Gbl.Usrs.Me.IBelongToCurrentCrs = Usr_CheckIfUsrBelongsToCurrentCrs (&Gbl.Usrs.Me.UsrDat); if (Gbl.Usrs.Me.IBelongToCurrentCrs) - Gbl.Usrs.Me.UsrDat.Accepted = Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Me.UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - true); + Gbl.Usrs.Me.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Me.UsrDat); else Gbl.Usrs.Me.UsrDat.Accepted = false; } diff --git a/swad_test.c b/swad_test.c index 0988e3287..a9f3f4b13 100644 --- a/swad_test.c +++ b/swad_test.c @@ -7146,9 +7146,7 @@ void Tst_ShowUsrsTestResults (void) Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64); Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat); if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) // Get of the database the data of the user - if (Usr_CheckIfUsrBelongsToCrs (Gbl.Usrs.Other.UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - false)) + if (Usr_CheckIfICanViewWrkTstAtt (&Gbl.Usrs.Other.UsrDat)) /***** Show test results *****/ Tst_ShowTestResults (&Gbl.Usrs.Other.UsrDat); } @@ -7709,6 +7707,8 @@ void Tst_ShowOneTestResult (void) /* Get data of the user who made the test */ if (!Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) Lay_ShowErrorAndExit ("User does not exists."); + if (!Usr_CheckIfICanViewWrkTstAtt (&Gbl.Usrs.Other.UsrDat)) + Lay_ShowErrorAndExit ("You can not view this test result."); /* User */ fprintf (Gbl.F.Out,"" diff --git a/swad_user.c b/swad_user.c index 47514bc97..7688a8bd4 100644 --- a/swad_user.c +++ b/swad_user.c @@ -1131,7 +1131,7 @@ bool Usr_CheckIfICanViewWrkTstAtt (const struct UsrData *UsrDat) switch (Gbl.Usrs.Me.Role.Logged) { case Rol_NET: - return Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (Gbl.Record.UsrDat); + return Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (UsrDat); case Rol_TCH: case Rol_SYS_ADM: return true; @@ -1765,7 +1765,8 @@ bool Usr_CheckIfUsrBelongsToDeg (long UsrCod,long DegCod) } /*****************************************************************************/ -/*************** Check if user belongs to the current course *****************/ +/***** Check if user belongs (no matter if he/she has accepted or not) *******/ +/***** to the current course *******/ /*****************************************************************************/ bool Usr_CheckIfUsrBelongsToCurrentCrs (const struct UsrData *UsrDat) @@ -1795,13 +1796,59 @@ bool Usr_CheckIfUsrBelongsToCurrentCrs (const struct UsrData *UsrDat) /***** 3. Fast check: If we know role of user in the current course *****/ if (UsrDat->Roles.InCurrentCrs.UsrCod == UsrDat->UsrCod) - return UsrDat->Roles.InCurrentCrs.Role == Rol_STD || - UsrDat->Roles.InCurrentCrs.Role == Rol_NET || - UsrDat->Roles.InCurrentCrs.Role == Rol_TCH; + { + Cached.UsrCod = UsrDat->UsrCod; + Cached.Belongs = UsrDat->Roles.InCurrentCrs.Role == Rol_STD || + UsrDat->Roles.InCurrentCrs.Role == Rol_NET || + UsrDat->Roles.InCurrentCrs.Role == Rol_TCH; + return Cached.Belongs; + } /***** 4. Fast / slow check: Get if user belongs to current course *****/ - return Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod,Gbl.CurrentCrs.Crs.CrsCod, - false); + Cached.UsrCod = UsrDat->UsrCod; + Cached.Belongs = Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod, + Gbl.CurrentCrs.Crs.CrsCod, + false); + return Cached.Belongs; + } + +/*****************************************************************************/ +/***** Check if user belongs (no matter if he/she has accepted or not) *******/ +/***** to the current course *******/ +/*****************************************************************************/ + +bool Usr_CheckIfUsrHasAcceptedInCurrentCrs (const struct UsrData *UsrDat) + { + static struct + { + long UsrCod; + bool Accepted; + } Cached = + { + -1L, + false + }; + + /***** 1. Fast check: trivial cases *****/ + if (UsrDat->UsrCod <= 0 || + Gbl.CurrentCrs.Crs.CrsCod <= 0) + { + Cached.UsrCod = -1L; + Cached.Accepted = false; + return Cached.Accepted; + } + + /***** 2. Fast check: If cached... *****/ + if (UsrDat->UsrCod == Cached.UsrCod) + return Cached.Accepted; + + /***** 3. Fast / slow check: Get if user belongs to current course + and has accepted *****/ + Cached.UsrCod = UsrDat->UsrCod; + Cached.Accepted = Usr_CheckIfUsrBelongsToCrs (UsrDat->UsrCod, + Gbl.CurrentCrs.Crs.CrsCod, + true); + return Cached.Accepted; } /*****************************************************************************/ diff --git a/swad_user.h b/swad_user.h index 54c2f9c5d..573a3e9e4 100644 --- a/swad_user.h +++ b/swad_user.h @@ -258,6 +258,7 @@ unsigned Usr_GetNumUsrsInCrssOfAUsr (long UsrCod,Rol_Role_t UsrRole, Rol_Role_t OthersRole); bool Usr_CheckIfUsrBelongsToCurrentCrs (const struct UsrData *UsrDat); +bool Usr_CheckIfUsrHasAcceptedInCurrentCrs (const struct UsrData *UsrDat); bool Usr_CheckIfICanViewRecordStd (const struct UsrData *UsrDat); bool Usr_CheckIfICanViewRecordTch (struct UsrData *UsrDat); bool Usr_CheckIfICanViewWrkTstAtt (const struct UsrData *UsrDat); diff --git a/swad_web_service.c b/swad_web_service.c index c2c31a39d..174a628c6 100644 --- a/swad_web_service.c +++ b/swad_web_service.c @@ -2768,9 +2768,7 @@ int swad__sendAttendanceUsers (struct soap *soap, if (Usr_ChkIfUsrCodExists (UsrDat.UsrCod)) // The user must belong to course, // but it's not necessary he/she belongs to groups associated to the event - if (Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - false)) + if (Usr_CheckIfUsrBelongsToCurrentCrs (&UsrDat)) { /* Mark user as present */ Att_RegUsrInAttEventNotChangingComments (Att.AttCod,UsrDat.UsrCod); diff --git a/swad_zip.c b/swad_zip.c index 40b375ae7..3e8223e9f 100644 --- a/swad_zip.c +++ b/swad_zip.c @@ -184,9 +184,7 @@ void ZIP_CreateZIPAsgWrk (void) if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // Get user's data from database - if (Usr_CheckIfUsrBelongsToCrs (UsrDat.UsrCod, - Gbl.CurrentCrs.Crs.CrsCod, - false)) + if (Usr_CheckIfUsrBelongsToCurrentCrs (&UsrDat)) ZIP_CreateDirCompressionUsr (&UsrDat); }