creation de l' API de creation / association d'une blockchaine.
gestion des autorisations : on ne peut pas modifier / supprimer un blocklog. ces 2 fonctions ne sont donc pas des fonctions dist
This commit is contained in:
parent
94944e471b
commit
5219b4aac3
2 changed files with 68 additions and 6 deletions
|
@ -20,6 +20,13 @@ if (!defined('_ECRIRE_INC_VERSION')) {
|
|||
function blocklog_autoriser() {
|
||||
}
|
||||
|
||||
function autoriser_connecte_etre($faire, $type, $id, $qui, $opt) {
|
||||
if ($qui['id_auteur'] > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// -----------------
|
||||
// Objet blocklogs
|
||||
|
@ -38,7 +45,10 @@ function blocklog_autoriser() {
|
|||
* @return bool true s'il a le droit, false sinon
|
||||
**/
|
||||
function autoriser_blocklog_creer_dist($faire, $type, $id, $qui, $opt) {
|
||||
return in_array($qui['statut'], array('0minirezo', '1comite'));
|
||||
if ($qui['id_auteur'] > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,8 +75,8 @@ function autoriser_blocklog_voir_dist($faire, $type, $id, $qui, $opt) {
|
|||
* @param array $opt Options de cette autorisation
|
||||
* @return bool true s'il a le droit, false sinon
|
||||
**/
|
||||
function autoriser_blocklog_modifier_dist($faire, $type, $id, $qui, $opt) {
|
||||
return in_array($qui['statut'], array('0minirezo', '1comite'));
|
||||
function autoriser_blocklog_modifier($faire, $type, $id, $qui, $opt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,8 +89,8 @@ function autoriser_blocklog_modifier_dist($faire, $type, $id, $qui, $opt) {
|
|||
* @param array $opt Options de cette autorisation
|
||||
* @return bool true s'il a le droit, false sinon
|
||||
**/
|
||||
function autoriser_blocklog_supprimer_dist($faire, $type, $id, $qui, $opt) {
|
||||
return $qui['statut'] == '0minirezo' and !$qui['restreint'];
|
||||
function autoriser_blocklog_supprimer($faire, $type, $id, $qui, $opt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -96,5 +106,9 @@ function autoriser_blocklog_supprimer_dist($faire, $type, $id, $qui, $opt) {
|
|||
* @return bool true s'il a le droit, false sinon
|
||||
**/
|
||||
function autoriser_associerblocklogs_dist($faire, $type, $id, $qui, $opt) {
|
||||
return $qui['statut'] == '0minirezo' and !$qui['restreint'];
|
||||
if ($qui['id_auteur'] > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
//return $qui['statut'] == '0minirezo' and !$qui['restreint'];
|
||||
}
|
||||
|
|
48
inc/blocklog.php
Normal file
48
inc/blocklog.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
if (!defined('_ECRIRE_INC_VERSION')){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* creation de la blockchaine
|
||||
*
|
||||
* @param string $objet
|
||||
* @param int $id_objet
|
||||
* @param string | array $chaine : ensemble des valeurs utilisées pour creer la chaine
|
||||
* @return array [id_blocklog, chaine, blockchaine]
|
||||
*/
|
||||
function inc_blocklog_dist($objet, $id_objet, $chaine) {
|
||||
if (!$objet or !$id_objet or !$chaine) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! defined("_BACKLOG_ALGO")) {
|
||||
define("_BACKLOG_ALGO", 'sha256');
|
||||
}
|
||||
if (is_array($chaine)) {
|
||||
$chaine = implode('|', $chaine);
|
||||
}
|
||||
|
||||
$date = date_create();
|
||||
$chaine .= "|". date_timestamp_get($date);
|
||||
|
||||
$chaine = hash(_BACKLOG_ALGO, $chaine);
|
||||
$blockchaine = sql_getfetsel('blockchaine', 'spip_blocklogs',1,'', 'id_blocklog DESC', '1');
|
||||
|
||||
include_spip('action/editer_objet');
|
||||
$set = array (
|
||||
'blockchaine' => $blockchaine,
|
||||
'chaine' => $chaine,
|
||||
);
|
||||
$id_blocklog = objet_inserer($objet);
|
||||
objet_modifier("blocklog", $id_blocklog, $set);
|
||||
$set['id_blocklog'] = $id_blocklog;
|
||||
|
||||
include_spip('action/editer_liens');
|
||||
$objets_source = array("blocklog"=>$id_blocklog);
|
||||
$objets_lies = array($objet => $id_objet);
|
||||
objet_associer($objets_source, $objets_lies);
|
||||
|
||||
return $set;
|
||||
}
|
Loading…
Add table
Reference in a new issue