From 041faac9ea8cd05ef036c49694d42ac0e2387a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Sat, 7 Oct 2017 20:01:34 +0200 Subject: [PATCH] Version 17.20.7 --- swad_changelog.h | 3 +- swad_file_browser.c | 109 +++++++++++++++++++++++++++++++++----------- swad_project.c | 28 ++++++++++++ swad_project.h | 2 + 4 files changed, 115 insertions(+), 27 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 99764daa1..3eafa85a2 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -256,13 +256,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 17.20.6 (2017-10-07)" +#define Log_PLATFORM_VERSION "SWAD 17.20.7 (2017-10-07)" #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.20.7: Oct 07, 2017 Only publishers can remove subtrees in project documents. (233105 lines) Version 17.20.6: Oct 07, 2017 Fixed bug in project documents. (233027 lines) Version 17.20.5: Oct 07, 2017 Title of project is now a link to show the project and its documents. (233024 lines) Version 17.20.4: Oct 07, 2017 Changes in layout of project. (232972 lines) diff --git a/swad_file_browser.c b/swad_file_browser.c index d442744c1..68721be59 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -1675,6 +1675,7 @@ static bool Brw_CheckIfICanEditFileOrFolder (unsigned Level); static bool Brw_CheckIfICanCreateIntoFolder (unsigned Level); static bool Brw_CheckIfICanModifySharedFileOrFolder (void); static bool Brw_CheckIfICanModifyPrivateFileOrFolder (void); +static bool Brw_CheckIfICanModifyProjectFileOrFolder (void); static long Brw_GetPublisherOfSubtree (void); static void Brw_WriteRowDocData (unsigned *NumDocsNotHidden,MYSQL_ROW row); @@ -5515,9 +5516,11 @@ static bool Brw_WriteRowFileBrowser (unsigned Level,const char *RowId, Gbl.FileBrowser.Asg.AsgCod = -1L; /***** Get the name of the file to show *****/ - Brw_GetFileNameToShowDependingOnLevel (Gbl.FileBrowser.Type,Level, + Brw_GetFileNameToShowDependingOnLevel (Gbl.FileBrowser.Type, + Level, Gbl.FileBrowser.FileType, - FileName,FileNameToShow); + FileName, + FileNameToShow); /***** Start this row *****/ fprintf (Gbl.F.Out,"%s.", Txt_Copy_source,TxtClipboardZone, @@ -8384,9 +8390,11 @@ void Brw_ShowFormFileBrowser (void) if (Brw_CheckIfICanCreateIntoFolder (Gbl.FileBrowser.Level)) { /***** Name of the folder to be shown ****/ - Brw_GetFileNameToShowDependingOnLevel (Gbl.FileBrowser.Type,Gbl.FileBrowser.Level, - Gbl.FileBrowser.FileType, - Gbl.FileBrowser.FilFolLnkName,FileNameToShow); + Brw_GetFileNameToShowDependingOnLevel (Gbl.FileBrowser.Type, + Gbl.FileBrowser.Level, + Gbl.FileBrowser.FileType, + Gbl.FileBrowser.FilFolLnkName, + FileNameToShow); /***** 1. Form to create a new folder *****/ Brw_PutFormToCreateAFolder (FileNameToShow); @@ -8727,9 +8735,11 @@ void Brw_RecFolderFileBrowser (void) PathCompleteInTreeIncludingFolder,false,Brw_LICENSE_DEFAULT); /* The folder has been created sucessfully */ - Brw_GetFileNameToShowDependingOnLevel (Gbl.FileBrowser.Type,Gbl.FileBrowser.Level, - Brw_IS_FOLDER, - Gbl.FileBrowser.FilFolLnkName,FileNameToShow); + Brw_GetFileNameToShowDependingOnLevel (Gbl.FileBrowser.Type, + Gbl.FileBrowser.Level, + Brw_IS_FOLDER, + Gbl.FileBrowser.FilFolLnkName, + FileNameToShow); sprintf (Gbl.Alert.Txt,Txt_The_folder_X_has_been_created_inside_the_folder_Y, Gbl.FileBrowser.NewFilFolLnkName,FileNameToShow); Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt); @@ -9029,9 +9039,11 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType) /* Show message of confirmation */ if (UploadType == Brw_CLASSIC_UPLOAD) { - Brw_GetFileNameToShowDependingOnLevel (Gbl.FileBrowser.Type,Gbl.FileBrowser.Level, - Brw_IS_FOLDER, - Gbl.FileBrowser.FilFolLnkName,FileNameToShow); + Brw_GetFileNameToShowDependingOnLevel (Gbl.FileBrowser.Type, + Gbl.FileBrowser.Level, + Brw_IS_FOLDER, + Gbl.FileBrowser.FilFolLnkName, + FileNameToShow); sprintf (Gbl.Alert.Txt,Txt_The_file_X_has_been_placed_inside_the_folder_Y, Gbl.FileBrowser.NewFilFolLnkName, FileNameToShow); @@ -9205,9 +9217,11 @@ void Brw_RecLinkFileBrowser (void) PathCompleteInTreeIncludingFile,false,Brw_LICENSE_DEFAULT); /* Show message of confirmation */ - Brw_GetFileNameToShowDependingOnLevel (Gbl.FileBrowser.Type,Gbl.FileBrowser.Level, - Brw_IS_FOLDER, - Gbl.FileBrowser.FilFolLnkName,FileNameToShow); + Brw_GetFileNameToShowDependingOnLevel (Gbl.FileBrowser.Type, + Gbl.FileBrowser.Level, + Brw_IS_FOLDER, + Gbl.FileBrowser.FilFolLnkName, + FileNameToShow); sprintf (Gbl.Alert.Txt,Txt_The_link_X_has_been_placed_inside_the_folder_Y, FileName,FileNameToShow); Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt); @@ -9356,9 +9370,11 @@ void Brw_SetDocumentAsVisible (void) Brw_RemoveAffectedClipboards (Gbl.FileBrowser.Type,Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Usrs.Other.UsrDat.UsrCod); /***** Write message of confirmation *****/ - Brw_GetFileNameToShowDependingOnLevel (Gbl.FileBrowser.Type,Gbl.FileBrowser.Level, - Gbl.FileBrowser.FileType, - Gbl.FileBrowser.FilFolLnkName,FileNameToShow); + Brw_GetFileNameToShowDependingOnLevel (Gbl.FileBrowser.Type, + Gbl.FileBrowser.Level, + Gbl.FileBrowser.FileType, + Gbl.FileBrowser.FilFolLnkName, + FileNameToShow); sprintf (Gbl.Alert.Txt,Txt_FILE_FOLDER_OR_LINK_X_is_now_visible, FileNameToShow); Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt); @@ -9389,9 +9405,11 @@ void Brw_SetDocumentAsHidden (void) Brw_RemoveAffectedClipboards (Gbl.FileBrowser.Type,Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Usrs.Other.UsrDat.UsrCod); /***** Write confirmation message *****/ - Brw_GetFileNameToShowDependingOnLevel (Gbl.FileBrowser.Type,Gbl.FileBrowser.Level, - Gbl.FileBrowser.FileType, - Gbl.FileBrowser.FilFolLnkName,FileNameToShow); + Brw_GetFileNameToShowDependingOnLevel (Gbl.FileBrowser.Type, + Gbl.FileBrowser.Level, + Gbl.FileBrowser.FileType, + Gbl.FileBrowser.FilFolLnkName, + FileNameToShow); sprintf (Gbl.Alert.Txt,Txt_FILE_FOLDER_OR_LINK_X_is_now_hidden,FileNameToShow); Ale_ShowAlert (Ale_SUCCESS,Gbl.Alert.Txt); @@ -11423,6 +11441,9 @@ static bool Brw_CheckIfICanEditFileOrFolder (unsigned Level) break; } return false; + case Brw_ADMI_DOCUM_PRJ: + // Check if I am the publisher of the file/folder + return Brw_CheckIfICanModifyProjectFileOrFolder (); default: return Brw_FileBrowserIsEditable[Gbl.FileBrowser.Type]; } @@ -11550,6 +11571,42 @@ static bool Brw_CheckIfICanModifyPrivateFileOrFolder (void) } } + +/*****************************************************************************/ +/********** Check if I have permission to modify a file or folder ************/ +/********** in the current project documents zone ************/ +/*****************************************************************************/ +// Returns true if I can remove or rename Gbl.FileBrowser.Priv.FullPathInTree, and false if I have not permission +// I can remove or rename a file if I am the publisher +// I can remove or rename a folder if I am the unique publisher of all the files and folders in the subtree starting there + +static bool Brw_CheckIfICanModifyProjectFileOrFolder (void) + { + Prj_RoleInProject_t MyRoleInProject; + + switch (Gbl.Usrs.Me.Role.Logged) + { + case Rol_STD: // If I am a student or a non-editing teacher... + case Rol_NET: // ...I can modify the file/folder if I am the publisher + case Rol_TCH: + MyRoleInProject = Prj_GetMyRoleInProject (Gbl.CurrentCrs.Prjs.PrjCod); + switch (MyRoleInProject) + { + case Prj_ROLE_UNK: // I am not a member + return false; + case Prj_ROLE_STD: + case Prj_ROLE_TUT: + case Prj_ROLE_EVA: + return (Gbl.Usrs.Me.UsrDat.UsrCod == Brw_GetPublisherOfSubtree ()); // Am I the publisher of subtree? + } + return false; + case Rol_SYS_ADM: + return true; + default: + return false; + } + } + /*****************************************************************************/ /************************ Get the publisher of a subtree *********************/ /*****************************************************************************/ diff --git a/swad_project.c b/swad_project.c index a721239a8..7b5008535 100644 --- a/swad_project.c +++ b/swad_project.c @@ -1419,6 +1419,34 @@ static unsigned Prj_GetUsrsInPrj (long PrjCod,Prj_RoleInProject_t RoleInProject, "can not get users in project"); } +/*****************************************************************************/ +/************************** Get my role in a project *************************/ +/*****************************************************************************/ + +Prj_RoleInProject_t Prj_GetMyRoleInProject (long PrjCod) + { + char Query[128]; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned UnsignedNum; + Prj_RoleInProject_t RoleInProject = Prj_ROLE_UNK; + + /***** Get my role in project from database *****/ + sprintf (Query,"SELECT RoleInProject FROM prj_usr WHERE PrjCod=%ld",PrjCod); + if (DB_QuerySELECT (Query,&mysql_res,"can not get my role in project")) + { + row = mysql_fetch_row (mysql_res); + if (sscanf (row[0],"%u",&UnsignedNum) == 1) + if (UnsignedNum < Prj_NUM_ROLES_IN_PROJECT) + RoleInProject = (Prj_RoleInProject_t) UnsignedNum; + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + return RoleInProject; + } + /*****************************************************************************/ /*** Request another user's ID, @nickname or email to add user to project ****/ /*****************************************************************************/ diff --git a/swad_project.h b/swad_project.h index b74e7d0ee..88a1601b4 100644 --- a/swad_project.h +++ b/swad_project.h @@ -115,6 +115,8 @@ void Prj_ShowOneUniqueProject (struct Project *Prj); void Prj_PrintOneProject (void); +Prj_RoleInProject_t Prj_GetMyRoleInProject (long PrjCod); + void Prj_ReqAddStd (void); void Prj_ReqAddTut (void); void Prj_ReqAddEva (void);