From cfdfdc7c5fdb9e977eb1662d75d667c26b38f368 Mon Sep 17 00:00:00 2001 From: acanas Date: Wed, 3 Mar 2021 21:53:43 +0100 Subject: [PATCH] Version 20.41.2: Mar 03, 2021 Code refactoring in timeline. --- swad_changelog.h | 3 +- swad_timeline_comment.c | 16 ++------ swad_timeline_favourite.c | 8 ++-- swad_timeline_note.c | 15 +------- swad_timeline_share.c | 4 +- swad_timeline_user.c | 78 ++++++++++++++++++++++++++------------- swad_timeline_user.h | 4 +- 7 files changed, 69 insertions(+), 59 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index a18971e9..41206442 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.41.1 (2021-03-03)" +#define Log_PLATFORM_VERSION "SWAD 20.41.2 (2021-03-03)" #define CSS_FILE "swad20.33.9.css" #define JS_FILE "swad20.6.2.js" /* + Version 20.41.2: Mar 03, 2021 Code refactoring in timeline. (? lines) Version 20.41.1: Mar 03, 2021 Code refactoring in timeline posts. (305563 lines) Version 20.41: Mar 03, 2021 Code refactoring in timeline comments. (305542 lines) Version 20.40.3: Mar 03, 2021 Code refactoring in timeline. (305528 lines) diff --git a/swad_timeline_comment.c b/swad_timeline_comment.c index 3c4f9d34..51f1ce0f 100644 --- a/swad_timeline_comment.c +++ b/swad_timeline_comment.c @@ -494,6 +494,7 @@ static void TL_Com_PutIconToToggleComms (const char *UniqueId, extern const char *The_ClassFormLinkInBox[The_NUM_THEMES]; char *OnClick; + /***** Build onclick text *****/ if (asprintf (&OnClick,"toggleComments('%s')",UniqueId) < 0) Lay_NotEnoughMemoryExit (); @@ -502,6 +503,7 @@ static void TL_Com_PutIconToToggleComms (const char *UniqueId, Ico_PutIconTextLink (Icon,Text); HTM_BUTTON_End (); + /***** Free onclick text *****/ free (OnClick); } @@ -842,7 +844,6 @@ void TL_Com_RequestRemComGbl (void) static void TL_Com_RequestRemovalComm (struct TL_Timeline *Timeline) { - 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; @@ -853,19 +854,10 @@ static void TL_Com_RequestRemovalComm (struct TL_Timeline *Timeline) Com.PubCod = TL_Pub_GetParamPubCod (); TL_Com_GetDataOfCommByCod (&Com); - /***** Trivial check 1: publication code *****/ - if (Com.PubCod <= 0) + /***** Do some checks *****/ + if (!TL_Usr_CheckIfICanRemove (Com.PubCod,Com.UsrCod)) { Med_MediaDestructor (&Com.Content.Media); - Ale_ShowAlert (Ale_WARNING,Txt_The_post_no_longer_exists); - return; - } - - /***** Trivial check 2: only if I am the author of this comment *****/ - if (!Usr_ItsMe (Com.UsrCod)) - { - Med_MediaDestructor (&Com.Content.Media); - Ale_ShowAlert (Ale_ERROR,"You are not the author."); return; } diff --git a/swad_timeline_favourite.c b/swad_timeline_favourite.c index fb48062b..c340a44a 100644 --- a/swad_timeline_favourite.c +++ b/swad_timeline_favourite.c @@ -146,7 +146,7 @@ static void TL_Fav_FavNote (struct TL_Not_Note *Not) TL_Not_GetDataOfNoteByCod (Not); /***** Do some checks *****/ - if (!TL_Usr_CheckICanFavSha (Not->NotCod,Not->UsrCod)) + if (!TL_Usr_CheckIfICanFavSha (Not->NotCod,Not->UsrCod)) return; /***** Trivial check: Have I faved this note? *****/ @@ -177,7 +177,7 @@ static void TL_Fav_UnfNote (struct TL_Not_Note *Not) TL_Not_GetDataOfNoteByCod (Not); /***** Do some checks *****/ - if (!TL_Usr_CheckICanFavSha (Not->NotCod,Not->UsrCod)) + if (!TL_Usr_CheckIfICanFavSha (Not->NotCod,Not->UsrCod)) return; /***** Trivial check: Have I faved this note? *****/ @@ -285,7 +285,7 @@ static void TL_Fav_FavComm (struct TL_Com_Comment *Com) TL_Com_GetDataOfCommByCod (Com); /***** Do some checks *****/ - if (!TL_Usr_CheckICanFavSha (Com->PubCod,Com->UsrCod)) + if (!TL_Usr_CheckIfICanFavSha (Com->PubCod,Com->UsrCod)) { Med_MediaDestructor (&Com->Content.Media); return; @@ -324,7 +324,7 @@ static void TL_Fav_UnfComm (struct TL_Com_Comment *Com) TL_Com_GetDataOfCommByCod (Com); /***** Do some checks *****/ - if (!TL_Usr_CheckICanFavSha (Com->PubCod,Com->UsrCod)) + if (!TL_Usr_CheckIfICanFavSha (Com->PubCod,Com->UsrCod)) { Med_MediaDestructor (&Com->Content.Media); return; diff --git a/swad_timeline_note.c b/swad_timeline_note.c index 436e2291..378a9d75 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -1121,7 +1121,6 @@ void TL_Not_RequestRemNoteGbl (void) static void TL_Not_RequestRemovalNote (struct TL_Timeline *Timeline) { - 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,19 +1128,9 @@ static void TL_Not_RequestRemovalNote (struct TL_Timeline *Timeline) 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_post_no_longer_exists); + /***** Do some checks *****/ + if (!TL_Usr_CheckIfICanRemove (Not.NotCod,Not.UsrCod)) return; - } - - /***** Trivial check 2: Am I the author of this note *****/ - if (!Usr_ItsMe (Not.UsrCod)) - { - Ale_ShowAlert (Ale_ERROR,"You are not the author."); - return; - } /***** Show question and button to remove note *****/ /* Begin alert */ diff --git a/swad_timeline_share.c b/swad_timeline_share.c index a1496312..46a1f400 100644 --- a/swad_timeline_share.c +++ b/swad_timeline_share.c @@ -122,7 +122,7 @@ static void TL_Sha_ShaNote (struct TL_Not_Note *Not) TL_Not_GetDataOfNoteByCod (Not); /***** Do some checks *****/ - if (!TL_Usr_CheckICanFavSha (Not->NotCod,Not->UsrCod)) + if (!TL_Usr_CheckIfICanFavSha (Not->NotCod,Not->UsrCod)) return; /***** Trivial check: Is note already shared by me? *****/ @@ -181,7 +181,7 @@ static void TL_Sha_UnsNote (struct TL_Not_Note *Not) TL_Not_GetDataOfNoteByCod (Not); /***** Do some checks *****/ - if (!TL_Usr_CheckICanFavSha (Not->NotCod,Not->UsrCod)) + if (!TL_Usr_CheckIfICanFavSha (Not->NotCod,Not->UsrCod)) return; /***** Delete publication from database *****/ diff --git a/swad_timeline_user.c b/swad_timeline_user.c index 73b51190..2ebdbcaa 100644 --- a/swad_timeline_user.c +++ b/swad_timeline_user.c @@ -232,32 +232,6 @@ static void TL_Usr_ListSharersOrFavers (MYSQL_RES **mysql_res, 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; - } - /*****************************************************************************/ /************* Check if a user has faved/shared a note/comment ***************/ /*****************************************************************************/ @@ -365,3 +339,55 @@ static void TL_Usr_PutDisabledIconFavSha (TL_Usr_FavSha_t FavSha, else Ico_PutDivIcon ("TL_ICO_DISABLED",Icon[FavSha],TitleWithoutUsrs[FavSha]); } + +/*****************************************************************************/ +/***************** Check if I can fav/share a note/comment *******************/ +/*****************************************************************************/ + +bool TL_Usr_CheckIfICanFavSha (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; + } + +/*****************************************************************************/ +/***************** Check if I can fav/share a note/comment *******************/ +/*****************************************************************************/ + +bool TL_Usr_CheckIfICanRemove (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 only remove 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 77b590e3..f86d65fe 100644 --- a/swad_timeline_user.h +++ b/swad_timeline_user.h @@ -69,11 +69,13 @@ typedef enum void TL_Usr_RemoveUsrContent (long UsrCod); -bool TL_Usr_CheckICanFavSha (long Cod,long UsrCod); bool TL_Usr_CheckIfFavedSharedByUsr (TL_Usr_FavSha_t FavSha,long Cod,long UsrCod); void TL_Usr_PutIconFavSha (TL_Usr_FavSha_t FavSha, long Cod,long UsrCod,unsigned NumUsrs, TL_Usr_HowManyUsrs_t HowManyUsrs); +bool TL_Usr_CheckIfICanFavSha (long Cod,long UsrCod); +bool TL_Usr_CheckIfICanRemove (long Cod,long UsrCod); + #endif