Fixed bug with message outputs using sprintf;
Added program 'remove' to remove access from a user to a project;
Esse commit está contido em:
@@ -154,8 +154,22 @@ class Project{
|
|||||||
return $this->db->execute($qr);
|
return $this->db->execute($qr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function removeUser($user){
|
||||||
|
if(\Mind::hasProject($this->data['name'], $user['pk_user'])){
|
||||||
|
|
||||||
|
$qr_userProj= "DELETE from project_user
|
||||||
|
WHERE fk_project= ".((int)$this->data['pk_project'])."
|
||||||
|
AND fk_user= ".((int)$user['pk_user']);
|
||||||
|
$this->db->execute($qr_userProj);
|
||||||
|
\Mind::write('done');
|
||||||
|
return $this->db->execute('COMMIT');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function addUser($user){
|
public function addUser($user){
|
||||||
if(!\Mind::hasProject($this->data['name'], $user['pk_user'])){
|
|
||||||
|
if(!\Mind::hasProject($this->data['name'], $user['pk_user']) ){
|
||||||
$qr_userProj= "INSERT into project_user
|
$qr_userProj= "INSERT into project_user
|
||||||
(
|
(
|
||||||
fk_project,
|
fk_project,
|
||||||
@@ -173,10 +187,7 @@ class Project{
|
|||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
return true;
|
return true;
|
||||||
//echo "JA TINHA\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//var_dump($this->data['pk_project']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class MindCommand extends Symfony\Component\Console\Command\Command
|
|||||||
!in_array(strtolower($answer),
|
!in_array(strtolower($answer),
|
||||||
array_map('strtolower', array_keys($options))))
|
array_map('strtolower', array_keys($options))))
|
||||||
{
|
{
|
||||||
Mind::write('invalidOptionValue', true, $answer, $name);
|
\MindSpeaker::write('invalidOptionValue', true, $answer, $name);
|
||||||
$answer= false;
|
$answer= false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ class MindCommand extends Symfony\Component\Console\Command\Command
|
|||||||
!in_array(strtolower($answer),
|
!in_array(strtolower($answer),
|
||||||
array_map('strtolower', $options)))
|
array_map('strtolower', $options)))
|
||||||
{
|
{
|
||||||
Mind::write('invalidOptionValue', true, $answer, $name);
|
\MindSpeaker::write('invalidOptionValue', true, $answer, $name);
|
||||||
$answer= false;
|
$answer= false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -541,7 +541,7 @@ class MindCommand extends Symfony\Component\Console\Command\Command
|
|||||||
if($avOpts && !in_array(strtolower($this->$k),
|
if($avOpts && !in_array(strtolower($this->$k),
|
||||||
array_map('strtolower', $avOpts)))
|
array_map('strtolower', $avOpts)))
|
||||||
{
|
{
|
||||||
Mind::write('invalidOptionValue', true, $this->$k, $k);
|
\MindSpeaker::write('invalidOptionValue', true, $this->$k, $k);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ class MindProject extends VersionManager{
|
|||||||
*
|
*
|
||||||
* @global Mind $_MIND
|
* @global Mind $_MIND
|
||||||
* @param String $project
|
* @param String $project
|
||||||
* @return boolean
|
* @return Mixed False, or an Array with the project ID, Name and creator
|
||||||
*/
|
*/
|
||||||
static function hasProject($project, $u=false)
|
static function hasProject($project, $u=false)
|
||||||
{
|
{
|
||||||
@@ -253,7 +253,7 @@ class MindProject extends VersionManager{
|
|||||||
{
|
{
|
||||||
if($u && \MindUser::isAdmin())
|
if($u && \MindUser::isAdmin())
|
||||||
return false;
|
return false;
|
||||||
Mind::write('noProject', true, $project);
|
\MindSpeaker::write('noProject', true, $project);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return $row;
|
return $row;
|
||||||
@@ -274,7 +274,9 @@ class MindProject extends VersionManager{
|
|||||||
$noAccess= true;
|
$noAccess= true;
|
||||||
|
|
||||||
$db= new MindDB();
|
$db= new MindDB();
|
||||||
$hasProject= "SELECT pk_project
|
$hasProject= "SELECT pk_project,
|
||||||
|
creator,
|
||||||
|
project.name as name
|
||||||
from project
|
from project
|
||||||
where project.name = '".$projectName."'
|
where project.name = '".$projectName."'
|
||||||
";
|
";
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ class MindSpeaker
|
|||||||
}
|
}
|
||||||
if(!is_array($args)){
|
if(!is_array($args)){
|
||||||
$args= func_get_args();
|
$args= func_get_args();
|
||||||
array_shift($args);
|
|
||||||
array_shift($args); // ugly, isn't it?!
|
|
||||||
}
|
}
|
||||||
|
array_shift($args);
|
||||||
|
array_shift($args); // ugly, isn't it?!
|
||||||
|
|
||||||
$parms= "";
|
$parms= "";
|
||||||
if(sizeof($args)>=1)
|
if(sizeof($args)>=1)
|
||||||
|
|||||||
@@ -27,19 +27,25 @@
|
|||||||
{
|
{
|
||||||
if(!\API\User::userExists($this->user))
|
if(!\API\User::userExists($this->user))
|
||||||
{
|
{
|
||||||
echo "user does not exist";
|
\MindSpeaker::write('auth_fail');
|
||||||
return false; // TODO: put it into L10N
|
return false;
|
||||||
}
|
}
|
||||||
if(!\API\Project::projectExists($this->project))
|
if(!\API\Project::projectExists($this->project))
|
||||||
{
|
{
|
||||||
echo "project does not exist";
|
\MindSpeaker::write('noProject', true, $this->project);
|
||||||
return false; // TODO: put it into L10N
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$projectData= \Mind::hasProject($this->project))
|
if(!$projectData= \Mind::hasProject($this->project, $this->user)){
|
||||||
return false;
|
if(\MindUser::isAdmin()){
|
||||||
|
$projectData= \API\Project::projectExists($this->project);
|
||||||
|
$projectData= $projectData[0];
|
||||||
|
}else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$pF= new DAO\ProjectFactory($projectData);
|
$pF= new DAO\ProjectFactory($projectData);
|
||||||
|
|
||||||
if($pF->addUser(\MindUser::getUserByLogin($this->user))){
|
if($pF->addUser(\MindUser::getUserByLogin($this->user))){
|
||||||
\MindSpeaker::write('done');
|
\MindSpeaker::write('done');
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ EOT
|
|||||||
|
|
||||||
if($this->projectExists($this->argName))
|
if($this->projectExists($this->argName))
|
||||||
{
|
{
|
||||||
Mind::write('projectAlreadyExists', true, $this->argName);
|
\MindSpeaker::write('projectAlreadyExists', true, $this->argName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!file_exists($this->projectfile) && !@mkdir($this->projectfile))
|
if(!file_exists($this->projectfile) && !@mkdir($this->projectfile))
|
||||||
@@ -154,7 +154,7 @@ EOT
|
|||||||
$ini);
|
$ini);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mind::write('projectCreated', true, $this->argName);
|
\MindSpeaker::write('projectCreated', true, $this->argName);
|
||||||
$db->execute("COMMIT");
|
$db->execute("COMMIT");
|
||||||
|
|
||||||
Mind::openProject(Array('pk_project'=>$key,
|
Mind::openProject(Array('pk_project'=>$key,
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of TheWebMind 3rd generation.
|
||||||
|
*
|
||||||
|
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||||
|
* @license licenses/mind3rd.license
|
||||||
|
*/
|
||||||
|
use Symfony\Component\Console\Input\InputArgument,
|
||||||
|
Symfony\Component\Console\Input\InputOption,
|
||||||
|
Symfony\Component\Console;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents a model for programs.
|
||||||
|
*
|
||||||
|
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||||
|
*/
|
||||||
|
class Remove extends MindCommand implements program
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* The properties you will use as argument MUST be declared, and public
|
||||||
|
*/
|
||||||
|
public $user= '';
|
||||||
|
public $from= '';
|
||||||
|
public $project= '';
|
||||||
|
|
||||||
|
public function executableFunction()
|
||||||
|
{
|
||||||
|
if(!\MindUser::isAdmin()){
|
||||||
|
\MindSpeaker::write('mustBeAdmin');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!\API\User::userExists($this->user))
|
||||||
|
{
|
||||||
|
\MindSpeaker::write('auth_fail');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!\API\Project::projectExists($this->project) || !$projectData= \Mind::hasProject($this->project))
|
||||||
|
{
|
||||||
|
\MindSpeaker::write('noProject', true, $this->project);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pF= new DAO\ProjectFactory($projectData);
|
||||||
|
if($pF->removeUser(\MindUser::getUserByLogin($this->user))){
|
||||||
|
\MindSpeaker::write('done');
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* You can use the following structure to set the program behavior
|
||||||
|
*/
|
||||||
|
$this->setCommandName('remove')
|
||||||
|
->setDescription("Removes a user from a project")
|
||||||
|
->setRestrict(true)
|
||||||
|
->setHelp("Use this command to remove a user's access to a project.")
|
||||||
|
->setAction('executableFunction');
|
||||||
|
|
||||||
|
$this->addRequiredArgument('user',
|
||||||
|
'The user to be removed');
|
||||||
|
$this->addRequiredArgument('from',
|
||||||
|
'string "from"');
|
||||||
|
$this->addRequiredArgument('project',
|
||||||
|
'The project from which the user will be removed');
|
||||||
|
|
||||||
|
$this->init();
|
||||||
|
}
|
||||||
|
}
|
||||||
Referência em uma Nova Issue
Bloquear um usuário