From 012dac0f09898be2d17d4572de880781d3f411b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Fri, 27 Jan 2017 10:42:20 +0100 Subject: [PATCH] Version 16.126 --- swad_ID.c | 47 ++++------------------------------------------- swad_ID.h | 1 - swad_changelog.h | 6 +++++- swad_enrollment.c | 36 +++++++----------------------------- swad_enrollment.h | 2 -- swad_mail.c | 37 +++---------------------------------- swad_mail.h | 1 - swad_password.c | 17 ++--------------- swad_password.h | 2 -- swad_record.c | 2 +- swad_text.c | 14 +++++++------- swad_user.c | 30 ++++++++++++++++++++++++++++++ swad_user.h | 1 + 13 files changed, 60 insertions(+), 136 deletions(-) diff --git a/swad_ID.c b/swad_ID.c index c84ba2b95..637fd1d38 100644 --- a/swad_ID.c +++ b/swad_ID.c @@ -425,45 +425,6 @@ bool ID_ICanSeeOtherUsrIDs (const struct UsrData *UsrDat) !UsrDat->Surname1[0] && // and who has no surname 1 (nobody filled user's surname 1) !UsrDat->FirstName[0] // and who has no first name (nobody filled user's first name) ); - return (UsrDat->RoleInCurrentCrsDB == Rol_STUDENT && // A student - UsrDat->Accepted) || // who has accepted inscription in course - ( - (UsrDat->RoleInCurrentCrsDB == Rol_STUDENT || // A student - UsrDat->RoleInCurrentCrsDB == Rol_TEACHER) && // or a teacher - !UsrDat->Password[0] && // who has no password (never logged) - !UsrDat->Surname1[0] && // and who has no surname 1 (nobody filled user's surname 1) - !UsrDat->FirstName[0] // and who has no first name (nobody filled user's first name) - ); - case Rol_DEG_ADM: - case Rol_CTR_ADM: - case Rol_INS_ADM: - case Rol_SYS_ADM: - return Usr_CheckIfIAsAdminCanEditOtherUsr (UsrDat); - default: - return false; - } - } - -/*****************************************************************************/ -/***************** Check if I can change another user's IDs ******************/ -/*****************************************************************************/ - -bool ID_ICanChangeOtherUsrIDs (const struct UsrData *UsrDat) - { - if (UsrDat->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // It's me - return true; - - /***** Check if I have permission to see another user's IDs *****/ - switch (Gbl.Usrs.Me.LoggedRole) - { - case Rol_TEACHER: - /* If I am a teacher of current course, - I only can change the user's IDs of empty users from current course */ - return (UsrDat->RoleInCurrentCrsDB == Rol_STUDENT || // A student - UsrDat->RoleInCurrentCrsDB == Rol_TEACHER) && // or a teacher - !UsrDat->Password[0] && // who has no password (never logged) - !UsrDat->Surname1[0] && // and who has no surname 1 (nobody filled user's surname 1) - !UsrDat->FirstName[0]; // and who has no first name (nobody filled user's first name) case Rol_DEG_ADM: case Rol_CTR_ADM: case Rol_INS_ADM: @@ -548,7 +509,7 @@ void ID_ShowFormOthIDs (void) /***** Get user whose password must be changed *****/ if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) { - if (ID_ICanChangeOtherUsrIDs (&Gbl.Usrs.Other.UsrDat)) + if (Usr_ICanChangeOtherUsrData (&Gbl.Usrs.Other.UsrDat)) { /***** Start frame *****/ Lay_StartRoundFrame (NULL,Txt_ID,NULL,NULL); @@ -752,7 +713,7 @@ static void ID_RemoveUsrID (const struct UsrData *UsrDat,bool ItsMe) char UsrID[ID_MAX_LENGTH_USR_ID+1]; bool ICanRemove; - if (ID_ICanChangeOtherUsrIDs (UsrDat)) + if (Usr_ICanChangeOtherUsrData (UsrDat)) { /***** Get user's ID from form *****/ Par_GetParToText ("UsrID",UsrID,ID_MAX_LENGTH_USR_ID); @@ -873,7 +834,7 @@ static void ID_NewUsrID (const struct UsrData *UsrDat,bool ItsMe) unsigned NumIDFound = 0; // Initialized to avoid warning bool Error = false; - if (ID_ICanChangeOtherUsrIDs (UsrDat)) + if (Usr_ICanChangeOtherUsrData (UsrDat)) { /***** Get new user's ID from form *****/ Par_GetParToText ("NewID",NewID,ID_MAX_LENGTH_USR_ID); @@ -996,7 +957,7 @@ static void ID_ReqConfOrConfOtherUsrID (ID_ReqConfOrConfID_t ReqConfOrConfID) /***** Get other user's code from form and get user's data *****/ if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) if (Gbl.Usrs.Other.UsrDat.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // Not me - if (ID_ICanChangeOtherUsrIDs (&Gbl.Usrs.Other.UsrDat)) + if (Usr_ICanChangeOtherUsrData (&Gbl.Usrs.Other.UsrDat)) ICanConfirm = true; if (ICanConfirm) diff --git a/swad_ID.h b/swad_ID.h index cb0dfc0e9..e8d8e750c 100644 --- a/swad_ID.h +++ b/swad_ID.h @@ -66,7 +66,6 @@ bool ID_CheckIfUsrIDSeemsAValidID (const char *UsrID); void ID_WriteUsrIDs (struct UsrData *UsrDat); bool ID_ICanSeeOtherUsrIDs (const struct UsrData *UsrDat); -bool ID_ICanChangeOtherUsrIDs (const struct UsrData *UsrDat); void ID_PutLinkToChangeUsrIDs (void); void ID_ShowFormOthIDs (void); diff --git a/swad_changelog.h b/swad_changelog.h index 1ab23947b..b0571b481 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -187,17 +187,21 @@ // TODO: Fix bug when creating a new attendance event: if title is repeated, form is cleared // TODO: Fix bug: When registering an administrator, the user's name changes are ignored +// TODO: When creating a new user, the ID should be visible and the record card should not have contextual icons + /*****************************************************************************/ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.125 (2017-01-27)" +#define Log_PLATFORM_VERSION "SWAD 16.126 (2017-01-27)" #define CSS_FILE "swad16.123.css" #define JS_FILE "swad16.123.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.126.1: Jan 27, 2017 A teacher can create and register a new teacher directly in a course. (? lines) + Version 16.126: Jan 27, 2017 Code refactoring related to permissions to view/change another user's data. (212086 lines) Version 16.125: Jan 27, 2017 Code refactoring related to permissions to view/change another user's data. (212152 lines) Version 16.124: Jan 26, 2017 Code refactoring related to permissions to view/change another user's data. (212163 lines) Version 16.123.4: Jan 26, 2017 Surname1 and first name can not be deleted when editing user's data. (212000 lines) diff --git a/swad_enrollment.c b/swad_enrollment.c index ed98333d9..9e3b5f9bb 100644 --- a/swad_enrollment.c +++ b/swad_enrollment.c @@ -3051,7 +3051,7 @@ static void Enr_AskIfRegRemUsr (struct ListUsrCods *ListUsrCods,Rol_Role_t Role) extern const char *Txt_THE_USER_X_is_already_in_the_course_Y_but_has_not_yet_accepted_the_enrollment; extern const char *Txt_THE_USER_X_already_exists_in_Y_but_is_not_yet_enrolled_in_the_course_Z; extern const char *Txt_THE_USER_X_already_exists_in_Y; - extern const char *Txt_The_user_is_new_does_not_exists_yet_in_X; + extern const char *Txt_The_user_is_new_not_yet_in_X; extern const char *Txt_If_this_is_a_new_user_in_X_you_should_indicate_her_his_ID; unsigned NumUsr; bool NewUsrIDValid; @@ -3129,7 +3129,7 @@ static void Enr_AskIfRegRemUsr (struct ListUsrCods *ListUsrCods,Rol_Role_t Role) if (NewUsrIDValid) { /***** Show form to enter the data of a new user *****/ - sprintf (Gbl.Message,Txt_The_user_is_new_does_not_exists_yet_in_X, + sprintf (Gbl.Message,Txt_The_user_is_new_not_yet_in_X, Cfg_PLATFORM_SHORT_NAME); Lay_ShowAlert (Lay_INFO,Gbl.Message); Rec_ShowFormOtherNewSharedRecord (&Gbl.Usrs.Other.UsrDat); @@ -3154,14 +3154,14 @@ static void Enr_ShowFormToEditOtherUsr (void) /***** Buttons for edition *****/ fprintf (Gbl.F.Out,"
"); - if (Pwd_ICanChangeOtherUsrPassword (&Gbl.Usrs.Other.UsrDat)) + if (Usr_CheckIfIAsAdminCanEditOtherUsr (&Gbl.Usrs.Other.UsrDat)) Pwd_PutLinkToChangeOtherUsrPassword (); // Put link (form) to change user's password - if (Mai_ICanChangeOtherUsrEmails (&Gbl.Usrs.Other.UsrDat)) + if (Usr_ICanChangeOtherUsrData (&Gbl.Usrs.Other.UsrDat)) + { Mai_PutLinkToChangeOtherUsrEmails (); // Put link (form) to change user's emails - - if (ID_ICanChangeOtherUsrIDs (&Gbl.Usrs.Other.UsrDat)) ID_PutLinkToChangeUsrIDs (); // Put link (form) to change user's IDs + } if (Pho_ICanChangeOtherUsrPhoto (&Gbl.Usrs.Other.UsrDat)) Pho_PutLinkToChangeOtherUsrPhoto (); // Put link (form) to change user's photo @@ -3669,7 +3669,7 @@ void Enr_ModifyUsr1 (void) if (ItsMe || Gbl.Usrs.Me.LoggedRole >= Rol_TEACHER) { /***** Get user's name from record form *****/ - if (Enr_CheckIfICanChangeAnotherUsrData (&Gbl.Usrs.Other.UsrDat)) + if (Usr_ICanChangeOtherUsrData (&Gbl.Usrs.Other.UsrDat)) Rec_GetUsrNameFromRecordForm (&Gbl.Usrs.Other.UsrDat); /***** Update user's data in database *****/ @@ -3827,28 +3827,6 @@ void Enr_ModifyUsr2 (void) } } -/*****************************************************************************/ -/**************** Check if I can change another user's data ******************/ -/*****************************************************************************/ - -bool Enr_CheckIfICanChangeAnotherUsrData (const struct UsrData *UsrDat) - { - switch (Gbl.Usrs.Me.LoggedRole) - { - case Rol_TEACHER: // Teachers only can edit data of new users - return !UsrDat->Email[0] || // Email empty - !UsrDat->Surname1[0] || // Surname 1 empty - !UsrDat->FirstName[0]; // First name empty - case Rol_DEG_ADM: - case Rol_CTR_ADM: - case Rol_INS_ADM: - case Rol_SYS_ADM: // Admins always can edit another user's data - return true; - default: // With other roles, I can not edit another user's data - return false; - } - } - /*****************************************************************************/ /********* Set a user's acceptation to true in the current course ************/ /*****************************************************************************/ diff --git a/swad_enrollment.h b/swad_enrollment.h index 30f3390e6..061838c8f 100644 --- a/swad_enrollment.h +++ b/swad_enrollment.h @@ -136,8 +136,6 @@ void Enr_CreateNewUsr2 (void); void Enr_ModifyUsr1 (void); void Enr_ModifyUsr2 (void); -bool Enr_CheckIfICanChangeAnotherUsrData (const struct UsrData *UsrDat); - void Enr_AcceptUsrInCrs (long UsrCod); #endif diff --git a/swad_mail.c b/swad_mail.c index 2a9fc7a91..373a5923f 100644 --- a/swad_mail.c +++ b/swad_mail.c @@ -1137,37 +1137,6 @@ void Mai_PutLinkToChangeOtherUsrEmails (void) NULL); } -/*****************************************************************************/ -/************** Check if I can change the email of another user **************/ -/*****************************************************************************/ - -bool Mai_ICanChangeOtherUsrEmails (const struct UsrData *UsrDat) - { - if (UsrDat->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // It's me - return true; - - /***** Check if I have permission to change another user's emails *****/ - switch (Gbl.Usrs.Me.LoggedRole) - { - case Rol_TEACHER: - /* If I am a teacher of current course, - I only can change the user's emails - of empty users from current course */ - return (UsrDat->RoleInCurrentCrsDB == Rol_STUDENT || // A student - UsrDat->RoleInCurrentCrsDB == Rol_TEACHER) && // or a teacher - !UsrDat->Password[0] && // who has no password (never logged) - !UsrDat->Surname1[0] && // and who has no surname 1 (nobody filled user's surname 1) - !UsrDat->FirstName[0]; // and who has no first name (nobody filled user's first name) - case Rol_DEG_ADM: - case Rol_CTR_ADM: - case Rol_INS_ADM: - case Rol_SYS_ADM: - return Usr_CheckIfIAsAdminCanEditOtherUsr (UsrDat); - default: - return false; - } - } - /*****************************************************************************/ /*********** Show form to the change the email of another user ***************/ /*****************************************************************************/ @@ -1180,7 +1149,7 @@ void Mai_ShowFormOthEmail (void) /***** Get user whose password must be changed *****/ if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) { - if (Mai_ICanChangeOtherUsrEmails (&Gbl.Usrs.Other.UsrDat)) + if (Usr_ICanChangeOtherUsrData (&Gbl.Usrs.Other.UsrDat)) { /***** Start frame *****/ Lay_StartRoundFrame (NULL,Txt_Email,NULL,NULL); @@ -1399,7 +1368,7 @@ static void Mai_RemoveEmail (struct UsrData *UsrDat) extern const char *Txt_User_not_found_or_you_do_not_have_permission_; char Email[Usr_MAX_BYTES_USR_EMAIL+1]; - if (Mai_ICanChangeOtherUsrEmails (UsrDat)) + if (Usr_ICanChangeOtherUsrData (UsrDat)) { /***** Get new email from form *****/ Par_GetParToText ("Email",Email,Usr_MAX_BYTES_USR_EMAIL); @@ -1481,7 +1450,7 @@ static void Mai_NewUsrEmail (struct UsrData *UsrDat,bool ItsMe) extern const char *Txt_User_not_found_or_you_do_not_have_permission_; char NewEmail[Usr_MAX_BYTES_USR_EMAIL+1]; - if (Mai_ICanChangeOtherUsrEmails (UsrDat)) + if (Usr_ICanChangeOtherUsrData (UsrDat)) { /***** Get new email from form *****/ Par_GetParToText ("NewEmail",NewEmail,Usr_MAX_BYTES_USR_EMAIL); diff --git a/swad_mail.h b/swad_mail.h index b7fc8e56b..6b566e0f1 100644 --- a/swad_mail.h +++ b/swad_mail.h @@ -78,7 +78,6 @@ bool Mai_GetEmailFromUsrCod (struct UsrData *UsrDat); long Mai_GetUsrCodFromEmail (const char *Email); void Mai_PutLinkToChangeOtherUsrEmails (void); -bool Mai_ICanChangeOtherUsrEmails (const struct UsrData *UsrDat); void Mai_ShowFormOthEmail (void); void Mai_ShowFormChangeUsrEmail (const struct UsrData *UsrDat,bool ItsMe); void Mai_RemoveMyUsrEmail (void); diff --git a/swad_password.c b/swad_password.c index 6a23e13b3..630f582fa 100644 --- a/swad_password.c +++ b/swad_password.c @@ -491,7 +491,7 @@ void Pwd_UpdateOtherPwd1 (void) /***** Get other user's code from form and get user's data *****/ if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) { - if (Pwd_ICanChangeOtherUsrPassword (&Gbl.Usrs.Other.UsrDat)) + if (Usr_CheckIfIAsAdminCanEditOtherUsr (&Gbl.Usrs.Other.UsrDat)) { Par_GetParToText ("Paswd1",NewPlainPassword[0],Pwd_MAX_LENGTH_PLAIN_PASSWORD); Par_GetParToText ("Paswd2",NewPlainPassword[1],Pwd_MAX_LENGTH_PLAIN_PASSWORD); @@ -813,7 +813,7 @@ void Pwd_ShowFormOthPwd (void) /***** Get user whose password must be changed *****/ if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ()) { - if (Pwd_ICanChangeOtherUsrPassword (&Gbl.Usrs.Other.UsrDat)) + if (Usr_CheckIfIAsAdminCanEditOtherUsr (&Gbl.Usrs.Other.UsrDat)) { /***** Start frame *****/ Lay_StartRoundFrame (NULL,Txt_Password,NULL,NULL); @@ -883,19 +883,6 @@ void Pwd_PutLinkToChangeOtherUsrPassword (void) NULL); } -/*****************************************************************************/ -/************ Check if I can change the password of another user *************/ -/*****************************************************************************/ - -bool Pwd_ICanChangeOtherUsrPassword (const struct UsrData *UsrDat) - { - if (UsrDat->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // It's me - return true; - - /***** Check if I have permission to change another user's password *****/ - return Usr_CheckIfIAsAdminCanEditOtherUsr (UsrDat); - } - /*****************************************************************************/ /***************** Ask for confirmation on dangerous actions *****************/ /*****************************************************************************/ diff --git a/swad_password.h b/swad_password.h index 965d9ec1a..3de6a22ab 100644 --- a/swad_password.h +++ b/swad_password.h @@ -69,8 +69,6 @@ void Pwd_ShowFormOthPwd (void); void Pwd_PutLinkToChangeMyPassword (void); void Pwd_PutLinkToChangeOtherUsrPassword (void); -bool Pwd_ICanChangeOtherUsrPassword (const struct UsrData *UsrDat); - void Pwd_AskForConfirmationOnDangerousAction (void); bool Pwd_GetConfirmationOnDangerousAction (void); diff --git a/swad_record.c b/swad_record.c index e33a20814..7e851608c 100644 --- a/swad_record.c +++ b/swad_record.c @@ -2123,7 +2123,7 @@ void Rec_ShowSharedUsrRecord (Rec_SharedRecordViewType_t TypeOfView, ICanEdit = true; break; case Rec_SHA_OTHER_EXISTING_USR_FORM: - ICanEdit = Enr_CheckIfICanChangeAnotherUsrData (UsrDat); + ICanEdit = Usr_ICanChangeOtherUsrData (UsrDat); break; default: // In other options, I can not edit another user's data ICanEdit = false; diff --git a/swad_text.c b/swad_text.c index b3e6ca828..e76c6ac1b 100644 --- a/swad_text.c +++ b/swad_text.c @@ -45985,25 +45985,25 @@ const char *Txt_THE_USER_X_is_already_enrolled_in_the_course_Y = // Warning: it " in the course %s."; // Necessita de tradução #endif -const char *Txt_The_user_is_new_does_not_exists_yet_in_X = // Warning: it is very important to include %s in the following sentences +const char *Txt_The_user_is_new_not_yet_in_X = // Warning: it is very important to include %s in the following sentences #if L==1 - "El usuario/a es nuevo/a, aún no existe en %s."; // Necessita traduccio + "L'usuari és nou, encara no existeix en %s."; #elif L==2 - "The user is new, does not exist yet in %s."; // Übersetzung notwendig + "Der Benutzer ist neu, noch nicht in %s."; #elif L==3 - "The user is new, does not exist yet in %s."; + "The user is new, not yet in %s."; #elif L==4 "El usuario/a es nuevo/a, aún no existe en %s."; #elif L==5 - "The user is new, does not exist yet in %s."; // Besoin de traduction + "L'utilisateur est nouveau, pas encore dans %s."; #elif L==6 "El usuario/a es nuevo/a, aún no existe en %s."; // Okoteve traducción #elif L==7 "L'utente è nuovo, non esiste ancora in %s."; #elif L==8 - "The user is new, does not exist yet in %s."; // Potrzebujesz tlumaczenie + "Użytkownik jest nowa, jeszcze nie w %s."; #elif L==9 - "The user is new, does not exist yet in %s."; // Necessita de tradução + "O usuário é novo, ainda não existe o %s."; #endif const char *Txt_THE_USER_X_is_not_an_administrator_of_Y = // Warning: it is very important to include two %s in the following sentences diff --git a/swad_user.c b/swad_user.c index fd9a04daa..f7fb52e8b 100644 --- a/swad_user.c +++ b/swad_user.c @@ -821,6 +821,36 @@ bool Usr_CheckIfUsrIsSuperuser (long UsrCod) return Cache.IsSuperuser; } +/*****************************************************************************/ +/**************** Check if I can change another user's data ******************/ +/*****************************************************************************/ + +bool Usr_ICanChangeOtherUsrData (const struct UsrData *UsrDat) + { + if (UsrDat->UsrCod == Gbl.Usrs.Me.UsrDat.UsrCod) // It's me + return true; + + /***** Check if I have permission to see another user's IDs *****/ + switch (Gbl.Usrs.Me.LoggedRole) + { + case Rol_TEACHER: + /* If I am a teacher of current course, + I only can change the user's data of empty users from current course */ + return (UsrDat->RoleInCurrentCrsDB == Rol_STUDENT || // A student + UsrDat->RoleInCurrentCrsDB == Rol_TEACHER) && // or a teacher + !UsrDat->Password[0] && // who has no password (never logged) + !UsrDat->Surname1[0] && // and who has no surname 1 (nobody filled user's surname 1) + !UsrDat->FirstName[0]; // and who has no first name (nobody filled user's first name) + case Rol_DEG_ADM: + case Rol_CTR_ADM: + case Rol_INS_ADM: + case Rol_SYS_ADM: + return Usr_CheckIfIAsAdminCanEditOtherUsr (UsrDat); + default: + return false; + } + } + /*****************************************************************************/ /************ Check if I (as admin) can edit another user's data *************/ /*****************************************************************************/ diff --git a/swad_user.h b/swad_user.h index 19649915d..df5bf061e 100644 --- a/swad_user.h +++ b/swad_user.h @@ -234,6 +234,7 @@ void Usr_RestrictLengthAndWriteName (const struct UsrData *UsrDat,unsigned MaxCh bool Usr_CheckIfUsrIsAdm (long UsrCod,Sco_Scope_t Scope,long Cod); bool Usr_CheckIfUsrIsSuperuser (long UsrCod); +bool Usr_ICanChangeOtherUsrData (const struct UsrData *UsrDat); bool Usr_CheckIfIAsAdminCanEditOtherUsr (const struct UsrData *UsrDat); unsigned Usr_GetNumCrssOfUsr (long UsrCod);