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) {
$newId = $update->default_board_id;
if ($newId > 0 && !Auth::HasBoardAccess($this->container, $request,
$newId, $user->id)) {
$board = new Board($this->container, $newId);
$board->users[] = $user;
$board->save();
$this->addUserToBoard($newId, $user);
}
if (isset($data->boardAccess)) {
foreach($data->boardAccess as $boardId) {
$this->addUserToBoard($boardId, $user);
}
unset($data->boardAccess);
}
$update->save();
@ -282,6 +284,15 @@ class Users extends BaseController {
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) {
$userBeans = R::findAll('user');
$userId = Auth::GetUserId($request);

View File

@ -18,6 +18,7 @@ class User extends BaseModel {
public $user_option_id = 0;
public $last_login = 0;
public $active_token = '';
public $board_access = [];
public function __construct($container, $id = 0) {
parent::__construct('user', $id, $container);
@ -79,6 +80,16 @@ class User extends BaseModel {
$this->is_valid = true;
$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) {

View File

@ -5,7 +5,8 @@ export class User {
public last_login: Date = null,
public security_level: number = 3,
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() {
// Uncomment to log errors to file
// The tests cover errors, so there will be plenty to sift through
$msg = func_get_arg(0);
$err = 'API ERROR: ' . $msg . PHP_EOL;
// $msg = func_get_arg(0);
// $err = 'API ERROR: ' . $msg . PHP_EOL;
$objs = func_get_args();
array_splice($objs, 0, 1);
// $objs = func_get_args();
// array_splice($objs, 0, 1);
ob_start();
foreach($objs as $obj) {
var_dump($obj);
}
$strings = ob_get_clean();
// ob_start();
// foreach($objs as $obj) {
// var_dump($obj);
// }
// $strings = ob_get_clean();
file_put_contents('tests.log', [$err, $strings], FILE_APPEND);
// file_put_contents('tests.log', [$err, $strings], FILE_APPEND);
}
}