Corrections ModuleManager + modification des permissions possibles

ModuleRequest() param optionnel ou NULL
Permissions de création possibles : 'admin' ou 'subject' (un admin peut être sujet quand même)
This commit is contained in:
xdrm-brackets 2016-04-18 19:09:25 +02:00
parent 0192b7b0b9
commit ad19c37b80
11 changed files with 32 additions and 33 deletions

View File

@ -69,11 +69,11 @@
"description": "Creation d'un nouvel utilisateur.",
"permissions": ["admin"],
"parameters": {
"login" : { "description": "Login de l'utilisateur, 30 caracteres maximum.", "type": "varchar(3,30)" },
"password" : { "description": "Mot de passe de l'utilisateur.", "type": "text" },
"mail" : { "description": "Adresse mail de l'utilisateur.", "type": "mail" },
"reference" : { "description": "UID d'une personne d'un sondage, peut etre vide.", "type": "text" },
"permissions": { "description": "Liste des permissions de l'utilisateur.", "type": "text" }
"login" : { "description": "Login de l'utilisateur, 30 caracteres maximum.", "type": "varchar(3,30)" },
"password" : { "description": "Mot de passe de l'utilisateur.", "type": "text" },
"mail" : { "description": "Adresse mail de l'utilisateur.", "type": "mail" },
"reference" : { "description": "UID d'une personne d'un sondage, peut etre vide.", "type": "text" },
"permission" : { "description": "Permissions de l'utilisateur : 'admin' ou 'subject'", "type": "varchar(5,7)" }
}
},
@ -164,16 +164,17 @@
"firstname" : { "description": "Prénom du sujet, 30 caracteres maximum.", "type": "varchar(3,30)" },
"lastname" : { "description": "Nom du sujet, 30 caracteres maximum.", "type": "varchar(3,30)" },
"id_facebook": { "description": "Id facebook du sujet (optionnel).", "type": "id", "optional": true },
"number" : { "description": "Numéro de téléphone du sujet (optionnel).", "type": "text" }
"number" : { "description": "Numéro de téléphone du sujet (optionnel).", "type": "text", "optional": true }
}
},
"remove": {
"description": "Suppression d'un utilisateur.",
"merge": {
"description": "Fusion de 2 sujets qui sont en fait la même personne.",
"permissions": ["admin"],
"parameters": {
"id_user": { "description": "UID de l'utilisateur", "type": "id" }
"id_source": { "description": "UID de l'utilisateur doublon", "type": "id" },
"id_target": { "description": "UID de l'utilisateur déjà existant", "type": "id" }
}
}

View File

@ -354,7 +354,7 @@
if( !isset($paramsdata['type']) ) continue;
/* (4) Si le paramètre est optionnel et n'est pas donné */
if( $optional && !isset($params[$name]) ){
if( $optional && (!isset($params[$name]) || is_null($params[$name])) ){
// On le crée avec la valeur NULL
$params[$name] = null;
// On passe au paramètre suivant

View File

@ -142,11 +142,12 @@
=========================================================*/
$password = sessionManager::sha1($password);
$reference = (is_numeric($reference)) ? (int) $reference : null;
$permissions = explode( ',', str_replace(' ', '', $permissions) );
$permission = ($permission=='admin') ? 'admin' : 'subject';
/* [1] Creation de l'utilisateur
=========================================================*/
$create = new Repo('user/create', array($login, $password, $mail, $reference, $permissions));
$create = new Repo('user/create', array($login, $password, $mail, $reference, $permission));
$created_id = $create->answer();
// Si erreur de creation, on retourne une erreur
@ -171,7 +172,7 @@
*/
public static function remove($params){
extract($params);
/* [1] On verifie que l'utilisateur existe
=========================================================*/
$exists = new Repo('user/getById', array($id_user));

View File

@ -6,7 +6,7 @@
class user{
/* VERIFICATION DU LOGIN/PASSWORD D'UN UTILISATEUR
*
* @login<String> Username ou Adresse mail de l'utilisateur
@ -122,19 +122,16 @@
* @return id_user<int> Renvoie l'id de l'utilisateur cree ou FALSE si erreur
*
*/
public static function create($login, $password, $mail, $reference, $permissions){
public static function create($login, $password, $mail, $reference, $permission){
/* [0] Verification et formattage des INPUT
=========================================================*/
$checkInput = Database::check('sha1', $password);
$checkInput = $checkInput && ( Database::check('id', $reference) || $reference === null );
$checkInput = $checkInput && Database::check('array', $permissions);
$checkInput = $checkInput && in_array($permission, array('admin', 'subject'));
// Si erreur en entree, on retourne FAUX
if( !$checkInput ) return false;
// On formatte les permissions (array -> string)
$permissions = implode(',', $permissions);
/* [1] On verifie que le login/mail et reference sont uniques
=========================================================*/
@ -165,8 +162,8 @@
':login' => $login,
':password' => $password,
':mail' => $mail,
':permission' => $permissions
));
':permission' => $permission
));
/* (2) Si reference est defini */
}else{
@ -178,8 +175,8 @@
':password' => $password,
':mail' => $mail,
':reference' => (int) $reference,
':permission' => $permissions
));
':permission' => $permission
));
}
@ -197,7 +194,7 @@
':password' => $password,
':mail' => $mail,
':reference' => (int) $reference,
':permission' => $permissions
':permission' => $permission
));
// On recupere l'id de l'utilisateur
@ -234,4 +231,4 @@
}
?>
?>

View File

@ -565,7 +565,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 16:55:53 UTC 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 17:06:21 UTC 2016.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>

View File

@ -247,7 +247,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 16:55:53 UTC 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 17:06:21 UTC 2016.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>

View File

@ -517,7 +517,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 16:55:53 UTC 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 17:06:21 UTC 2016.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>

View File

@ -214,7 +214,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 16:55:53 UTC 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 17:06:21 UTC 2016.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>

View File

@ -350,7 +350,7 @@
<span class="success"><strong>High</strong>: 90% to 100%</span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 16:55:53 UTC 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 17:06:21 UTC 2016.</small>
</p>
</footer>
</div>

View File

@ -315,7 +315,7 @@
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 16:55:53 UTC 2016.</small>
<small>Generated by <a href="http://github.com/sebastianbergmann/php-code-coverage" target="_top">PHP_CodeCoverage 2.1.7</a> using <a href="http://php.net/" target="_top">PHP 5.6.11-1ubuntu3.1</a> and <a href="http://phpunit.de/">PHPUnit 4.7.6</a> at Mon Apr 18 17:06:21 UTC 2016.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>

View File

@ -136,7 +136,7 @@ var USERS = {
'password': USERS.add.password.value,
'mail': USERS.add.mail.value,
'reference': USERS.add.reference.value,
'permissions': (USERS.add.isAdmin.checked) ? 'admin' : 'subject'
'permission': (USERS.add.isAdmin.checked) ? 'admin' : 'subject'
};
// On lance la requete
@ -182,4 +182,4 @@ for( var i = 0 ; i < USERS.remove.buttons.length ; i++ ){
}, false);
}
}