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);
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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."'
|
||||
";
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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