diff --git a/swad_changelog.h b/swad_changelog.h index 838a1b37..4472c14a 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -598,10 +598,11 @@ TODO: DNI de un estudiante sale err TODO: BUG: Cuando un tipo de grupo sólo tiene un grupo, inscribirse es voluntario, el estudiante sólo puede pertenecer a un grupo, y se inscribe en él, debería poder desapuntarse. Ahora no puede. TODO: Salvador Romero Cortés: @acanas opción para editar posts */ -#define Log_PLATFORM_VERSION "SWAD 20.39.10 (2021-03-02)" +#define Log_PLATFORM_VERSION "SWAD 20.39.11 (2021-03-02)" #define CSS_FILE "swad20.33.9.css" #define JS_FILE "swad20.6.2.js" /* + Version 20.39.11: Mar 02, 2021 Code refactoring in fav/share timeline. (305525 lines) Version 20.39.10: Mar 02, 2021 Code refactoring in timeline. (305576 lines) Version 20.39.9: Mar 02, 2021 Code refactoring in timeline. (305580 lines) Version 20.39.8: Mar 02, 2021 Code refactoring in timeline. (305573 lines) diff --git a/swad_text.c b/swad_text.c index 3a128b33..840c7c53 100644 --- a/swad_text.c +++ b/swad_text.c @@ -46594,27 +46594,6 @@ const char *Txt_The_centre_X_has_been_renamed_as_Y = // Warning: it is very impo "O centro %s foi renomeado como %s."; #endif -const char *Txt_The_comment_no_longer_exists = -#if L==1 // ca - "El comentari ja no existeix."; -#elif L==2 // de - "Der Kommentar nicht mehr existiert."; -#elif L==3 // en - "The comment no longer exists."; -#elif L==4 // es - "El comentario ya no existe."; -#elif L==5 // fr - "Le commentaire a disparu."; -#elif L==6 // gn - "El comentario ya no existe."; // Okoteve traducción -#elif L==7 // it - "Il commento non esiste più."; -#elif L==8 // pl - "Komentarz już nie istnieje."; -#elif L==9 // pt - "O comentário não existe mais."; -#endif - const char *Txt_The_configuration_of_the_projects_has_been_updated = #if L==1 // ca "La configuració dels projectes s'ha actualitzat."; @@ -49660,25 +49639,25 @@ const char *Txt_The_photo_no_longer_exists = "La foto não existe mais."; #endif -const char *Txt_The_original_post_no_longer_exists = +const char *Txt_The_post_no_longer_exists = #if L==1 // ca - "La publicació original ja no existeix."; + "La publicació ja no existeix."; #elif L==2 // de - "Der ursprüngliche Post nicht mehr existiert."; + "Der Post nicht mehr existiert."; #elif L==3 // en - "The original post no longer exists."; + "The post no longer exists."; #elif L==4 // es - "La publicación original ya no existe."; + "La publicación ya no existe."; #elif L==5 // fr - "Le post original a disparu."; + "Le post a disparu."; #elif L==6 // gn - "La publicación original ya no existe."; // Okoteve traducción + "La publicación ya no existe."; // Okoteve traducción #elif L==7 // it - "La pubblicazione originale non esiste più."; + "La pubblicazione non esiste più."; #elif L==8 // pl - "Oryginalna publikacja już nie istnieje."; + "Publikacja już nie istnieje."; #elif L==9 // pt - "A publicação original não existe mais."; + "A publicação não existe mais."; #endif const char *Txt_The_password_can_not_consist_only_of_digits = diff --git a/swad_timeline_comment.c b/swad_timeline_comment.c index 34168f29..3cec0258 100644 --- a/swad_timeline_comment.c +++ b/swad_timeline_comment.c @@ -726,7 +726,7 @@ void TL_Com_ReceiveCommGbl (void) static long TL_Com_ReceiveComm (void) { - extern const char *Txt_The_original_post_no_longer_exists; + extern const char *Txt_The_post_no_longer_exists; struct TL_Pst_PostContent Content; struct TL_Not_Note Not; struct TL_Pub_Publication Pub; @@ -738,7 +738,7 @@ static long TL_Com_ReceiveComm (void) /***** Trivial check: note code *****/ if (Not.NotCod <= 0) { - Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists); + Ale_ShowAlert (Ale_WARNING,Txt_The_post_no_longer_exists); return -1L; } @@ -831,7 +831,7 @@ void TL_Com_RequestRemComGbl (void) static void TL_Com_RequestRemovalComm (struct TL_Timeline *Timeline) { - extern const char *Txt_The_comment_no_longer_exists; + extern const char *Txt_The_post_no_longer_exists; extern const char *Txt_Do_you_really_want_to_remove_the_following_comment; struct TL_Com_Comment Com; @@ -846,7 +846,7 @@ static void TL_Com_RequestRemovalComm (struct TL_Timeline *Timeline) if (Com.PubCod <= 0) { Med_MediaDestructor (&Com.Content.Media); - Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists); + Ale_ShowAlert (Ale_WARNING,Txt_The_post_no_longer_exists); return; } @@ -950,7 +950,7 @@ void TL_Com_RemoveComGbl (void) static void TL_Com_RemoveComm (void) { - extern const char *Txt_The_comment_no_longer_exists; + extern const char *Txt_The_post_no_longer_exists; extern const char *Txt_Comment_removed; struct TL_Com_Comment Com; @@ -965,7 +965,7 @@ static void TL_Com_RemoveComm (void) if (Com.PubCod <= 0) { Med_MediaDestructor (&Com.Content.Media); - Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists); + Ale_ShowAlert (Ale_WARNING,Txt_The_post_no_longer_exists); return; } @@ -1094,42 +1094,3 @@ static void TL_Com_ResetComm (struct TL_Com_Comment *Com) Com->Content.Txt[0] = '\0'; Com->NumFavs = 0; } - -/*****************************************************************************/ -/******************* Check if I can fav/share a comment **********************/ -/*****************************************************************************/ - -bool TL_Com_CheckICanFavShaComm (struct TL_Com_Comment *Com) - { - extern const char *Txt_The_comment_no_longer_exists; - - /***** Get data of comment *****/ - Com->PubCod = TL_Pub_GetParamPubCod (); - TL_Com_GetDataOfCommByCod (Com); - - /***** Trivial check 1: publication code should be > 0 *****/ - if (Com->PubCod <= 0) - { - Med_MediaDestructor (&Com->Content.Media); - Ale_ShowAlert (Ale_WARNING,Txt_The_comment_no_longer_exists); - return false; - } - - /***** Trivial check 2: I must be logged *****/ - if (!Gbl.Usrs.Me.Logged) - { - Med_MediaDestructor (&Com->Content.Media); - Ale_ShowAlert (Ale_ERROR,"You are not logged."); - return false; - } - - /***** Trivial check 3: The author can not fav his/her own comments *****/ - if (Usr_ItsMe (Com->UsrCod)) - { - Med_MediaDestructor (&Com->Content.Media); - Ale_ShowAlert (Ale_ERROR,"You can not fav/unfav your own comments."); - return false; - } - - return true; - } diff --git a/swad_timeline_comment.h b/swad_timeline_comment.h index 8a0bf5ce..3747fdbb 100644 --- a/swad_timeline_comment.h +++ b/swad_timeline_comment.h @@ -77,6 +77,4 @@ void TL_Com_RemoveCommMediaAndDBEntries (long PubCod); void TL_Com_GetDataOfCommByCod (struct TL_Com_Comment *Com); -bool TL_Com_CheckICanFavShaComm (struct TL_Com_Comment *Com); - #endif diff --git a/swad_timeline_favourite.c b/swad_timeline_favourite.c index 84d85646..94894591 100644 --- a/swad_timeline_favourite.c +++ b/swad_timeline_favourite.c @@ -145,13 +145,16 @@ static void TL_Fav_FavNote (struct TL_Not_Note *Not) { long OriginalPubCod; - /***** Get data of note and do some checks *****/ - if (!TL_Not_CheckICanFavShaNote (Not)) + /***** Get data of note *****/ + Not->NotCod = TL_Not_GetParamNotCod (); + TL_Not_GetDataOfNoteByCod (Not); + + /***** Do some checks *****/ + if (!TL_Usr_CheckICanFavSha (Not->NotCod,Not->UsrCod)) return; /***** Trivial check: Have I faved this note? *****/ if (TL_DB_CheckIfFavedByUsr (TL_Fav_NOTE,Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod)) - // Don't show error message return; /***** Mark note as favourite in database *****/ @@ -173,13 +176,16 @@ static void TL_Fav_UnfNote (struct TL_Not_Note *Not) { long OriginalPubCod; - /***** Get data of note and do some checks *****/ - if (!TL_Not_CheckICanFavShaNote (Not)) + /***** Get data of note *****/ + Not->NotCod = TL_Not_GetParamNotCod (); + TL_Not_GetDataOfNoteByCod (Not); + + /***** Do some checks *****/ + if (!TL_Usr_CheckICanFavSha (Not->NotCod,Not->UsrCod)) return; /***** Trivial check: Have I faved this note? *****/ if (!TL_DB_CheckIfFavedByUsr (TL_Fav_NOTE,Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod)) - // Don't show error message return; /***** Delete the mark as favourite from database *****/ @@ -270,8 +276,12 @@ static void TL_Fav_FavComm (struct TL_Com_Comment *Com) /***** Initialize image *****/ Med_MediaConstructor (&Com->Content.Media); - /***** Get data of comment and do some checks *****/ - if (!TL_Com_CheckICanFavShaComm (Com)) + /***** Get data of comment *****/ + Com->PubCod = TL_Pub_GetParamPubCod (); + TL_Com_GetDataOfCommByCod (Com); + + /***** Do some checks *****/ + if (!TL_Usr_CheckICanFavSha (Com->PubCod,Com->UsrCod)) { Med_MediaDestructor (&Com->Content.Media); return; @@ -282,7 +292,6 @@ static void TL_Fav_FavComm (struct TL_Com_Comment *Com) Gbl.Usrs.Me.UsrDat.UsrCod)) { Med_MediaDestructor (&Com->Content.Media); - // Don't show error message return; } @@ -307,8 +316,12 @@ static void TL_Fav_UnfComm (struct TL_Com_Comment *Com) /***** Initialize image *****/ Med_MediaConstructor (&Com->Content.Media); - /***** Get data of comment and do some checks *****/ - if (!TL_Com_CheckICanFavShaComm (Com)) + /***** Get data of comment *****/ + Com->PubCod = TL_Pub_GetParamPubCod (); + TL_Com_GetDataOfCommByCod (Com); + + /***** Do some checks *****/ + if (!TL_Usr_CheckICanFavSha (Com->PubCod,Com->UsrCod)) { Med_MediaDestructor (&Com->Content.Media); return; @@ -319,7 +332,6 @@ static void TL_Fav_UnfComm (struct TL_Com_Comment *Com) Gbl.Usrs.Me.UsrDat.UsrCod)) { Med_MediaDestructor (&Com->Content.Media); - // Don't show error message return; } diff --git a/swad_timeline_note.c b/swad_timeline_note.c index 0cae1d83..41e147a5 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -1118,7 +1118,7 @@ void TL_Not_RequestRemNoteGbl (void) static void TL_Not_RequestRemovalNote (struct TL_Timeline *Timeline) { - extern const char *Txt_The_original_post_no_longer_exists; + extern const char *Txt_The_post_no_longer_exists; extern const char *Txt_Do_you_really_want_to_remove_the_following_post; struct TL_Not_Note Not; @@ -1129,7 +1129,7 @@ static void TL_Not_RequestRemovalNote (struct TL_Timeline *Timeline) /***** Trivial check 1: note code should be > 0 *****/ if (Not.NotCod <= 0) { - Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists); + Ale_ShowAlert (Ale_WARNING,Txt_The_post_no_longer_exists); return; } @@ -1223,7 +1223,7 @@ void TL_Not_RemoveNoteGbl (void) static void TL_Not_RemoveNote (void) { - extern const char *Txt_The_original_post_no_longer_exists; + extern const char *Txt_The_post_no_longer_exists; extern const char *Txt_TIMELINE_Post_removed; struct TL_Not_Note Not; @@ -1234,7 +1234,7 @@ static void TL_Not_RemoveNote (void) /***** Trivial check 1: note code should be > 0 *****/ if (Not.NotCod <= 0) { - Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists); + Ale_ShowAlert (Ale_WARNING,Txt_The_post_no_longer_exists); return; } @@ -1424,39 +1424,3 @@ void TL_Not_GetDataOfNoteByCod (struct TL_Not_Note *Not) /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); } - -/*****************************************************************************/ -/******************** Check if I can fav/share a note ************************/ -/*****************************************************************************/ - -bool TL_Not_CheckICanFavShaNote (struct TL_Not_Note *Not) - { - extern const char *Txt_The_original_post_no_longer_exists; - - /***** Get data of note *****/ - Not->NotCod = TL_Not_GetParamNotCod (); - TL_Not_GetDataOfNoteByCod (Not); - - /***** Trivial check 1: note code should be > 0 *****/ - if (Not->NotCod <= 0) - { - Ale_ShowAlert (Ale_WARNING,Txt_The_original_post_no_longer_exists); - return false; - } - - /***** Trivial check 2: I must be logged *****/ - if (!Gbl.Usrs.Me.Logged) - { - Ale_ShowAlert (Ale_ERROR,"You are not logged."); - return false; - } - - /***** Trivial check 3: The author can not unfav his/her own notes *****/ - if (Usr_ItsMe (Not->UsrCod)) - { - Ale_ShowAlert (Ale_ERROR,"You can not fav/share your own posts."); - return false; - } - - return true; - } diff --git a/swad_timeline_note.h b/swad_timeline_note.h index d1232310..2a6ee453 100644 --- a/swad_timeline_note.h +++ b/swad_timeline_note.h @@ -113,6 +113,4 @@ void TL_Not_RemoveNoteGbl (void); void TL_Not_GetDataOfNoteByCod (struct TL_Not_Note *Not); -bool TL_Not_CheckICanFavShaNote (struct TL_Not_Note *Not); - #endif diff --git a/swad_timeline_share.c b/swad_timeline_share.c index 858aeabc..b9480a77 100644 --- a/swad_timeline_share.c +++ b/swad_timeline_share.c @@ -118,13 +118,16 @@ static void TL_Sha_ShaNote (struct TL_Not_Note *Not) struct TL_Pub_Publication Pub; long OriginalPubCod; - /***** Get data of note and do some checks *****/ - if (!TL_Not_CheckICanFavShaNote (Not)) + /***** Get data of note *****/ + Not->NotCod = TL_Not_GetParamNotCod (); + TL_Not_GetDataOfNoteByCod (Not); + + /***** Do some checks *****/ + if (!TL_Usr_CheckICanFavSha (Not->NotCod,Not->UsrCod)) return; /***** Trivial check: Is note already shared by me? *****/ if (TL_DB_CheckIfNoteIsSharedByUsr (Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod)) - // Don't show error message return; /***** Share (publish note in timeline) *****/ @@ -172,13 +175,12 @@ static void TL_Sha_UnsNote (struct TL_Not_Note *Not) { long OriginalPubCod; - /***** Get data of note and do some checks *****/ - if (!TL_Not_CheckICanFavShaNote (Not)) - return; + /***** Get data of note *****/ + Not->NotCod = TL_Not_GetParamNotCod (); + TL_Not_GetDataOfNoteByCod (Not); - /***** Trivial check: Is note already shared by me? *****/ - if (!TL_DB_CheckIfNoteIsSharedByUsr (Not->NotCod,Gbl.Usrs.Me.UsrDat.UsrCod)) - // Don't show error message + /***** Do some checks *****/ + if (!TL_Usr_CheckICanFavSha (Not->NotCod,Not->UsrCod)) return; /***** Delete publication from database *****/ diff --git a/swad_timeline_user.c b/swad_timeline_user.c index 92e19b57..19ae9886 100644 --- a/swad_timeline_user.c +++ b/swad_timeline_user.c @@ -162,3 +162,29 @@ void TL_Usr_ShowSharersOrFavers (MYSQL_RES **mysql_res, /***** Free memory used for user's data *****/ Usr_UsrDataDestructor (&UsrDat); } + +/*****************************************************************************/ +/***************** Check if I can fav/share a note/comment *******************/ +/*****************************************************************************/ + +bool TL_Usr_CheckICanFavSha (long Cod,long UsrCod) + { + extern const char *Txt_The_post_no_longer_exists; + + /***** Trivial check 1: note/comment code should be > 0 *****/ + if (Cod <= 0) + { + Ale_ShowAlert (Ale_WARNING,Txt_The_post_no_longer_exists); + return false; + } + + /***** Trivial check 2: I must be logged + I can not fav/share my own notes/comments *****/ + if (!Gbl.Usrs.Me.Logged || Usr_ItsMe (UsrCod)) + { + Lay_NoPermissionExit (); + return false; // Not reached + } + + return true; + } diff --git a/swad_timeline_user.h b/swad_timeline_user.h index c620636c..53987980 100644 --- a/swad_timeline_user.h +++ b/swad_timeline_user.h @@ -64,5 +64,6 @@ void TL_Usr_RemoveUsrContent (long UsrCod); void TL_Usr_ShowNumSharersOrFavers (unsigned NumUsrs); void TL_Usr_ShowSharersOrFavers (MYSQL_RES **mysql_res, unsigned NumUsrs,unsigned NumFirstUsrs); +bool TL_Usr_CheckICanFavSha (long Cod,long UsrCod); #endif