Skip to content

Commit

Permalink
#23 [Security] add: generic security & multicompany checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo David committed Jan 9, 2023
1 parent 511996b commit 9754ec1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
12 changes: 9 additions & 3 deletions langs/fr_FR/saturne.lang
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ ModuleSaturneDesc = Corrigez vos problèmes de sécurité facilement et rapideme
SaturneSetup = Configuration du module Saturne
Settings = Réglages
SaturneSetupPage = Page de configuration du module Saturne
TimeSpender = Pointeur de temps
TimeSpenderConfiguration = Configuration du pointage de temps
GitHubProjectName = Nom du projet GitHub
GitHubProjectOrganization = Nom de l'organisation GitHub
GitHubProjectVersion = Version du projet GitHub
DolibarrLinkedTask = Tâche liée
SaturneConfig = Configuration du module

#
Expand All @@ -51,6 +48,14 @@ LireSaturne = Consulter Saturne
ReadSaturne = Consulter Saturne (read)
ReadAdminPage = Accéder à la configuration du module Saturne

#
# Sécurité
#

# Data - Donnée
ChangeEntityRedirection = Vous avez été redirigé car vous avez changé d'entité
EnableModule = Veuillez activer le module %s pour voir cette page

#
# Index
#
Expand All @@ -60,6 +65,7 @@ SaturneArea = Bienvenue sur Saturne
SaturneData = Données configurables de Saturne



#
# Media Gallery
#
Expand Down
39 changes: 38 additions & 1 deletion lib/saturne_functions.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ function saturne_show_medias_linked($modulepart = 'ecm', $sdir, $size = 0, $nbma
return $return;
}


/**
* Load array of pages to display
*
Expand Down Expand Up @@ -430,3 +429,41 @@ function saturne_show_pagination($pagesCounter, $page_array, $offset) {
$return .= '</ul>';
return $return;
}

/**
* Show pages based on loaded pages array
*
* @param integer $pagesCounter
* @param array $page_array
* @param integer $offset
* @return string Pages html content
*
*/
function saturne_check_access($module, $object, $permission) {

global $conf, $langs, $user;

if (!$permission) accessforbidden();
if ($user->socid > 0) accessforbidden();

$langs->loadLangs(['saturne@saturne']);

if ($conf->multicompany->enabled) {
if ($conf->$module->enabled) {
if ($object->id > 0) {
if ($object->entity != $conf->entity) {
setEventMessage($langs->trans('ChangeEntityRedirection'), 'warnings');
$urltogo = dol_buildpath('/custom/' . $module . '/' . $module . 'index.php?mainmenu=' . $module, 1);
header("Location: " . $urltogo);
exit;
}
}
} else {
setEventMessage($langs->trans('EnableModule', ucfirst($module)), 'warnings');
$urltogo = dol_buildpath('/admin/modules.php?search_nature=external_Evarisk', 1);
header("Location: " . $urltogo);
exit;
}
}
}

0 comments on commit 9754ec1

Please sign in to comment.