PMCORE-2614
This commit is contained in:
@@ -5,6 +5,11 @@ namespace ProcessMaker\BusinessModel;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class GroupTest
|
||||||
|
*
|
||||||
|
* @coversDefaultClass \ProcessMaker\BusinessModel\Group
|
||||||
|
*/
|
||||||
class GroupTest extends TestCase
|
class GroupTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use ProcessMaker\Model\User;
|
|||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DelegationTest
|
* Class ApplicationTest
|
||||||
*
|
*
|
||||||
* @coversDefaultClass \ProcessMaker\Model\Application
|
* @coversDefaultClass \ProcessMaker\Model\Application
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,10 +2,16 @@
|
|||||||
|
|
||||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
|
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
|
||||||
|
|
||||||
|
use G;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use ProcessMaker\Model\User;
|
use ProcessMaker\Model\User;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class UserTest
|
||||||
|
*
|
||||||
|
* @coversDefaultClass \ProcessMaker\Model\User
|
||||||
|
*/
|
||||||
class UserTest extends TestCase
|
class UserTest extends TestCase
|
||||||
{
|
{
|
||||||
use DatabaseTransactions;
|
use DatabaseTransactions;
|
||||||
@@ -85,6 +91,8 @@ class UserTest extends TestCase
|
|||||||
* It test get users for the new home view
|
* It test get users for the new home view
|
||||||
*
|
*
|
||||||
* @covers \ProcessMaker\Model\User::getUsersForHome()
|
* @covers \ProcessMaker\Model\User::getUsersForHome()
|
||||||
|
* @covers \ProcessMaker\Model\User::scopeActive()
|
||||||
|
* @covers \ProcessMaker\Model\User::scopeWithoutGuest()
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function it_should_test_get_users_for_home()
|
public function it_should_test_get_users_for_home()
|
||||||
@@ -128,4 +136,22 @@ class UserTest extends TestCase
|
|||||||
// Only will considerate by default the actives and limit
|
// Only will considerate by default the actives and limit
|
||||||
$this->assertCount(1, User::getUsersForHome(null, 2, 1));
|
$this->assertCount(1, User::getUsersForHome(null, 2, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It test get the user Id
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\Model\User::getId()
|
||||||
|
* @covers \ProcessMaker\Model\User::scopeUser()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_get_usr_id()
|
||||||
|
{
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
// When the user exist
|
||||||
|
$results = User::getId($user->USR_UID);
|
||||||
|
$this->assertGreaterThan(0, $results);
|
||||||
|
// When the user does not exist
|
||||||
|
$results = User::getId(G::generateUniqueID());
|
||||||
|
$this->assertEquals(0, $results);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -31,6 +31,20 @@ class User extends Model
|
|||||||
return $this->belongsTo(GroupUser::class, 'USR_UID', 'USR_UID');
|
return $this->belongsTo(GroupUser::class, 'USR_UID', 'USR_UID');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope for query to get the user by USR_UID
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||||
|
* @param string $usrUid
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
|
public function scopeUser($query, string $usrUid)
|
||||||
|
{
|
||||||
|
$result = $query->where('USR_UID', '=', $usrUid);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the groups from a user
|
* Return the groups from a user
|
||||||
*
|
*
|
||||||
@@ -157,4 +171,24 @@ class User extends Model
|
|||||||
throw new Exception("Error getting the users: {$e->getMessage()}.");
|
throw new Exception("Error getting the users: {$e->getMessage()}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Get the user id
|
||||||
|
*
|
||||||
|
* @param string $usrUid
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function getId($usrUid)
|
||||||
|
{
|
||||||
|
$query = User::query()->select(['USR_ID'])
|
||||||
|
->user($usrUid)
|
||||||
|
->limit(1);
|
||||||
|
$results = $query->get();
|
||||||
|
$id = 0;
|
||||||
|
$results->each(function ($item) use (&$id) {
|
||||||
|
$id = $item->USR_ID;
|
||||||
|
});
|
||||||
|
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class Home extends Api
|
|||||||
$properties['task'] = $task;
|
$properties['task'] = $task;
|
||||||
// Get the user that access to the API
|
// Get the user that access to the API
|
||||||
$usrUid = $this->getUserId();
|
$usrUid = $this->getUserId();
|
||||||
$properties['user'] = User::find($usrUid)->first()->USR_ID;
|
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||||
// Set the pagination parameters
|
// Set the pagination parameters
|
||||||
$paged = explode(',', $paged);
|
$paged = explode(',', $paged);
|
||||||
$sort = explode(',', $sort);
|
$sort = explode(',', $sort);
|
||||||
@@ -131,7 +131,7 @@ class Home extends Api
|
|||||||
$properties['task'] = $task;
|
$properties['task'] = $task;
|
||||||
// Get the user that access to the API
|
// Get the user that access to the API
|
||||||
$usrUid = $this->getUserId();
|
$usrUid = $this->getUserId();
|
||||||
$properties['user'] = User::find($usrUid)->first()->USR_ID;
|
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||||
// Set the pagination parameters
|
// Set the pagination parameters
|
||||||
$paged = explode(',', $paged);
|
$paged = explode(',', $paged);
|
||||||
$sort = explode(',', $sort);
|
$sort = explode(',', $sort);
|
||||||
@@ -186,7 +186,7 @@ class Home extends Api
|
|||||||
$properties['task'] = $task;
|
$properties['task'] = $task;
|
||||||
// Get the user that access to the API
|
// Get the user that access to the API
|
||||||
$usrUid = $this->getUserId();
|
$usrUid = $this->getUserId();
|
||||||
$properties['user'] = User::find($usrUid)->first()->USR_ID;
|
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||||
// Set the pagination parameters
|
// Set the pagination parameters
|
||||||
$paged = explode(',', $paged);
|
$paged = explode(',', $paged);
|
||||||
$sort = explode(',', $sort);
|
$sort = explode(',', $sort);
|
||||||
@@ -243,7 +243,7 @@ class Home extends Api
|
|||||||
$properties['task'] = $task;
|
$properties['task'] = $task;
|
||||||
// Get the user that access to the API
|
// Get the user that access to the API
|
||||||
$usrUid = $this->getUserId();
|
$usrUid = $this->getUserId();
|
||||||
$properties['user'] = User::find($usrUid)->first()->USR_ID;
|
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||||
// Set the pagination parameters
|
// Set the pagination parameters
|
||||||
$paged = explode(',', $paged);
|
$paged = explode(',', $paged);
|
||||||
$sort = explode(',', $sort);
|
$sort = explode(',', $sort);
|
||||||
@@ -308,7 +308,7 @@ class Home extends Api
|
|||||||
$properties['task'] = $task;
|
$properties['task'] = $task;
|
||||||
// Get the user that access to the API
|
// Get the user that access to the API
|
||||||
$usrUid = $this->getUserId();
|
$usrUid = $this->getUserId();
|
||||||
$properties['user'] = User::find($usrUid)->first()->USR_ID;
|
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||||
$properties['filter'] = $filter;
|
$properties['filter'] = $filter;
|
||||||
$properties['caseStatus'] = $caseStatus;
|
$properties['caseStatus'] = $caseStatus;
|
||||||
$properties['startCaseFrom'] = $startCaseFrom;
|
$properties['startCaseFrom'] = $startCaseFrom;
|
||||||
@@ -370,7 +370,8 @@ class Home extends Api
|
|||||||
$participatedStatuses = ['STARTED', 'IN_PROGRESS', 'COMPLETED', 'SUPERVISING'];
|
$participatedStatuses = ['STARTED', 'IN_PROGRESS', 'COMPLETED', 'SUPERVISING'];
|
||||||
$participatedLabels = array_combine($participatedStatuses, ['ID_OPT_STARTED', 'ID_IN_PROGRESS', 'ID_COMPLETED', 'ID_SUPERVISING']);
|
$participatedLabels = array_combine($participatedStatuses, ['ID_OPT_STARTED', 'ID_IN_PROGRESS', 'ID_COMPLETED', 'ID_SUPERVISING']);
|
||||||
$counters = [];
|
$counters = [];
|
||||||
|
// Get the user that access to the API
|
||||||
|
$usrUid = $this->getUserId();
|
||||||
// Get counters
|
// Get counters
|
||||||
foreach ($participatedStatuses as $participatedStatus) {
|
foreach ($participatedStatuses as $participatedStatus) {
|
||||||
// Initializing counter object
|
// Initializing counter object
|
||||||
@@ -385,12 +386,14 @@ class Home extends Api
|
|||||||
case 'COMPLETED':
|
case 'COMPLETED':
|
||||||
$participated = new Participated();
|
$participated = new Participated();
|
||||||
$participated->setParticipatedStatus($participatedStatus);
|
$participated->setParticipatedStatus($participatedStatus);
|
||||||
$participated->setUserId($this->getUserId());
|
$usrId = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||||
|
$participated->setUserId($usrId);
|
||||||
$counter->counter = $participated->getCounter();
|
$counter->counter = $participated->getCounter();
|
||||||
break;
|
break;
|
||||||
case 'SUPERVISING':
|
case 'SUPERVISING':
|
||||||
$supervising = new Supervising();
|
$supervising = new Supervising();
|
||||||
$supervising->setUserUid($this->getUserId());
|
$usrId = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||||
|
$supervising->setUserUid($usrId);
|
||||||
$counter->counter = $supervising->getCounter();
|
$counter->counter = $supervising->getCounter();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -636,7 +639,7 @@ class Home extends Api
|
|||||||
{
|
{
|
||||||
$result = [];
|
$result = [];
|
||||||
$usrUid = $this->getUserId();
|
$usrUid = $this->getUserId();
|
||||||
$usrId = User::find($usrUid)->first()->USR_ID;
|
$usrId = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||||
// For inbox
|
// For inbox
|
||||||
$inbox = new Inbox();
|
$inbox = new Inbox();
|
||||||
$inbox->setUserUid($usrUid);
|
$inbox->setUserUid($usrUid);
|
||||||
|
|||||||
Reference in New Issue
Block a user