When creating a new project, have the possibility to select another project to duplicate
This commit is contained in:
@@ -171,14 +171,15 @@ class Project extends Base
|
||||
$project = $this->getProject();
|
||||
|
||||
if ($this->request->getStringParam('duplicate') === 'yes') {
|
||||
$values = array_keys($this->request->getValues());
|
||||
if ($this->projectDuplication->duplicate($project['id'], $values) !== false) {
|
||||
$project_id = $this->projectDuplication->duplicate($project['id'], array_keys($this->request->getValues()), $this->userSession->getId());
|
||||
|
||||
if ($project_id !== false) {
|
||||
$this->flash->success(t('Project cloned successfully.'));
|
||||
} else {
|
||||
$this->flash->failure(t('Unable to clone this project.'));
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('project', 'index'));
|
||||
$this->response->redirect($this->helper->url->to('project', 'show', array('project_id' => $project_id)));
|
||||
}
|
||||
|
||||
$this->response->html($this->projectLayout('project/duplicate', array(
|
||||
@@ -240,57 +241,4 @@ class Project extends Base
|
||||
'title' => t('Project activation')
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a form to create a new project
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function create(array $values = array(), array $errors = array())
|
||||
{
|
||||
$is_private = isset($values['is_private']) && $values['is_private'] == 1;
|
||||
|
||||
$this->response->html($this->template->layout('project/new', array(
|
||||
'board_selector' => $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()),
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
'is_private' => $is_private,
|
||||
'title' => $is_private ? t('New private project') : t('New project'),
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a form to create a private project
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function createPrivate(array $values = array(), array $errors = array())
|
||||
{
|
||||
$values['is_private'] = 1;
|
||||
$this->create($values, $errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate and save a new project
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->projectValidator->validateCreation($values);
|
||||
|
||||
if ($valid) {
|
||||
$project_id = $this->project->create($values, $this->userSession->getId(), true);
|
||||
|
||||
if ($project_id > 0) {
|
||||
$this->flash->success(t('Your project have been created successfully.'));
|
||||
$this->response->redirect($this->helper->url->to('project', 'show', array('project_id' => $project_id)));
|
||||
}
|
||||
|
||||
$this->flash->failure(t('Unable to create your project.'));
|
||||
}
|
||||
|
||||
$this->create($values, $errors);
|
||||
}
|
||||
}
|
||||
|
||||
126
app/Controller/ProjectCreation.php
Normal file
126
app/Controller/ProjectCreation.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Controller;
|
||||
|
||||
/**
|
||||
* Project Creation Controller
|
||||
*
|
||||
* @package controller
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ProjectCreation extends Base
|
||||
{
|
||||
/**
|
||||
* Display a form to create a new project
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function create(array $values = array(), array $errors = array())
|
||||
{
|
||||
$is_private = isset($values['is_private']) && $values['is_private'] == 1;
|
||||
$projects_list = array(0 => t('Do not duplicate anything')) + $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId());
|
||||
|
||||
$this->response->html($this->template->layout('project_creation/create', array(
|
||||
'board_selector' => $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()),
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
'is_private' => $is_private,
|
||||
'projects_list' => $projects_list,
|
||||
'title' => $is_private ? t('New private project') : t('New project'),
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a form to create a private project
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function createPrivate(array $values = array(), array $errors = array())
|
||||
{
|
||||
$values['is_private'] = 1;
|
||||
$this->create($values, $errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate and save a new project
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->projectValidator->validateCreation($values);
|
||||
|
||||
if ($valid) {
|
||||
$project_id = $this->createOrDuplicate($values);
|
||||
|
||||
if ($project_id > 0) {
|
||||
$this->flash->success(t('Your project have been created successfully.'));
|
||||
return $this->response->redirect($this->helper->url->to('project', 'show', array('project_id' => $project_id)));
|
||||
}
|
||||
|
||||
$this->flash->failure(t('Unable to create your project.'));
|
||||
}
|
||||
|
||||
$this->create($values, $errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or duplicate a project
|
||||
*
|
||||
* @access private
|
||||
* @param array $values
|
||||
* @return boolean|integer
|
||||
*/
|
||||
private function createOrDuplicate(array $values)
|
||||
{
|
||||
if ($values['src_project_id'] == 0) {
|
||||
return $this->createNewProject($values);
|
||||
}
|
||||
|
||||
return $this->duplicateNewProject($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a new project
|
||||
*
|
||||
* @access private
|
||||
* @param array $values
|
||||
* @return boolean|integer
|
||||
*/
|
||||
private function createNewProject(array $values)
|
||||
{
|
||||
$project = array(
|
||||
'name' => $values['name'],
|
||||
'is_private' => $values['is_private'],
|
||||
);
|
||||
|
||||
return $this->project->create($project, $this->userSession->getId(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creatte from another project
|
||||
*
|
||||
* @access private
|
||||
* @param array $values
|
||||
* @return boolean|integer
|
||||
*/
|
||||
private function duplicateNewProject(array $values)
|
||||
{
|
||||
$selection = array();
|
||||
|
||||
foreach ($this->projectDuplication->getOptionalSelection() as $item) {
|
||||
if (isset($values[$item]) && $values[$item] == 1) {
|
||||
$selection[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->projectDuplication->duplicate(
|
||||
$values['src_project_id'],
|
||||
$selection,
|
||||
$this->userSession->getId(),
|
||||
$values['name'],
|
||||
$values['is_private'] == 1
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -89,11 +89,11 @@ class ProjectEdit extends Base
|
||||
{
|
||||
if ($redirect === 'edit') {
|
||||
if (isset($values['is_private'])) {
|
||||
if (! $this->helper->user->hasProjectAccess('project', 'create', $project['id'])) {
|
||||
if (! $this->helper->user->hasProjectAccess('ProjectCreation', 'create', $project['id'])) {
|
||||
unset($values['is_private']);
|
||||
}
|
||||
} elseif ($project['is_private'] == 1 && ! isset($values['is_private'])) {
|
||||
if ($this->helper->user->hasProjectAccess('project', 'create', $project['id'])) {
|
||||
if ($this->helper->user->hasProjectAccess('ProjectCreation', 'create', $project['id'])) {
|
||||
$values += array('is_private' => 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,24 @@ use Kanboard\Core\Security\Role;
|
||||
*/
|
||||
class ProjectPermission extends Base
|
||||
{
|
||||
/**
|
||||
* Permissions are only available for team projects
|
||||
*
|
||||
* @access protected
|
||||
* @param integer $project_id Default project id
|
||||
* @return array
|
||||
*/
|
||||
protected function getProject($project_id = 0)
|
||||
{
|
||||
$project = parent::getProject($project_id);
|
||||
|
||||
if ($project['is_private'] == 1) {
|
||||
$this->forbidden();
|
||||
}
|
||||
|
||||
return $project;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all permissions
|
||||
*
|
||||
@@ -62,6 +80,7 @@ class ProjectPermission extends Base
|
||||
*/
|
||||
public function addUser()
|
||||
{
|
||||
$project = $this->getProject();
|
||||
$values = $this->request->getValues();
|
||||
|
||||
if ($this->projectUserRole->addUser($values['project_id'], $values['user_id'], $values['role'])) {
|
||||
@@ -70,7 +89,7 @@ class ProjectPermission extends Base
|
||||
$this->flash->failure(t('Unable to update this project.'));
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('ProjectPermission', 'index', array('project_id' => $values['project_id'])));
|
||||
$this->response->redirect($this->helper->url->to('ProjectPermission', 'index', array('project_id' => $project['id'])));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,19 +100,16 @@ class ProjectPermission extends Base
|
||||
public function removeUser()
|
||||
{
|
||||
$this->checkCSRFParam();
|
||||
$project = $this->getProject();
|
||||
$user_id = $this->request->getIntegerParam('user_id');
|
||||
|
||||
$values = array(
|
||||
'project_id' => $this->request->getIntegerParam('project_id'),
|
||||
'user_id' => $this->request->getIntegerParam('user_id'),
|
||||
);
|
||||
|
||||
if ($this->projectUserRole->removeUser($values['project_id'], $values['user_id'])) {
|
||||
if ($this->projectUserRole->removeUser($project['id'], $user_id)) {
|
||||
$this->flash->success(t('Project updated successfully.'));
|
||||
} else {
|
||||
$this->flash->failure(t('Unable to update this project.'));
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('ProjectPermission', 'index', array('project_id' => $values['project_id'])));
|
||||
$this->response->redirect($this->helper->url->to('ProjectPermission', 'index', array('project_id' => $project['id'])));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,10 +119,10 @@ class ProjectPermission extends Base
|
||||
*/
|
||||
public function changeUserRole()
|
||||
{
|
||||
$project_id = $this->request->getIntegerParam('project_id');
|
||||
$project = $this->getProject();
|
||||
$values = $this->request->getJson();
|
||||
|
||||
if (! empty($project_id) && ! empty($values) && $this->projectUserRole->changeUserRole($project_id, $values['id'], $values['role'])) {
|
||||
if (! empty($project) && ! empty($values) && $this->projectUserRole->changeUserRole($project['id'], $values['id'], $values['role'])) {
|
||||
$this->response->json(array('status' => 'ok'));
|
||||
} else {
|
||||
$this->response->json(array('status' => 'error'));
|
||||
@@ -120,19 +136,20 @@ class ProjectPermission extends Base
|
||||
*/
|
||||
public function addGroup()
|
||||
{
|
||||
$project = $this->getProject();
|
||||
$values = $this->request->getValues();
|
||||
|
||||
if (empty($values['group_id']) && ! empty($values['external_id'])) {
|
||||
$values['group_id'] = $this->group->create($values['name'], $values['external_id']);
|
||||
}
|
||||
|
||||
if ($this->projectGroupRole->addGroup($values['project_id'], $values['group_id'], $values['role'])) {
|
||||
if ($this->projectGroupRole->addGroup($project['id'], $values['group_id'], $values['role'])) {
|
||||
$this->flash->success(t('Project updated successfully.'));
|
||||
} else {
|
||||
$this->flash->failure(t('Unable to update this project.'));
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('ProjectPermission', 'index', array('project_id' => $values['project_id'])));
|
||||
$this->response->redirect($this->helper->url->to('ProjectPermission', 'index', array('project_id' => $project['id'])));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,19 +160,16 @@ class ProjectPermission extends Base
|
||||
public function removeGroup()
|
||||
{
|
||||
$this->checkCSRFParam();
|
||||
$project = $this->getProject();
|
||||
$group_id = $this->request->getIntegerParam('group_id');
|
||||
|
||||
$values = array(
|
||||
'project_id' => $this->request->getIntegerParam('project_id'),
|
||||
'group_id' => $this->request->getIntegerParam('group_id'),
|
||||
);
|
||||
|
||||
if ($this->projectGroupRole->removeGroup($values['project_id'], $values['group_id'])) {
|
||||
if ($this->projectGroupRole->removeGroup($project['id'], $group_id)) {
|
||||
$this->flash->success(t('Project updated successfully.'));
|
||||
} else {
|
||||
$this->flash->failure(t('Unable to update this project.'));
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('ProjectPermission', 'index', array('project_id' => $values['project_id'])));
|
||||
$this->response->redirect($this->helper->url->to('ProjectPermission', 'index', array('project_id' => $project['id'])));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,10 +179,10 @@ class ProjectPermission extends Base
|
||||
*/
|
||||
public function changeGroupRole()
|
||||
{
|
||||
$project_id = $this->request->getIntegerParam('project_id');
|
||||
$project = $this->getProject();
|
||||
$values = $this->request->getJson();
|
||||
|
||||
if (! empty($project_id) && ! empty($values) && $this->projectGroupRole->changeGroupRole($project_id, $values['id'], $values['role'])) {
|
||||
if (! empty($project) && ! empty($values) && $this->projectGroupRole->changeGroupRole($project['id'], $values['id'], $values['role'])) {
|
||||
$this->response->json(array('status' => 'ok'));
|
||||
} else {
|
||||
$this->response->json(array('status' => 'error'));
|
||||
|
||||
@@ -109,7 +109,7 @@ class Taskduplication extends Base
|
||||
private function chooseDestination(array $task, $template)
|
||||
{
|
||||
$values = array();
|
||||
$projects_list = $this->projectUserRole->getProjectsByUser($this->userSession->getId(), array(ProjectModel::ACTIVE));
|
||||
$projects_list = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId());
|
||||
|
||||
unset($projects_list[$task['project_id']]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user