Add user to board when setting default board

This commit is contained in:
kiswa 2016-09-13 21:08:39 +00:00
parent 960457b82b
commit e22e30eccb
4 changed files with 39 additions and 16 deletions

View File

@ -179,12 +179,14 @@ class Users extends BaseController {
if ($user->default_board_id !== $update->default_board_id) { if ($user->default_board_id !== $update->default_board_id) {
$newId = $update->default_board_id; $newId = $update->default_board_id;
if ($newId > 0 && !Auth::HasBoardAccess($this->container, $request, $this->addUserToBoard($newId, $user);
$newId, $user->id)) { }
$board = new Board($this->container, $newId);
$board->users[] = $user; if (isset($data->boardAccess)) {
$board->save(); foreach($data->boardAccess as $boardId) {
$this->addUserToBoard($boardId, $user);
} }
unset($data->boardAccess);
} }
$update->save(); $update->save();
@ -282,6 +284,15 @@ class Users extends BaseController {
return $this->jsonResponse($response); return $this->jsonResponse($response);
} }
private function addUserToBoard($boardId, $user) {
if ($boardId > 0 && !Auth::HasBoardAccess($this->container, $request,
$boardId, $user->id)) {
$board = new Board($this->container, $boardId);
$board->users[] = $user;
$board->save();
}
}
private function getAllUsersCleaned($request) { private function getAllUsersCleaned($request) {
$userBeans = R::findAll('user'); $userBeans = R::findAll('user');
$userId = Auth::GetUserId($request); $userId = Auth::GetUserId($request);

View File

@ -18,6 +18,7 @@ class User extends BaseModel {
public $user_option_id = 0; public $user_option_id = 0;
public $last_login = 0; public $last_login = 0;
public $active_token = ''; public $active_token = '';
public $board_access = [];
public function __construct($container, $id = 0) { public function __construct($container, $id = 0) {
parent::__construct('user', $id, $container); parent::__construct('user', $id, $container);
@ -79,6 +80,16 @@ class User extends BaseModel {
$this->is_valid = true; $this->is_valid = true;
$this->loadPropertiesFrom($bean); $this->loadPropertiesFrom($bean);
$this->board_access = [];
$boards = RedBeanPHP\R::getAll('select bu.board_id, bu.user_id from ' .
'board_user bu join board b on b.id = bu.board_id');
foreach($boards as $item) {
if ($this->id === (int)$item['user_id']) {
$this->board_access[] = (int)$item['board_id'];
}
}
} }
public function loadFromJson($json) { public function loadFromJson($json) {

View File

@ -5,7 +5,8 @@ export class User {
public last_login: Date = null, public last_login: Date = null,
public security_level: number = 3, public security_level: number = 3,
public user_option_id: number = 0, public user_option_id: number = 0,
public username: string = '') { public username: string = '',
public board_acccess: Array<number> = []) {
} }
} }

View File

@ -249,19 +249,19 @@ class LoggerMock {
public function addError() { public function addError() {
// Uncomment to log errors to file // Uncomment to log errors to file
// The tests cover errors, so there will be plenty to sift through // The tests cover errors, so there will be plenty to sift through
$msg = func_get_arg(0); // $msg = func_get_arg(0);
$err = 'API ERROR: ' . $msg . PHP_EOL; // $err = 'API ERROR: ' . $msg . PHP_EOL;
$objs = func_get_args(); // $objs = func_get_args();
array_splice($objs, 0, 1); // array_splice($objs, 0, 1);
ob_start(); // ob_start();
foreach($objs as $obj) { // foreach($objs as $obj) {
var_dump($obj); // var_dump($obj);
} // }
$strings = ob_get_clean(); // $strings = ob_get_clean();
file_put_contents('tests.log', [$err, $strings], FILE_APPEND); // file_put_contents('tests.log', [$err, $strings], FILE_APPEND);
} }
} }