swad-core/swad_privacy.c

267 lines
10 KiB
C
Raw Normal View History

2015-10-16 02:24:29 +02:00
// swad_privacy.c: users' photo and public profile visibility
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
2018-04-24 13:21:53 +02:00
Copyright (C) 1999-2018 Antonio Ca<EFBFBD>as Vargas
2015-10-16 02:24:29 +02:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
#include <string.h>
#include "swad_action.h"
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2015-10-16 02:24:29 +02:00
#include "swad_global.h"
#include "swad_parameter.h"
#include "swad_privacy.h"
#include "swad_theme.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
/***** Visibility (who can see user's photo or public profile) *****/
const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY] =
{
2016-01-18 10:21:18 +01:00
"unknown", // Pri_VISIBILITY_UNKNOWN
2015-10-16 02:24:29 +02:00
"user", // Pri_VISIBILITY_USER
"course", // Pri_VISIBILITY_COURSE
"system", // Pri_VISIBILITY_SYSTEM
"world", // Pri_VISIBILITY_WORLD
};
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
2018-10-09 00:42:05 +02:00
#define Pri_PRIVACY_ID "privacy"
2015-10-16 02:24:29 +02:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2016-11-07 13:56:39 +01:00
static void Pri_PutIconsPrivacy (void);
2015-12-24 19:30:45 +01:00
static void Pri_PutFormVisibility (const char *TxtLabel,
Act_Action_t Action,const char *ParamName,
2016-01-04 16:30:50 +01:00
Pri_Visibility_t CurrentVisibilityInDB,
unsigned MaskAllowedVisibility);
2015-10-16 02:24:29 +02:00
/*****************************************************************************/
/******************************* Edit my privacy *****************************/
/*****************************************************************************/
void Pri_EditMyPrivacy (void)
{
2016-11-13 01:21:35 +01:00
extern const char *Hlp_PROFILE_Preferences_privacy;
2016-01-18 10:21:18 +01:00
extern const char *Txt_Please_review_your_privacy_preferences;
2015-10-16 02:24:29 +02:00
extern const char *Txt_Privacy;
extern const char *Txt_Photo;
extern const char *Txt_Public_profile;
2017-02-27 19:52:04 +01:00
extern const char *Txt_Timeline;
2015-10-16 02:24:29 +02:00
2018-10-09 00:42:05 +02:00
/***** Start section with preferences on privacy *****/
Lay_StartSection (Pri_PRIVACY_ID);
2016-01-18 10:21:18 +01:00
/***** If any of my preferences about privacy is unknown *****/
if (Gbl.Usrs.Me.UsrDat.PhotoVisibility == Pri_VISIBILITY_UNKNOWN ||
Gbl.Usrs.Me.UsrDat.ProfileVisibility == Pri_VISIBILITY_UNKNOWN)
2017-05-11 23:45:46 +02:00
Ale_ShowAlert (Ale_WARNING,Txt_Please_review_your_privacy_preferences);
2016-01-18 10:21:18 +01:00
2017-06-12 14:16:33 +02:00
/***** Start box and table *****/
2017-06-10 21:38:10 +02:00
Box_StartBoxTable (NULL,Txt_Privacy,Pri_PutIconsPrivacy,
2017-06-12 15:03:29 +02:00
Hlp_PROFILE_Preferences_privacy,Box_NOT_CLOSABLE,2);
2015-10-16 02:24:29 +02:00
/***** Edit photo visibility *****/
2015-12-24 19:30:45 +01:00
Pri_PutFormVisibility (Txt_Photo,
ActChgPriPho,"VisPho",
2016-01-04 16:30:50 +01:00
Gbl.Usrs.Me.UsrDat.PhotoVisibility,
(1 << Pri_VISIBILITY_USER) |
(1 << Pri_VISIBILITY_COURSE) |
(1 << Pri_VISIBILITY_SYSTEM) |
(1 << Pri_VISIBILITY_WORLD));
2015-10-16 02:24:29 +02:00
/***** Edit public profile visibility *****/
2015-12-24 19:30:45 +01:00
Pri_PutFormVisibility (Txt_Public_profile,
ActChgPriPrf,"VisPrf",
2016-01-04 16:30:50 +01:00
Gbl.Usrs.Me.UsrDat.ProfileVisibility,
(1 << Pri_VISIBILITY_USER) |
(1 << Pri_VISIBILITY_COURSE) |
(1 << Pri_VISIBILITY_SYSTEM) |
(1 << Pri_VISIBILITY_WORLD));
/***** Edit public activity (timeline) visibility *****/
2017-02-27 19:52:04 +01:00
Pri_PutFormVisibility (Txt_Timeline,
2016-01-04 16:30:50 +01:00
ActUnk,"VisTml",
Pri_VISIBILITY_SYSTEM,
(1 << Pri_VISIBILITY_SYSTEM));
2015-10-16 02:24:29 +02:00
2017-06-12 14:16:33 +02:00
/***** End table and box *****/
2017-06-10 21:38:10 +02:00
Box_EndBoxTable ();
2018-10-09 00:42:05 +02:00
/***** End section with preferences on privacy *****/
Lay_EndSection ();
2016-11-07 13:56:39 +01:00
}
/*****************************************************************************/
2016-11-07 14:12:15 +01:00
/***************** Put contextual icons in privacy preference ****************/
2016-11-07 13:56:39 +01:00
/*****************************************************************************/
static void Pri_PutIconsPrivacy (void)
{
/***** Put icon to show a figure *****/
Gbl.Stat.FigureType = Sta_PRIVACY;
Sta_PutIconToShowFigure ();
2015-10-16 02:24:29 +02:00
}
/*****************************************************************************/
/************************** Select photo visibility **************************/
/*****************************************************************************/
2015-12-24 19:30:45 +01:00
static void Pri_PutFormVisibility (const char *TxtLabel,
Act_Action_t Action,const char *ParamName,
2016-01-04 16:30:50 +01:00
Pri_Visibility_t CurrentVisibilityInDB,
unsigned MaskAllowedVisibility)
2015-10-16 02:24:29 +02:00
{
extern const char *The_ClassForm[The_NUM_THEMES];
extern const char *Txt_PRIVACY_OPTIONS[Pri_NUM_OPTIONS_PRIVACY];
Pri_Visibility_t Visibility;
/***** Select visibility *****/
fprintf (Gbl.F.Out,"<tr>"
"<td class=\"%s RIGHT_TOP\">"
"%s:"
"</td>"
"<td class=\"LEFT_TOP\">",
The_ClassForm[Gbl.Prefs.Theme],TxtLabel);
/***** Form with list of options *****/
2016-01-04 16:30:50 +01:00
if (Action != ActUnk)
2018-10-15 14:07:12 +02:00
Act_StartFormAnchor (Action,Pri_PRIVACY_ID);
2015-10-16 02:24:29 +02:00
fprintf (Gbl.F.Out,"<ul class=\"LIST_LEFT\">");
2016-01-18 10:21:18 +01:00
for (Visibility = Pri_VISIBILITY_USER;
Visibility <= Pri_VISIBILITY_WORLD;
2015-10-16 02:24:29 +02:00
Visibility++)
2016-01-04 16:30:50 +01:00
if (MaskAllowedVisibility & 1 << Visibility)
{
fprintf (Gbl.F.Out,"<li class=\"%s\">"
2016-12-25 18:35:19 +01:00
"<label>"
2016-01-04 16:30:50 +01:00
"<input type=\"radio\" name=\"%s\" value=\"%u\"",
(Visibility == CurrentVisibilityInDB) ? "DAT_N LIGHT_BLUE" :
"DAT",
ParamName,(unsigned) Visibility);
if (Visibility == CurrentVisibilityInDB)
fprintf (Gbl.F.Out," checked=\"checked\"");
if (Action == ActUnk)
fprintf (Gbl.F.Out," disabled=\"disabled\"");
else
fprintf (Gbl.F.Out," onclick=\"document.getElementById('%s').submit();\"",
2016-01-14 10:31:09 +01:00
Gbl.Form.Id);
2016-01-04 16:30:50 +01:00
fprintf (Gbl.F.Out," />"
"%s"
2016-12-25 18:35:19 +01:00
"</label>"
2016-01-04 16:30:50 +01:00
"</li>",
Txt_PRIVACY_OPTIONS[Visibility]);
}
2015-10-16 02:24:29 +02:00
2017-06-12 14:16:33 +02:00
/***** End list and form *****/
2015-10-16 02:24:29 +02:00
fprintf (Gbl.F.Out,"</ul>");
2016-01-04 16:30:50 +01:00
if (Action != ActUnk)
2018-10-15 14:07:12 +02:00
Act_EndForm ();
2015-10-16 02:24:29 +02:00
fprintf (Gbl.F.Out,"</td>"
"</tr>");
}
/*****************************************************************************/
/************************ Get visibility from string *************************/
/*****************************************************************************/
2016-01-18 10:21:18 +01:00
Pri_Visibility_t Pri_GetVisibilityFromStr (const char *Str)
2015-10-16 02:24:29 +02:00
{
Pri_Visibility_t Visibility;
for (Visibility = (Pri_Visibility_t) 0;
Visibility < Pri_NUM_OPTIONS_PRIVACY;
Visibility++)
if (!strcasecmp (Str,Pri_VisibilityDB[Visibility]))
return Visibility;
2016-01-18 10:21:18 +01:00
return Pri_VISIBILITY_UNKNOWN;
2015-10-16 02:24:29 +02:00
}
/*****************************************************************************/
/**************** Get parameter with visibility from form ********************/
/*****************************************************************************/
2016-01-18 10:21:18 +01:00
Pri_Visibility_t Pri_GetParamVisibility (const char *ParamName)
2015-10-16 02:24:29 +02:00
{
2017-01-29 12:42:19 +01:00
return (Pri_Visibility_t)
2017-01-29 21:41:08 +01:00
Par_GetParToUnsignedLong (ParamName,
0,
Pri_NUM_OPTIONS_PRIVACY - 1,
(unsigned long) Pri_VISIBILITY_UNKNOWN);
2015-10-16 02:24:29 +02:00
}
/*****************************************************************************/
/*********** Check if user's photo of public profile can be shown ************/
/*****************************************************************************/
// Returns true if it can be shown and false if not.
2017-01-28 15:58:46 +01:00
bool Pri_ShowingIsAllowed (Pri_Visibility_t Visibility,struct UsrData *UsrDat)
2015-10-16 02:24:29 +02:00
{
2018-10-10 23:56:42 +02:00
bool ItsMe = Usr_ItsMe (UsrDat->UsrCod);
2018-10-10 14:03:06 +02:00
/***** I always can see my things *****/
if (ItsMe)
2016-06-12 19:55:33 +02:00
return true;
2015-11-15 02:24:48 +01:00
/***** System admins always can see others' profiles *****/
2017-06-04 18:18:54 +02:00
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
2015-11-15 02:24:48 +01:00
return true;
2015-10-16 02:24:29 +02:00
/***** Check if I can see the other's photo *****/
switch (Visibility)
{
2016-01-18 10:21:18 +01:00
case Pri_VISIBILITY_UNKNOWN:
2016-06-12 19:55:33 +02:00
return false; // It's not me
2017-01-28 15:58:46 +01:00
case Pri_VISIBILITY_USER: // Only visible
// by me and my teachers if I am a student
// or me and my students if I am a teacher
2016-12-13 13:32:19 +01:00
// Do both users share the same course but whit different role?
return Usr_CheckIfUsrSharesAnyOfMyCrsWithDifferentRole (UsrDat->UsrCod);
2015-10-16 02:24:29 +02:00
case Pri_VISIBILITY_COURSE: // Visible by users sharing courses with me
2016-12-13 13:32:19 +01:00
// Do both users share the same course?
return Usr_CheckIfUsrSharesAnyOfMyCrs (UsrDat);
2015-10-16 02:24:29 +02:00
case Pri_VISIBILITY_SYSTEM: // Visible by any user logged in platform
2015-11-15 02:24:48 +01:00
return Gbl.Usrs.Me.Logged;
2015-10-16 02:24:29 +02:00
case Pri_VISIBILITY_WORLD: // Public, visible by everyone, even unlogged visitors
2015-11-15 02:24:48 +01:00
return true;
2015-10-16 02:24:29 +02:00
}
2015-11-15 02:24:48 +01:00
return false; // Never reached. To avoid warning
2015-10-16 02:24:29 +02:00
}