mirror of https://github.com/acanas/swad-core.git
Version 16.247.2
This commit is contained in:
parent
2daf60960b
commit
4499b07d3b
|
@ -236,13 +236,15 @@
|
||||||
/****************************** Public constants *****************************/
|
/****************************** Public constants *****************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
#define Log_PLATFORM_VERSION "SWAD 16.247.1 (2017-06-23)"
|
#define Log_PLATFORM_VERSION "SWAD 16.247.2 (2017-06-23)"
|
||||||
#define CSS_FILE "swad16.235.1.css"
|
#define CSS_FILE "swad16.235.1.css"
|
||||||
#define JS_FILE "swad16.206.3.js"
|
#define JS_FILE "swad16.206.3.js"
|
||||||
|
|
||||||
// Number of lines (includes comments but not blank lines) has been got with the following command:
|
// 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
|
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1
|
||||||
/*
|
/*
|
||||||
|
Version 16.247.2: Jun 23, 2017 Non-editing teachers can not view records of users who do not share groups with them.
|
||||||
|
Code refactoring related with roles. (222094 lines)
|
||||||
Version 16.247.1: Jun 23, 2017 Non-editing teachers can select all groups when writing a message. (222068 lines)
|
Version 16.247.1: Jun 23, 2017 Non-editing teachers can select all groups when writing a message. (222068 lines)
|
||||||
Version 16.247: Jun 20, 2017 Fixed bug when removing a user from a course.
|
Version 16.247: Jun 20, 2017 Fixed bug when removing a user from a course.
|
||||||
Code refactoring related with caches. (222063 lines)
|
Code refactoring related with caches. (222063 lines)
|
||||||
|
|
|
@ -230,8 +230,8 @@ void Enr_ModifyRoleInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole)
|
||||||
activate the sending of a notification *****/
|
activate the sending of a notification *****/
|
||||||
Enr_NotifyAfterEnrolment (UsrDat,NewRole);
|
Enr_NotifyAfterEnrolment (UsrDat,NewRole);
|
||||||
|
|
||||||
UsrDat->Roles.InCurrentCrs.Role = NewRole;
|
UsrDat->Roles.InCurrentCrs.Role = NewRole;
|
||||||
UsrDat->Roles.InCurrentCrs.GotFromDBForUsrCod = UsrDat->UsrCod;
|
UsrDat->Roles.InCurrentCrs.Valid = true;
|
||||||
UsrDat->Roles.InCrss = -1; // Force roles to be got from database
|
UsrDat->Roles.InCrss = -1; // Force roles to be got from database
|
||||||
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat); // Get roles
|
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat); // Get roles
|
||||||
}
|
}
|
||||||
|
@ -279,8 +279,8 @@ void Enr_RegisterUsrInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole,
|
||||||
Usr_LIST_WITH_PHOTOS_DEF ? 'Y' :
|
Usr_LIST_WITH_PHOTOS_DEF ? 'Y' :
|
||||||
'N');
|
'N');
|
||||||
DB_QueryINSERT (Query,"can not register user in course");
|
DB_QueryINSERT (Query,"can not register user in course");
|
||||||
UsrDat->Roles.InCurrentCrs.Role = NewRole;
|
UsrDat->Roles.InCurrentCrs.Role = NewRole;
|
||||||
UsrDat->Roles.InCurrentCrs.GotFromDBForUsrCod = UsrDat->UsrCod;
|
UsrDat->Roles.InCurrentCrs.Valid = true;
|
||||||
UsrDat->Roles.InCrss = -1; // Force roles to be got from database
|
UsrDat->Roles.InCrss = -1; // Force roles to be got from database
|
||||||
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat); // Get roles
|
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat); // Get roles
|
||||||
|
|
||||||
|
@ -3921,8 +3921,8 @@ void Enr_ModifyUsr1 (void)
|
||||||
/***** If it's me, change my roles *****/
|
/***** If it's me, change my roles *****/
|
||||||
if (ItsMe)
|
if (ItsMe)
|
||||||
{
|
{
|
||||||
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role = Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs.Role;
|
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role = Gbl.Usrs.Other.UsrDat.Roles.InCurrentCrs.Role;
|
||||||
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.GotFromDBForUsrCod = Gbl.Usrs.Other.UsrDat.UsrCod;
|
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Valid = true;
|
||||||
Gbl.Usrs.Me.UsrDat.Roles.InCrss = Gbl.Usrs.Other.UsrDat.Roles.InCrss;
|
Gbl.Usrs.Me.UsrDat.Roles.InCrss = Gbl.Usrs.Other.UsrDat.Roles.InCrss;
|
||||||
Rol_SetMyRoles ();
|
Rol_SetMyRoles ();
|
||||||
}
|
}
|
||||||
|
@ -4202,8 +4202,8 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat,struct Course *
|
||||||
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role =
|
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role =
|
||||||
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
||||||
|
|
||||||
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.GotFromDBForUsrCod =
|
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Valid =
|
||||||
UsrDat->Roles.InCurrentCrs.GotFromDBForUsrCod = UsrDat->UsrCod;
|
UsrDat->Roles.InCurrentCrs.Valid = true;
|
||||||
|
|
||||||
Gbl.Usrs.Me.UsrDat.Roles.InCrss =
|
Gbl.Usrs.Me.UsrDat.Roles.InCrss =
|
||||||
UsrDat->Roles.InCrss = -1; // not yet filled/calculated
|
UsrDat->Roles.InCrss = -1; // not yet filled/calculated
|
||||||
|
|
22
swad_group.c
22
swad_group.c
|
@ -3280,12 +3280,12 @@ bool Grp_GetIfIBelongToGrp (long GrpCod)
|
||||||
sprintf (Query,"SELECT COUNT(*) FROM crs_grp_usr"
|
sprintf (Query,"SELECT COUNT(*) FROM crs_grp_usr"
|
||||||
" WHERE GrpCod=%ld AND UsrCod=%ld",
|
" WHERE GrpCod=%ld AND UsrCod=%ld",
|
||||||
GrpCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
GrpCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||||
Gbl.Cache.IBelongToGrp.IBelong = DB_QueryCOUNT (Query,"can not check if you belong to a group") != 0;
|
|
||||||
Gbl.Cache.IBelongToGrp.GrpCod = GrpCod;
|
Gbl.Cache.IBelongToGrp.GrpCod = GrpCod;
|
||||||
|
Gbl.Cache.IBelongToGrp.IBelong = (DB_QueryCOUNT (Query,"can not check"
|
||||||
|
" if you belong to a group") != 0);
|
||||||
return Gbl.Cache.IBelongToGrp.IBelong;
|
return Gbl.Cache.IBelongToGrp.IBelong;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/*************** Check if a user belongs to any of my courses ****************/
|
/*************** Check if a user belongs to any of my courses ****************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -3333,7 +3333,17 @@ bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** 8. Slow check: Get if user shares any group in this course with me from database *****/
|
/***** 8. Fast check: Course has groups? *****/
|
||||||
|
if (!Gbl.CurrentCrs.Grps.NumGrps)
|
||||||
|
{
|
||||||
|
Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.UsrCod = UsrDat->UsrCod;
|
||||||
|
Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.Shares = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Course has groups
|
||||||
|
|
||||||
|
/***** 9. Slow check: Get if user shares any group in this course with me from database *****/
|
||||||
/* Check if user shares any group with me */
|
/* Check if user shares any group with me */
|
||||||
Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.UsrCod = UsrDat->UsrCod;
|
Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.UsrCod = UsrDat->UsrCod;
|
||||||
sprintf (Query,"SELECT COUNT(*) FROM crs_grp_usr"
|
sprintf (Query,"SELECT COUNT(*) FROM crs_grp_usr"
|
||||||
|
@ -3348,9 +3358,9 @@ bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat)
|
||||||
UsrDat->UsrCod,
|
UsrDat->UsrCod,
|
||||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||||
Gbl.CurrentCrs.Crs.CrsCod);
|
Gbl.CurrentCrs.Crs.CrsCod);
|
||||||
Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.Shares = DB_QueryCOUNT (Query,"can not check"
|
Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.Shares = (DB_QueryCOUNT (Query,"can not check"
|
||||||
" if a user shares any group"
|
" if a user shares any group"
|
||||||
" in the current course with you") != 0;
|
" in the current course with you") != 0);
|
||||||
return Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.Shares;
|
return Gbl.Cache.UsrSharesAnyOfMyGrpsInCurrentCrs.Shares;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -287,7 +287,7 @@ bool Prf_ShowUserProfile (struct UsrData *UsrDat)
|
||||||
/* Get user's role in current course */
|
/* Get user's role in current course */
|
||||||
UsrDat->Roles.InCurrentCrs.Role = Rol_GetRoleUsrInCrs (UsrDat->UsrCod,
|
UsrDat->Roles.InCurrentCrs.Role = Rol_GetRoleUsrInCrs (UsrDat->UsrCod,
|
||||||
Gbl.CurrentCrs.Crs.CrsCod);
|
Gbl.CurrentCrs.Crs.CrsCod);
|
||||||
UsrDat->Roles.InCurrentCrs.GotFromDBForUsrCod = UsrDat->UsrCod;
|
UsrDat->Roles.InCurrentCrs.Valid = true;
|
||||||
|
|
||||||
/* Get if user has accepted enrolment in current course */
|
/* Get if user has accepted enrolment in current course */
|
||||||
UsrDat->Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (UsrDat);
|
UsrDat->Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (UsrDat);
|
||||||
|
|
|
@ -2137,9 +2137,9 @@ void Rec_ShowFormOtherNewSharedRecord (struct UsrData *UsrDat,Rol_Role_t Default
|
||||||
/* In this case UsrDat->Roles.InCurrentCrsDB
|
/* In this case UsrDat->Roles.InCurrentCrsDB
|
||||||
is not the current role in current course.
|
is not the current role in current course.
|
||||||
Instead it is initialized with the preferred role. */
|
Instead it is initialized with the preferred role. */
|
||||||
UsrDat->Roles.InCurrentCrs.Role = (Gbl.CurrentCrs.Crs.CrsCod > 0) ? DefaultRole : // Course selected
|
UsrDat->Roles.InCurrentCrs.Role = (Gbl.CurrentCrs.Crs.CrsCod > 0) ? DefaultRole : // Course selected
|
||||||
Rol_UNK; // No course selected
|
Rol_UNK; // No course selected
|
||||||
UsrDat->Roles.InCurrentCrs.GotFromDBForUsrCod = UsrDat->UsrCod;
|
UsrDat->Roles.InCurrentCrs.Valid = true;
|
||||||
Rec_ShowSharedUsrRecord (Rec_SHA_OTHER_NEW_USR_FORM,UsrDat,NULL);
|
Rec_ShowSharedUsrRecord (Rec_SHA_OTHER_NEW_USR_FORM,UsrDat,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,10 +68,10 @@ void Rol_SetMyRoles (void)
|
||||||
bool ICanBeDegAdm = false;
|
bool ICanBeDegAdm = false;
|
||||||
|
|
||||||
/***** Get my role in current course if not yet filled *****/
|
/***** Get my role in current course if not yet filled *****/
|
||||||
if (Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.GotFromDBForUsrCod != Gbl.Usrs.Me.UsrDat.UsrCod)
|
if (!Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Valid)
|
||||||
{
|
{
|
||||||
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role = Rol_GetMyRoleInCrs (Gbl.CurrentCrs.Crs.CrsCod);
|
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role = Rol_GetMyRoleInCrs (Gbl.CurrentCrs.Crs.CrsCod);
|
||||||
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.GotFromDBForUsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
|
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** Set the user's role I am logged *****/
|
/***** Set the user's role I am logged *****/
|
||||||
|
|
|
@ -48,13 +48,15 @@ typedef enum
|
||||||
Rol_USR = 2, // Student, non-editing teacher or teacher in some courses...
|
Rol_USR = 2, // Student, non-editing teacher or teacher in some courses...
|
||||||
// ...but no course selected
|
// ...but no course selected
|
||||||
// ...or not belonging to the current course
|
// ...or not belonging to the current course
|
||||||
|
|
||||||
Rol_STD = 3, // Student in the current course
|
Rol_STD = 3, // Student in the current course
|
||||||
Rol_NET = 4, // Non-editing teacher in the current course
|
Rol_NET = 4, // Non-editing teacher in the current course
|
||||||
Rol_TCH = 5, // Old 4 // Teacher in the current course
|
Rol_TCH = 5, // Teacher in the current course
|
||||||
Rol_DEG_ADM = 6, // Old 5 // Degree administrator
|
|
||||||
Rol_CTR_ADM = 7, // Old 6 // Centre administrator
|
Rol_DEG_ADM = 6, // Degree administrator
|
||||||
Rol_INS_ADM = 8, // Old 7 // Institution administrator
|
Rol_CTR_ADM = 7, // Centre administrator
|
||||||
Rol_SYS_ADM = 9, // Old 8 // System administrator (superuser)
|
Rol_INS_ADM = 8, // Institution administrator
|
||||||
|
Rol_SYS_ADM = 9, // System administrator (superuser)
|
||||||
} Rol_Role_t;
|
} Rol_Role_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
94
swad_user.c
94
swad_user.c
|
@ -295,8 +295,8 @@ void Usr_ResetUsrDataExceptUsrCodAndIDs (struct UsrData *UsrDat)
|
||||||
UsrDat->EncryptedUsrCod[0] = '\0';
|
UsrDat->EncryptedUsrCod[0] = '\0';
|
||||||
UsrDat->Nickname[0] = '\0';
|
UsrDat->Nickname[0] = '\0';
|
||||||
UsrDat->Password[0] = '\0';
|
UsrDat->Password[0] = '\0';
|
||||||
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
||||||
UsrDat->Roles.InCurrentCrs.GotFromDBForUsrCod = -1L;
|
UsrDat->Roles.InCurrentCrs.Valid = false;
|
||||||
UsrDat->Roles.InCrss = -1; // < 0 ==> not yet got from database
|
UsrDat->Roles.InCrss = -1; // < 0 ==> not yet got from database
|
||||||
UsrDat->Accepted = true;
|
UsrDat->Accepted = true;
|
||||||
|
|
||||||
|
@ -522,7 +522,7 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat)
|
||||||
/* Get roles */
|
/* Get roles */
|
||||||
UsrDat->Roles.InCurrentCrs.Role = Rol_GetRoleUsrInCrs (UsrDat->UsrCod,
|
UsrDat->Roles.InCurrentCrs.Role = Rol_GetRoleUsrInCrs (UsrDat->UsrCod,
|
||||||
Gbl.CurrentCrs.Crs.CrsCod);
|
Gbl.CurrentCrs.Crs.CrsCod);
|
||||||
UsrDat->Roles.InCurrentCrs.GotFromDBForUsrCod = UsrDat->UsrCod;
|
UsrDat->Roles.InCurrentCrs.Valid = true;
|
||||||
UsrDat->Roles.InCrss = -1; // Force roles to be got from database
|
UsrDat->Roles.InCrss = -1; // Force roles to be got from database
|
||||||
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat);
|
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat);
|
||||||
|
|
||||||
|
@ -1045,16 +1045,45 @@ unsigned Usr_GetNumUsrsInCrssOfAUsr (long UsrCod,Rol_Role_t UsrRole,
|
||||||
|
|
||||||
bool Usr_CheckIfICanViewRecordStd (const struct UsrData *UsrDat)
|
bool Usr_CheckIfICanViewRecordStd (const struct UsrData *UsrDat)
|
||||||
{
|
{
|
||||||
if (UsrDat->Roles.InCurrentCrs.Role != Rol_STD) // Not a student in the current course
|
/***** 1. Fast check: Am I logged? *****/
|
||||||
|
if (!Gbl.Usrs.Me.Logged)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// The user is a student in the current course
|
/***** 2. Fast check: Is it a valid user code? *****/
|
||||||
|
if (UsrDat->UsrCod <= 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/***** 3. Fast check: Is it a course selected? *****/
|
||||||
|
if (Gbl.CurrentCrs.Crs.CrsCod <= 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/***** 4. Fast check: Is he/she a student? *****/
|
||||||
|
if (UsrDat->Roles.InCurrentCrs.Role != Rol_STD)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/***** 5. Fast check: Am I a system admin? *****/
|
||||||
|
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
/***** 6. Fast check: Do I belong to the current course? *****/
|
||||||
|
if (!Gbl.Usrs.Me.IBelongToCurrentCrs)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/***** 7. Fast check: It's me? *****/
|
||||||
|
if (Gbl.Usrs.Me.UsrDat.UsrCod == UsrDat->UsrCod)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
/***** 8. Fast / slow check: Does he/she belong to the current course? *****/
|
||||||
|
if (!Usr_CheckIfUsrBelongsToCurrentCrs (UsrDat))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/***** 9. Fast / slow check depending on roles *****/
|
||||||
switch (Gbl.Usrs.Me.Role.Logged)
|
switch (Gbl.Usrs.Me.Role.Logged)
|
||||||
{
|
{
|
||||||
case Rol_STD:
|
case Rol_STD:
|
||||||
case Rol_NET:
|
case Rol_NET:
|
||||||
|
return Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (UsrDat);
|
||||||
case Rol_TCH:
|
case Rol_TCH:
|
||||||
case Rol_SYS_ADM:
|
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -1074,23 +1103,39 @@ bool Usr_CheckIfICanViewRecordTch (struct UsrData *UsrDat)
|
||||||
if (!Gbl.Usrs.Me.Logged)
|
if (!Gbl.Usrs.Me.Logged)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/***** 2. Fast/slow check: Is he/she a non-editing teacher or a teacher in any course? *****/
|
/***** 2. Fast check: Is it a valid user code? *****/
|
||||||
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat);
|
if (UsrDat->UsrCod <= 0)
|
||||||
if ((UsrDat->Roles.InCrss & ((1 << Rol_NET) |
|
|
||||||
(1 << Rol_TCH))) == 0)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// He/she is a non-editing teacher or a teacher in any course
|
if (Gbl.CurrentCrs.Crs.CrsCod > 0) // Course selected
|
||||||
|
{
|
||||||
|
/***** 3. Fast check: Is he/she a non-editing teacher or a teacher? *****/
|
||||||
|
if (UsrDat->Roles.InCurrentCrs.Role != Rol_NET &&
|
||||||
|
UsrDat->Roles.InCurrentCrs.Role != Rol_TCH)
|
||||||
|
return false;
|
||||||
|
|
||||||
/***** 3. Fast check: It's me? *****/
|
// He/she is a non-editing teacher or a teacher in this course
|
||||||
|
}
|
||||||
|
else // No course selected
|
||||||
|
{
|
||||||
|
/***** 3. Fast/slow check: Is he/she a non-editing teacher or a teacher in any course? *****/
|
||||||
|
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat);
|
||||||
|
if ((UsrDat->Roles.InCrss & ((1 << Rol_NET) |
|
||||||
|
(1 << Rol_TCH))) == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// He/she is a non-editing teacher or a teacher in any course
|
||||||
|
}
|
||||||
|
|
||||||
|
/***** 4. Fast check: It's me? *****/
|
||||||
if (Gbl.Usrs.Me.UsrDat.UsrCod == UsrDat->UsrCod)
|
if (Gbl.Usrs.Me.UsrDat.UsrCod == UsrDat->UsrCod)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
/***** 4. Fast check: Am I logged as system admin? *****/
|
/***** 5. Fast check: Am I a system admin? *****/
|
||||||
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
|
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
/***** 5. Slow check: Get if user shares any course with me from database *****/
|
/***** 6. Slow check: Get if user shares any course with me from database *****/
|
||||||
return Usr_CheckIfUsrSharesAnyOfMyCrs (UsrDat);
|
return Usr_CheckIfUsrSharesAnyOfMyCrs (UsrDat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1112,25 +1157,28 @@ bool Usr_CheckIfICanViewWrkTstAtt (const struct UsrData *UsrDat)
|
||||||
if (Gbl.CurrentCrs.Crs.CrsCod <= 0)
|
if (Gbl.CurrentCrs.Crs.CrsCod <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/***** 4. Fast check: Do I belong to the current course? *****/
|
/***** 4. Fast check: Am I a system admin? *****/
|
||||||
|
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
/***** 5. Fast check: Do I belong to the current course? *****/
|
||||||
if (!Gbl.Usrs.Me.IBelongToCurrentCrs)
|
if (!Gbl.Usrs.Me.IBelongToCurrentCrs)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/***** 5. Fast check: It's me? *****/
|
/***** 6. Fast check: It's me? *****/
|
||||||
if (Gbl.Usrs.Me.UsrDat.UsrCod == UsrDat->UsrCod)
|
if (Gbl.Usrs.Me.UsrDat.UsrCod == UsrDat->UsrCod)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
/***** 6. Fast check: Does he/she belong to the current course? *****/
|
/***** 7. Fast check: Does he/she belong to the current course? *****/
|
||||||
if (!Usr_CheckIfUsrBelongsToCurrentCrs (UsrDat))
|
if (!Usr_CheckIfUsrBelongsToCurrentCrs (UsrDat))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/***** 7. Fast / slow check depending on roles *****/
|
/***** 8. Fast / slow check depending on roles *****/
|
||||||
switch (Gbl.Usrs.Me.Role.Logged)
|
switch (Gbl.Usrs.Me.Role.Logged)
|
||||||
{
|
{
|
||||||
case Rol_NET:
|
case Rol_NET:
|
||||||
return Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (UsrDat);
|
return Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (UsrDat);
|
||||||
case Rol_TCH:
|
case Rol_TCH:
|
||||||
case Rol_SYS_ADM:
|
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -1197,8 +1245,8 @@ bool Usr_CheckIfUsrSharesAnyOfMyCrs (struct UsrData *UsrDat)
|
||||||
/***** 6. Fast/slow check: Does he/she belong to any course? *****/
|
/***** 6. Fast/slow check: Does he/she belong to any course? *****/
|
||||||
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat);
|
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat);
|
||||||
if (!(UsrDat->Roles.InCrss & ((1 << Rol_STD) | // Any of his/her roles is student
|
if (!(UsrDat->Roles.InCrss & ((1 << Rol_STD) | // Any of his/her roles is student
|
||||||
(1 << Rol_NET) | // or non-editing teacher
|
(1 << Rol_NET) | // or non-editing teacher
|
||||||
(1 << Rol_TCH)))) // or teacher?
|
(1 << Rol_TCH)))) // or teacher?
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/***** 7. Slow check: Get if user shares any course with me from database *****/
|
/***** 7. Slow check: Get if user shares any course with me from database *****/
|
||||||
|
@ -1794,7 +1842,7 @@ bool Usr_CheckIfUsrBelongsToCurrentCrs (const struct UsrData *UsrDat)
|
||||||
return Gbl.Cache.UsrBelongsToCurrentCrs.Belongs;
|
return Gbl.Cache.UsrBelongsToCurrentCrs.Belongs;
|
||||||
|
|
||||||
/***** 3. Fast check: If we know role of user in the current course *****/
|
/***** 3. Fast check: If we know role of user in the current course *****/
|
||||||
if (UsrDat->Roles.InCurrentCrs.GotFromDBForUsrCod == UsrDat->UsrCod)
|
if (UsrDat->Roles.InCurrentCrs.Valid)
|
||||||
{
|
{
|
||||||
Gbl.Cache.UsrBelongsToCurrentCrs.UsrCod = UsrDat->UsrCod;
|
Gbl.Cache.UsrBelongsToCurrentCrs.UsrCod = UsrDat->UsrCod;
|
||||||
Gbl.Cache.UsrBelongsToCurrentCrs.Belongs = UsrDat->Roles.InCurrentCrs.Role == Rol_STD ||
|
Gbl.Cache.UsrBelongsToCurrentCrs.Belongs = UsrDat->Roles.InCurrentCrs.Role == Rol_STD ||
|
||||||
|
@ -3049,7 +3097,7 @@ static void Usr_SetMyPrefsAndRoles (void)
|
||||||
/* Get again my role in this course */
|
/* Get again my role in this course */
|
||||||
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role = Rol_GetRoleUsrInCrs (Gbl.Usrs.Me.UsrDat.UsrCod,
|
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role = Rol_GetRoleUsrInCrs (Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||||
Gbl.CurrentCrs.Crs.CrsCod);
|
Gbl.CurrentCrs.Crs.CrsCod);
|
||||||
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.GotFromDBForUsrCod = Gbl.Usrs.Me.UsrDat.UsrCod;
|
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Valid = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ struct UsrData
|
||||||
{
|
{
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
long GotFromDBForUsrCod; // Role was got from database for this user (used to not retrieve role if already retrieved)
|
bool Valid; // Role is not valid (for examples, it has not been trtriev
|
||||||
Rol_Role_t Role;
|
Rol_Role_t Role;
|
||||||
} InCurrentCrs; // Role in current course (Rol_UNK is no course selected)
|
} InCurrentCrs; // Role in current course (Rol_UNK is no course selected)
|
||||||
int InCrss; // Roles in all his/her courses
|
int InCrss; // Roles in all his/her courses
|
||||||
|
@ -262,10 +262,12 @@ void Usr_FlushCacheUsrBelongsToCurrentCrs (void);
|
||||||
bool Usr_CheckIfUsrBelongsToCurrentCrs (const struct UsrData *UsrDat);
|
bool Usr_CheckIfUsrBelongsToCurrentCrs (const struct UsrData *UsrDat);
|
||||||
void Usr_FlushCacheUsrHasAcceptedInCurrentCrs (void);
|
void Usr_FlushCacheUsrHasAcceptedInCurrentCrs (void);
|
||||||
bool Usr_CheckIfUsrHasAcceptedInCurrentCrs (const struct UsrData *UsrDat);
|
bool Usr_CheckIfUsrHasAcceptedInCurrentCrs (const struct UsrData *UsrDat);
|
||||||
|
|
||||||
bool Usr_CheckIfICanViewRecordStd (const struct UsrData *UsrDat);
|
bool Usr_CheckIfICanViewRecordStd (const struct UsrData *UsrDat);
|
||||||
bool Usr_CheckIfICanViewRecordTch (struct UsrData *UsrDat);
|
bool Usr_CheckIfICanViewRecordTch (struct UsrData *UsrDat);
|
||||||
bool Usr_CheckIfICanViewWrkTstAtt (const struct UsrData *UsrDat);
|
bool Usr_CheckIfICanViewWrkTstAtt (const struct UsrData *UsrDat);
|
||||||
bool Usr_CheckIfICanViewUsrAgenda (struct UsrData *UsrDat);
|
bool Usr_CheckIfICanViewUsrAgenda (struct UsrData *UsrDat);
|
||||||
|
|
||||||
void Usr_FlushCacheUsrSharesAnyOfMyCrs (void);
|
void Usr_FlushCacheUsrSharesAnyOfMyCrs (void);
|
||||||
bool Usr_CheckIfUsrSharesAnyOfMyCrs (struct UsrData *UsrDat);
|
bool Usr_CheckIfUsrSharesAnyOfMyCrs (struct UsrData *UsrDat);
|
||||||
bool Usr_CheckIfUsrSharesAnyOfMyCrsWithDifferentRole (long UsrCod);
|
bool Usr_CheckIfUsrSharesAnyOfMyCrsWithDifferentRole (long UsrCod);
|
||||||
|
|
|
@ -592,20 +592,24 @@ static bool Svc_GetSomeUsrDataFromUsrCod (struct UsrData *UsrDat,long CrsCod)
|
||||||
row = mysql_fetch_row (mysql_res);
|
row = mysql_fetch_row (mysql_res);
|
||||||
if (row[0])
|
if (row[0])
|
||||||
{
|
{
|
||||||
if (sscanf (row[0],"%u",&UsrDat->Roles.InCurrentCrs.Role) != 1)
|
if (sscanf (row[0],"%u",&UsrDat->Roles.InCurrentCrs.Role) == 1)
|
||||||
|
UsrDat->Roles.InCurrentCrs.Valid = true;
|
||||||
|
else
|
||||||
|
{
|
||||||
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
||||||
UsrDat->Roles.InCurrentCrs.GotFromDBForUsrCod = UsrDat->UsrCod;
|
UsrDat->Roles.InCurrentCrs.Valid = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else // Impossible
|
else // Impossible
|
||||||
{
|
{
|
||||||
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
||||||
UsrDat->Roles.InCurrentCrs.GotFromDBForUsrCod = UsrDat->UsrCod;
|
UsrDat->Roles.InCurrentCrs.Valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // User does not belong to course
|
else // User does not belong to course
|
||||||
{
|
{
|
||||||
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
||||||
UsrDat->Roles.InCurrentCrs.GotFromDBForUsrCod = UsrDat->UsrCod;
|
UsrDat->Roles.InCurrentCrs.Valid = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -619,21 +623,25 @@ static bool Svc_GetSomeUsrDataFromUsrCod (struct UsrData *UsrDat,long CrsCod)
|
||||||
row = mysql_fetch_row (mysql_res);
|
row = mysql_fetch_row (mysql_res);
|
||||||
if (row[0])
|
if (row[0])
|
||||||
{
|
{
|
||||||
if (sscanf (row[0],"%u",&UsrDat->Roles.InCurrentCrs.Role) != 1)
|
if (sscanf (row[0],"%u",&UsrDat->Roles.InCurrentCrs.Role) == 1)
|
||||||
|
UsrDat->Roles.InCurrentCrs.Valid = true;
|
||||||
|
else
|
||||||
|
{
|
||||||
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
||||||
UsrDat->Roles.InCurrentCrs.GotFromDBForUsrCod = UsrDat->UsrCod;
|
UsrDat->Roles.InCurrentCrs.Valid = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
// MAX(Role) == NULL if user does not belong to any course
|
// MAX(Role) == NULL if user does not belong to any course
|
||||||
{
|
{
|
||||||
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
||||||
UsrDat->Roles.InCurrentCrs.GotFromDBForUsrCod = UsrDat->UsrCod;
|
UsrDat->Roles.InCurrentCrs.Valid = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // Impossible
|
else // Impossible
|
||||||
{
|
{
|
||||||
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
|
||||||
UsrDat->Roles.InCurrentCrs.GotFromDBForUsrCod = UsrDat->UsrCod;
|
UsrDat->Roles.InCurrentCrs.Valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue