PMCORE-2614
This commit is contained in:
@@ -5,6 +5,11 @@ namespace ProcessMaker\BusinessModel;
|
||||
use Exception;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class GroupTest
|
||||
*
|
||||
* @coversDefaultClass \ProcessMaker\BusinessModel\Group
|
||||
*/
|
||||
class GroupTest extends TestCase
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,7 @@ use ProcessMaker\Model\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class DelegationTest
|
||||
* Class ApplicationTest
|
||||
*
|
||||
* @coversDefaultClass \ProcessMaker\Model\Application
|
||||
*/
|
||||
|
||||
@@ -2,10 +2,16 @@
|
||||
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
|
||||
|
||||
use G;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use ProcessMaker\Model\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class UserTest
|
||||
*
|
||||
* @coversDefaultClass \ProcessMaker\Model\User
|
||||
*/
|
||||
class UserTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
@@ -85,6 +91,8 @@ class UserTest extends TestCase
|
||||
* It test get users for the new home view
|
||||
*
|
||||
* @covers \ProcessMaker\Model\User::getUsersForHome()
|
||||
* @covers \ProcessMaker\Model\User::scopeActive()
|
||||
* @covers \ProcessMaker\Model\User::scopeWithoutGuest()
|
||||
* @test
|
||||
*/
|
||||
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
|
||||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@@ -157,4 +171,24 @@ class User extends Model
|
||||
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;
|
||||
// Get the user that access to the API
|
||||
$usrUid = $this->getUserId();
|
||||
$properties['user'] = User::find($usrUid)->first()->USR_ID;
|
||||
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||
// Set the pagination parameters
|
||||
$paged = explode(',', $paged);
|
||||
$sort = explode(',', $sort);
|
||||
@@ -131,7 +131,7 @@ class Home extends Api
|
||||
$properties['task'] = $task;
|
||||
// Get the user that access to the API
|
||||
$usrUid = $this->getUserId();
|
||||
$properties['user'] = User::find($usrUid)->first()->USR_ID;
|
||||
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||
// Set the pagination parameters
|
||||
$paged = explode(',', $paged);
|
||||
$sort = explode(',', $sort);
|
||||
@@ -186,7 +186,7 @@ class Home extends Api
|
||||
$properties['task'] = $task;
|
||||
// Get the user that access to the API
|
||||
$usrUid = $this->getUserId();
|
||||
$properties['user'] = User::find($usrUid)->first()->USR_ID;
|
||||
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||
// Set the pagination parameters
|
||||
$paged = explode(',', $paged);
|
||||
$sort = explode(',', $sort);
|
||||
@@ -243,7 +243,7 @@ class Home extends Api
|
||||
$properties['task'] = $task;
|
||||
// Get the user that access to the API
|
||||
$usrUid = $this->getUserId();
|
||||
$properties['user'] = User::find($usrUid)->first()->USR_ID;
|
||||
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||
// Set the pagination parameters
|
||||
$paged = explode(',', $paged);
|
||||
$sort = explode(',', $sort);
|
||||
@@ -308,7 +308,7 @@ class Home extends Api
|
||||
$properties['task'] = $task;
|
||||
// Get the user that access to the API
|
||||
$usrUid = $this->getUserId();
|
||||
$properties['user'] = User::find($usrUid)->first()->USR_ID;
|
||||
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||
$properties['filter'] = $filter;
|
||||
$properties['caseStatus'] = $caseStatus;
|
||||
$properties['startCaseFrom'] = $startCaseFrom;
|
||||
@@ -370,7 +370,8 @@ class Home extends Api
|
||||
$participatedStatuses = ['STARTED', 'IN_PROGRESS', 'COMPLETED', 'SUPERVISING'];
|
||||
$participatedLabels = array_combine($participatedStatuses, ['ID_OPT_STARTED', 'ID_IN_PROGRESS', 'ID_COMPLETED', 'ID_SUPERVISING']);
|
||||
$counters = [];
|
||||
|
||||
// Get the user that access to the API
|
||||
$usrUid = $this->getUserId();
|
||||
// Get counters
|
||||
foreach ($participatedStatuses as $participatedStatus) {
|
||||
// Initializing counter object
|
||||
@@ -385,12 +386,14 @@ class Home extends Api
|
||||
case 'COMPLETED':
|
||||
$participated = new Participated();
|
||||
$participated->setParticipatedStatus($participatedStatus);
|
||||
$participated->setUserId($this->getUserId());
|
||||
$usrId = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||
$participated->setUserId($usrId);
|
||||
$counter->counter = $participated->getCounter();
|
||||
break;
|
||||
case 'SUPERVISING':
|
||||
$supervising = new Supervising();
|
||||
$supervising->setUserUid($this->getUserId());
|
||||
$usrId = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||
$supervising->setUserUid($usrId);
|
||||
$counter->counter = $supervising->getCounter();
|
||||
break;
|
||||
default:
|
||||
@@ -636,7 +639,7 @@ class Home extends Api
|
||||
{
|
||||
$result = [];
|
||||
$usrUid = $this->getUserId();
|
||||
$usrId = User::find($usrUid)->first()->USR_ID;
|
||||
$usrId = !empty($usrUid) ? User::getId($usrUid) : 0;
|
||||
// For inbox
|
||||
$inbox = new Inbox();
|
||||
$inbox->setUserUid($usrUid);
|
||||
|
||||
Reference in New Issue
Block a user