diff --git a/swad_assignment.c b/swad_assignment.c index e0fb93d97..d4dfe029d 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -85,7 +85,7 @@ static bool Asg_CheckIfAsgIsAssociatedToGrps (long AsgCod); static void Asg_RemoveAllTheGrpsAssociatedToAnAssignment (long AsgCod); static void Asg_CreateGrps (long AsgCod); static void Asg_GetAndWriteNamesOfGrpsAssociatedToAsg (struct Assignment *Asg); -static bool Asg_CheckIfICanDoThisAssignment (long AsgCod); +static bool Asg_CheckIfIBelongToCrsOrGrpsThisAssignment (long AsgCod); /*****************************************************************************/ /************************ List all the assignments ***************************/ @@ -406,8 +406,9 @@ static void Asg_WriteAssignmentFolder (struct Assignment *Asg) if (Asg->SendWork == Asg_SEND_WORK) { /***** Folder icon *****/ - if (Asg->Open && - Asg->ICanDo) // I can send files to this assignment folder + if (Gbl.Usrs.Me.LoggedRole == Rol_STUDENT && + Asg->Open && + Asg->IBelongToCrsOrGrps) // I can send files to this assignment folder { /* Form to create a new file or folder */ Act_FormStart (ActFrmCreAsgUsr); @@ -422,7 +423,7 @@ static void Asg_WriteAssignmentFolder (struct Assignment *Asg) Gbl.Title); Act_FormEnd (); } - else // I can't send files to this assignment folder + else // I can't send files to this assignment folder fprintf (Gbl.F.Out,"\"%s\"", Gbl.Prefs.IconsURL, @@ -702,7 +703,7 @@ static void Asg_GetDataOfAssignment (struct Assignment *Asg,const char *Query) Asg->SendWork = (Asg->Folder[0] != '\0'); /* Can I do this assignment? */ - Asg->ICanDo = Asg_CheckIfICanDoThisAssignment (Asg->AsgCod); + Asg->IBelongToCrsOrGrps = Asg_CheckIfIBelongToCrsOrGrpsThisAssignment (Asg->AsgCod); } else { @@ -713,7 +714,7 @@ static void Asg_GetDataOfAssignment (struct Assignment *Asg,const char *Query) Asg->Title[0] = '\0'; Asg->SendWork = false; Asg->Folder[0] = '\0'; - Asg->ICanDo = false; + Asg->IBelongToCrsOrGrps = false; } /***** Free structure that stores the query result *****/ @@ -1034,7 +1035,7 @@ void Asg_RequestCreatOrEditAsg (void) Asg.Title[0] = '\0'; Asg.SendWork = false; Asg.Folder[0] = '\0'; - Asg.ICanDo = false; + Asg.IBelongToCrsOrGrps = false; } else { @@ -1573,19 +1574,22 @@ void Asg_RemoveCrsAssignments (long CrsCod) /********* Check if I belong to any of the groups of an assignment ***********/ /*****************************************************************************/ -static bool Asg_CheckIfICanDoThisAssignment (long AsgCod) +static bool Asg_CheckIfIBelongToCrsOrGrpsThisAssignment (long AsgCod) { char Query[512]; - if (Gbl.Usrs.Me.LoggedRole == Rol_STUDENT) + if (Gbl.Usrs.Me.LoggedRole == Rol_STUDENT || + Gbl.Usrs.Me.LoggedRole == Rol_TEACHER) { - /***** Get if I can do an assignment from database *****/ + // Students and teachers can edit assignments depending on groups + /***** Get if I can edit an assignment from database *****/ sprintf (Query,"SELECT COUNT(*) FROM assignments" " WHERE AsgCod='%ld'" - " AND (" - "AsgCod NOT IN (SELECT AsgCod FROM asg_grp)" + " AND " + "(" + "AsgCod NOT IN (SELECT AsgCod FROM asg_grp)" // Assignment is for the whole course " OR " - "AsgCod IN" + "AsgCod IN" // Assignment is for specific groups " (SELECT asg_grp.AsgCod FROM asg_grp,crs_grp_usr" " WHERE crs_grp_usr.UsrCod='%ld'" " AND asg_grp.GrpCod=crs_grp_usr.GrpCod)" @@ -1594,7 +1598,7 @@ static bool Asg_CheckIfICanDoThisAssignment (long AsgCod) return (DB_QueryCOUNT (Query,"can not check if I can do an assignment") != 0); } else - return false; + return (Gbl.Usrs.Me.LoggedRole > Rol_TEACHER); // Admins can edit assignments } /*****************************************************************************/ diff --git a/swad_assignment.h b/swad_assignment.h index f0e35f4ac..3ca2fef4a 100644 --- a/swad_assignment.h +++ b/swad_assignment.h @@ -62,7 +62,10 @@ struct Assignment char Title[Asg_MAX_LENGTH_ASSIGNMENT_TITLE+1]; Asg_SendWork_t SendWork; char Folder[Asg_MAX_LENGTH_FOLDER+1]; - bool ICanDo; // I can do this assignment (it is associated to no groups or (if associated to groups) I belong to any of the groups + bool IBelongToCrsOrGrps; // I can do this assignment + // (it is associated to no groups + // or, if associated to groups, + // I belong to any of the groups) }; typedef enum diff --git a/swad_changelog.h b/swad_changelog.h index f30e11632..72a430b4d 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -107,19 +107,19 @@ // TODO: The image of a country (the Earth) in listing of pending countries should link to the country inside SWAD // TODO: Row with total of users in figures // TODO: Remove total rows in listing of places -// TODO: Teachers should edit students' assignment folders and files // TODO: Show message indicating that mail could be in SPAM folder -// TODO: Fix problem with gmail. They think we are SPAM. See https://support.google.com/a/answer/178723 /*****************************************************************************/ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.35.5 (2015/11/09)" +#define Log_PLATFORM_VERSION "SWAD 15.36 (2015/11/10)" // 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 15.36: Nov 10, 2015 Fixed bug in assignments, reported by Javier Fernández Baldomero. + Changes in automatic creation of assignment folders. (186985 lines) Version 15.35.5: Nov 09, 2015 Fixed bug in swad.sql, reported by Florent H. Carré. Fixed bug in groups, reported by Francisco Ocaña Lara. (186977 lines) Version 15.35.4: Nov 09, 2015 Fixed bug in test exams. (186975 lines) diff --git a/swad_file_browser.c b/swad_file_browser.c index d918e6495..ec4a4f3be 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -1314,7 +1314,7 @@ static long Brw_GetGrpSettings (void); static void Brw_GetDataCurrentGrp (void); static void Brw_GetParamsPathInTreeAndFileName (void); static void Brw_SetPathFileBrowser (void); -static void Brw_CreateFoldersAssignmentsIfNotExist (void); +static void Brw_CreateFoldersAssignmentsIfNotExist (long ZoneUsrCod); static void Brw_SetAndCheckQuota (void); static void Brw_SetMaxQuota (void); static bool Brw_CheckIfQuotaExceded (void); @@ -2442,9 +2442,10 @@ static void Brw_SetPathFileBrowser (void) /***** If file browser is for assignments, create folders of assignments if not exist *****/ - if (Gbl.FileBrowser.Type == Brw_ADMI_ASSIG_USR || - Gbl.FileBrowser.Type == Brw_ADMI_ASSIG_CRS) - Brw_CreateFoldersAssignmentsIfNotExist (); + if (Gbl.FileBrowser.Type == Brw_ADMI_ASSIG_USR) + Brw_CreateFoldersAssignmentsIfNotExist (Gbl.Usrs.Me.UsrDat.UsrCod); + else if (Gbl.FileBrowser.Type == Brw_ADMI_ASSIG_CRS) + Brw_CreateFoldersAssignmentsIfNotExist (Gbl.Usrs.Other.UsrDat.UsrCod); } } @@ -2498,13 +2499,12 @@ bool Brw_CheckIfExistsFolderAssigmentForAnyUsr (const char *FolderName) /********* Create folders of assignments if not exist for one user ***********/ /*****************************************************************************/ // Folders are created in level 1, just under root folder -// Create a folder of and assignment when: +// Create a folder of an assignment when: // 1. The assignment is visible (not hidden) // 2. ...and the folder name is not empty (the teacher has set that the user must send work(s) for that assignment) -// 3. ...and the assignment is open (StartTime <= now <= EndTime) -// 4. ...the assignment is not restricted to groups or (if restricted to groups) I belong to any of the groups +// 3. ...the assignment is not restricted to groups or (if restricted to groups), the owner of zone belong to any of the groups -static void Brw_CreateFoldersAssignmentsIfNotExist (void) +static void Brw_CreateFoldersAssignmentsIfNotExist (long ZoneUsrCod) { char Query[1024]; MYSQL_RES *mysql_res; @@ -2513,12 +2513,13 @@ static void Brw_CreateFoldersAssignmentsIfNotExist (void) char PathFolderAsg[PATH_MAX+1]; /***** Get assignment folders from database *****/ + // Old behaviour (only create assignment folder if assignment is open) is obsolete since 2015-11-10 sprintf (Query,"SELECT Folder FROM assignments" - " WHERE CrsCod='%ld' AND Hidden='N' AND Folder<>'' AND StartTime<=NOW() AND EndTime>=NOW()" + " WHERE CrsCod='%ld' AND Hidden='N' AND Folder<>''" " AND (AsgCod NOT IN (SELECT AsgCod FROM asg_grp) OR" " AsgCod IN (SELECT asg_grp.AsgCod FROM asg_grp,crs_grp_usr" " WHERE crs_grp_usr.UsrCod='%ld' AND asg_grp.GrpCod=crs_grp_usr.GrpCod))", - Gbl.CurrentCrs.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod); + Gbl.CurrentCrs.Crs.CrsCod,ZoneUsrCod); NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get folders of assignments"); /***** Create one folder for each assignment *****/ @@ -10561,10 +10562,10 @@ static bool Brw_CheckIfICanEditFileOrFolder (unsigned Level) case Brw_ADMI_ASSIG_CRS: return (Level != 0 && (Gbl.FileBrowser.Asg.AsgCod < 0 || // If folder does not correspond to any assignment - (Level > 1 && - !Gbl.FileBrowser.Asg.Hidden && // If assignment is visible (not hidden) - Gbl.FileBrowser.Asg.ICanDo && // If I can do this assignment - (Gbl.FileBrowser.Asg.Open || Gbl.Usrs.Me.LoggedRole >= Rol_TEACHER)))); + (!Gbl.FileBrowser.Asg.Hidden && // If assignment is visible (not hidden) + Gbl.FileBrowser.Asg.IBelongToCrsOrGrps && // If I can do this assignment + ((Gbl.Usrs.Me.LoggedRole == Rol_STUDENT && Gbl.FileBrowser.Asg.Open) || + Gbl.Usrs.Me.LoggedRole >= Rol_TEACHER)))); default: return (Level != 0 && Brw_FileBrowserIsEditable[Gbl.FileBrowser.Type]); @@ -10593,9 +10594,9 @@ static bool Brw_CheckIfICanCreateIntoFolder (unsigned Level) return (Level != 0 && (Gbl.FileBrowser.Asg.AsgCod < 0 || // If folder does not correspond to any assignment (!Gbl.FileBrowser.Asg.Hidden && // If assignment is visible (not hidden) - Gbl.FileBrowser.Asg.ICanDo && // If I can do this assignment - (Gbl.FileBrowser.Asg.Open || - Gbl.Usrs.Me.LoggedRole >= Rol_TEACHER)))); + Gbl.FileBrowser.Asg.IBelongToCrsOrGrps && // If I can do this assignment + ((Gbl.Usrs.Me.LoggedRole == Rol_STUDENT && Gbl.FileBrowser.Asg.Open) || + Gbl.Usrs.Me.LoggedRole >= Rol_TEACHER)))); default: return Brw_FileBrowserIsEditable[Gbl.FileBrowser.Type]; }