Version 20.41.2: Mar 03, 2021 Code refactoring in timeline.

This commit is contained in:
acanas 2021-03-03 21:53:43 +01:00
parent cae52f721c
commit cfdfdc7c5f
7 changed files with 69 additions and 59 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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;

View File

@ -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 */

View File

@ -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 *****/

View File

@ -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;
}

View File

@ -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