diff --git a/mind3rd/API/classes/DAO/Project.php b/mind3rd/API/classes/DAO/Project.php index 1991bf4..35e4283 100755 --- a/mind3rd/API/classes/DAO/Project.php +++ b/mind3rd/API/classes/DAO/Project.php @@ -154,8 +154,22 @@ class Project{ 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){ - if(!\Mind::hasProject($this->data['name'], $user['pk_user'])){ + + if(!\Mind::hasProject($this->data['name'], $user['pk_user']) ){ $qr_userProj= "INSERT into project_user ( fk_project, @@ -173,10 +187,7 @@ class Project{ return true; }else{ return true; - //echo "JA TINHA\n"; } - - //var_dump($this->data['pk_project']); } /** diff --git a/mind3rd/API/classes/MindCommand.php b/mind3rd/API/classes/MindCommand.php index d065fe2..690458d 100755 --- a/mind3rd/API/classes/MindCommand.php +++ b/mind3rd/API/classes/MindCommand.php @@ -126,7 +126,7 @@ class MindCommand extends Symfony\Component\Console\Command\Command !in_array(strtolower($answer), array_map('strtolower', array_keys($options)))) { - Mind::write('invalidOptionValue', true, $answer, $name); + \MindSpeaker::write('invalidOptionValue', true, $answer, $name); $answer= false; } @@ -143,7 +143,7 @@ class MindCommand extends Symfony\Component\Console\Command\Command !in_array(strtolower($answer), array_map('strtolower', $options))) { - Mind::write('invalidOptionValue', true, $answer, $name); + \MindSpeaker::write('invalidOptionValue', true, $answer, $name); $answer= false; } } @@ -541,7 +541,7 @@ class MindCommand extends Symfony\Component\Console\Command\Command if($avOpts && !in_array(strtolower($this->$k), array_map('strtolower', $avOpts))) { - Mind::write('invalidOptionValue', true, $this->$k, $k); + \MindSpeaker::write('invalidOptionValue', true, $this->$k, $k); return false; } } diff --git a/mind3rd/API/classes/MindProject.php b/mind3rd/API/classes/MindProject.php index bd2cc8d..1d284c9 100755 --- a/mind3rd/API/classes/MindProject.php +++ b/mind3rd/API/classes/MindProject.php @@ -218,7 +218,7 @@ class MindProject extends VersionManager{ * * @global Mind $_MIND * @param String $project - * @return boolean + * @return Mixed False, or an Array with the project ID, Name and creator */ static function hasProject($project, $u=false) { @@ -253,7 +253,7 @@ class MindProject extends VersionManager{ { if($u && \MindUser::isAdmin()) return false; - Mind::write('noProject', true, $project); + \MindSpeaker::write('noProject', true, $project); return false; } return $row; @@ -274,7 +274,9 @@ class MindProject extends VersionManager{ $noAccess= true; $db= new MindDB(); - $hasProject= "SELECT pk_project + $hasProject= "SELECT pk_project, + creator, + project.name as name from project where project.name = '".$projectName."' "; diff --git a/mind3rd/API/classes/MindSpeaker.php b/mind3rd/API/classes/MindSpeaker.php index 556fcd5..4219d70 100755 --- a/mind3rd/API/classes/MindSpeaker.php +++ b/mind3rd/API/classes/MindSpeaker.php @@ -30,9 +30,9 @@ class MindSpeaker } if(!is_array($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= ""; if(sizeof($args)>=1) diff --git a/mind3rd/API/programs/Add.php b/mind3rd/API/programs/Add.php index 26a6238..6a218f1 100755 --- a/mind3rd/API/programs/Add.php +++ b/mind3rd/API/programs/Add.php @@ -27,19 +27,25 @@ { if(!\API\User::userExists($this->user)) { - echo "user does not exist"; - return false; // TODO: put it into L10N + \MindSpeaker::write('auth_fail'); + return false; } if(!\API\Project::projectExists($this->project)) { - echo "project does not exist"; - return false; // TODO: put it into L10N + \MindSpeaker::write('noProject', true, $this->project); + return false; } - if(!$projectData= \Mind::hasProject($this->project)) - return false; + if(!$projectData= \Mind::hasProject($this->project, $this->user)){ + if(\MindUser::isAdmin()){ + $projectData= \API\Project::projectExists($this->project); + $projectData= $projectData[0]; + }else + return false; + } $pF= new DAO\ProjectFactory($projectData); + if($pF->addUser(\MindUser::getUserByLogin($this->user))){ \MindSpeaker::write('done'); return true; diff --git a/mind3rd/API/programs/Create.php b/mind3rd/API/programs/Create.php index 553477a..4ac6be0 100755 --- a/mind3rd/API/programs/Create.php +++ b/mind3rd/API/programs/Create.php @@ -65,7 +65,7 @@ EOT if($this->projectExists($this->argName)) { - Mind::write('projectAlreadyExists', true, $this->argName); + \MindSpeaker::write('projectAlreadyExists', true, $this->argName); return false; } if(!file_exists($this->projectfile) && !@mkdir($this->projectfile)) @@ -154,7 +154,7 @@ EOT $ini); } - Mind::write('projectCreated', true, $this->argName); + \MindSpeaker::write('projectCreated', true, $this->argName); $db->execute("COMMIT"); Mind::openProject(Array('pk_project'=>$key, diff --git a/mind3rd/API/programs/Remove.php b/mind3rd/API/programs/Remove.php new file mode 100644 index 0000000..e96d8a9 --- /dev/null +++ b/mind3rd/API/programs/Remove.php @@ -0,0 +1,74 @@ + + * @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 + */ + 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(); + } + }