From 41c571cbda4d05b1335d922db16168bd6e0017c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Thu, 5 Oct 2017 22:29:33 +0200 Subject: [PATCH] Version 17.17.5 --- swad_attendance.c | 4 +- swad_changelog.h | 3 +- swad_file_browser.c | 2 +- swad_record.c | 66 +++++++++++++++--------------- swad_test.c | 6 +-- swad_user.c | 97 ++++++++++++++++++++++++++++++++++++++++++++- swad_user.h | 4 +- 7 files changed, 141 insertions(+), 41 deletions(-) diff --git a/swad_attendance.c b/swad_attendance.c index 34da1c59a..964804081 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -3235,7 +3235,7 @@ 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 - if (Usr_CheckIfICanViewWrkTstAtt (&UsrDat)) + if (Usr_CheckIfICanViewAtt (&UsrDat)) { UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&UsrDat); Att_WriteRowStdSeveralAttEvents (NumStd,&UsrDat); @@ -3448,7 +3448,7 @@ 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 - if (Usr_CheckIfICanViewWrkTstAtt (&UsrDat)) + if (Usr_CheckIfICanViewAtt (&UsrDat)) { UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&UsrDat); Att_ListAttEventsForAStd (NumStd,&UsrDat); diff --git a/swad_changelog.h b/swad_changelog.h index deae7ea73..493e9bd95 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -254,13 +254,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 17.17.4 (2017-10-05)" +#define Log_PLATFORM_VERSION "SWAD 17.17.5 (2017-10-05)" #define CSS_FILE "swad17.0.css" #define JS_FILE "swad17.17.1.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 17.17.5: Oct 05, 2017 Fixed bug in contextual icons in records. (232467 lines) Version 17.17.4: Oct 05, 2017 Department is filled automatically with user's department when creating a new project. (232385 lines) Version 17.17.3: Oct 04, 2017 Fixed problems with icons when expanding / contracting a folder. (232383 lines) Version 17.17.2: Oct 04, 2017 Changes related with output with status 204 No Content. (232332 lines) diff --git a/swad_file_browser.c b/swad_file_browser.c index 5239cec48..bcc480b93 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -3257,7 +3257,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_CheckIfICanViewWrkTstAtt (&Gbl.Usrs.Other.UsrDat)) + if (Usr_CheckIfICanViewAsgWrk (&Gbl.Usrs.Other.UsrDat)) { /***** Show a row with the data of the owner of the works *****/ fprintf (Gbl.F.Out,""); diff --git a/swad_record.c b/swad_record.c index 3bc2c6cc0..55e742d81 100644 --- a/swad_record.c +++ b/swad_record.c @@ -2634,49 +2634,53 @@ static void Rec_PutIconsCommands (void) if (Gbl.CurrentCrs.Crs.CrsCod > 0) // A course is selected { - if (Usr_CheckIfICanViewWrkTstAtt (Gbl.Record.UsrDat)) - { - /***** Button to view user's assignments and works *****/ - if (ItsMe) // I am a student - Lay_PutContextualLink (ActAdmAsgWrkUsr,NULL,NULL, - "folder64x64.gif", - Txt_View_homework,NULL, - NULL); - else // I am a teacher or superuser - Lay_PutContextualLink (ActAdmAsgWrkCrs,NULL,Rec_PutParamsWorks, - "folder64x64.gif", - Txt_View_homework,NULL, - NULL); - - /***** Button to view user's test exams *****/ - if (ItsMe) - Lay_PutContextualLink (ActSeeMyTstRes,NULL,NULL, - "exam64x64.png", - Txt_View_test_results,NULL, - NULL); - else - Lay_PutContextualLink (ActSeeUsrTstRes,NULL,Rec_PutParamsStudent, - "exam64x64.png", - Txt_View_test_results,NULL, - NULL); - - /***** Button to view user's attendance *****/ - if (Gbl.Record.UsrDat->Roles.InCurrentCrs.Role == Rol_STD) + if (Gbl.Record.UsrDat->Roles.InCurrentCrs.Role == Rol_STD) // He/she is a student in current course + { + /***** Button to view student's test exams *****/ + if (Usr_CheckIfICanViewTst (Gbl.Record.UsrDat)) + { + if (ItsMe) + Lay_PutContextualLink (ActSeeMyTstRes,NULL,NULL, + "exam64x64.png", + Txt_View_test_results,NULL, + NULL); + else + Lay_PutContextualLink (ActSeeUsrTstRes,NULL,Rec_PutParamsStudent, + "exam64x64.png", + Txt_View_test_results,NULL, + NULL); + } + + /***** Button to view student's assignments and works *****/ + if (Usr_CheckIfICanViewAsgWrk (Gbl.Record.UsrDat)) + { + if (ItsMe) + Lay_PutContextualLink (ActAdmAsgWrkUsr,NULL,NULL, + "folder64x64.gif", + Txt_View_homework,NULL, + NULL); + else // I am not a student in current course + Lay_PutContextualLink (ActAdmAsgWrkCrs,NULL,Rec_PutParamsWorks, + "folder64x64.gif", + Txt_View_homework,NULL, + NULL); + } + + /***** Button to view student's attendance *****/ + if (Usr_CheckIfICanViewAtt (Gbl.Record.UsrDat)) { if (ItsMe) - // As student, I can see my attendance Lay_PutContextualLink (ActSeeLstMyAtt,NULL,NULL, "rollcall64x64.png", Txt_View_attendance,NULL, NULL); else - // I can see attendance of the student Lay_PutContextualLink (ActSeeLstStdAtt,NULL,Rec_PutParamsStudent, "rollcall64x64.png", Txt_View_attendance,NULL, NULL); } - } + } /***** Button to print QR code *****/ Lay_PutContextualLink (ActPrnUsrQR,NULL,Rec_PutParamUsrCodEncrypted, diff --git a/swad_test.c b/swad_test.c index 2098fcfec..e8305b5c3 100644 --- a/swad_test.c +++ b/swad_test.c @@ -7578,7 +7578,7 @@ void Tst_ShowUsrsTestResults (void) /***** Header of the table with the list of users *****/ Tst_ShowHeaderTestResults (); - /***** List the assignments and works of the selected users *****/ + /***** List the test exams of the selected users *****/ Ptr = Gbl.Usrs.Select[Rol_UNK]; while (*Ptr) { @@ -7586,7 +7586,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_CheckIfICanViewWrkTstAtt (&Gbl.Usrs.Other.UsrDat)) + if (Usr_CheckIfICanViewTst (&Gbl.Usrs.Other.UsrDat)) /***** Show test results *****/ Tst_ShowTestResults (&Gbl.Usrs.Other.UsrDat); } @@ -8149,7 +8149,7 @@ 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)) + if (!Usr_CheckIfICanViewTst (&Gbl.Usrs.Other.UsrDat)) Lay_ShowErrorAndExit ("You can not view this test result."); /* User */ diff --git a/swad_user.c b/swad_user.c index 7cdc22374..c4ecf0746 100644 --- a/swad_user.c +++ b/swad_user.c @@ -1158,10 +1158,10 @@ bool Usr_CheckIfICanViewRecordTch (struct UsrData *UsrDat) } /*****************************************************************************/ -/*** Check if a user belongs to any of my courses but has a different role ***/ +/************** Check if I can view test exams of another user ***************/ /*****************************************************************************/ -bool Usr_CheckIfICanViewWrkTstAtt (const struct UsrData *UsrDat) +bool Usr_CheckIfICanViewTst (const struct UsrData *UsrDat) { /***** 1. Fast check: Am I logged? *****/ if (!Gbl.Usrs.Me.Logged) @@ -1203,6 +1203,99 @@ bool Usr_CheckIfICanViewWrkTstAtt (const struct UsrData *UsrDat) } } +/*****************************************************************************/ +/********** Check if I can view assigments / works of another user ***********/ +/*****************************************************************************/ + +bool Usr_CheckIfICanViewAsgWrk (const struct UsrData *UsrDat) + { + /***** 1. Fast check: Am I logged? *****/ + if (!Gbl.Usrs.Me.Logged) + return false; + + /***** 2. Fast check: Is it a valid user code? *****/ + if (UsrDat->UsrCod <= 0) + return false; + + /***** 3. Fast check: Is it a course selected? *****/ + if (Gbl.CurrentCrs.Crs.CrsCod <= 0) + return false; + + /***** 4. Fast check: Does he/she belong to the current course? *****/ + // Only users beloging to course can have files in assignments/works + if (!Usr_CheckIfUsrBelongsToCurrentCrs (UsrDat)) + return false; + + /***** 5. Fast check: Am I a system admin? *****/ + if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM) + return true; + + /***** 6. Fast check: Do I belong to the current course? *****/ + if (!Gbl.Usrs.Me.IBelongToCurrentCrs) + return false; + + /***** 7. Fast check: It's me? *****/ + if (Gbl.Usrs.Me.UsrDat.UsrCod == UsrDat->UsrCod) + return true; + + /***** 8. Fast / slow check depending on roles *****/ + switch (Gbl.Usrs.Me.Role.Logged) + { + case Rol_NET: + return Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (UsrDat); + case Rol_TCH: + return true; + default: + return false; + } + } + +/*****************************************************************************/ +/************** Check if I can view attendance of another user ***************/ +/*****************************************************************************/ + +bool Usr_CheckIfICanViewAtt (const struct UsrData *UsrDat) + { + /***** 1. Fast check: Am I logged? *****/ + if (!Gbl.Usrs.Me.Logged) + return false; + + /***** 2. Fast check: Is it a valid user code? *****/ + if (UsrDat->UsrCod <= 0) + return false; + + /***** 3. Fast check: Is it a course selected? *****/ + if (Gbl.CurrentCrs.Crs.CrsCod <= 0) + return false; + + /***** 4. Fast check: Is he/she a student in the current course? *****/ + if (UsrDat->Roles.InCurrentCrs.Role != Rol_STD) + return false; + + /***** 5. Fast check: Am I a system admin? *****/ + if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM) + return true; + + /***** 6. Fast check: Do I belong to the current course? *****/ + if (!Gbl.Usrs.Me.IBelongToCurrentCrs) + return false; + + /***** 7. Fast check: It's me? *****/ + if (Gbl.Usrs.Me.UsrDat.UsrCod == UsrDat->UsrCod) + return true; + + /***** 8. Fast / slow check depending on roles *****/ + switch (Gbl.Usrs.Me.Role.Logged) + { + case Rol_NET: + return Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (UsrDat); + case Rol_TCH: + return true; + default: + return false; + } + } + /*****************************************************************************/ /******************* Check if I can view a user's agenda *********************/ /*****************************************************************************/ diff --git a/swad_user.h b/swad_user.h index 9a35f4329..df1ada9de 100644 --- a/swad_user.h +++ b/swad_user.h @@ -267,7 +267,9 @@ 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); +bool Usr_CheckIfICanViewTst (const struct UsrData *UsrDat); +bool Usr_CheckIfICanViewAsgWrk (const struct UsrData *UsrDat); +bool Usr_CheckIfICanViewAtt (const struct UsrData *UsrDat); bool Usr_CheckIfICanViewUsrAgenda (struct UsrData *UsrDat); void Usr_FlushCacheUsrSharesAnyOfMyCrs (void);