PMCORE-2887

This commit is contained in:
Andrea Adamczyk
2021-03-17 12:25:11 -04:00
parent 9edceb3f5f
commit 01bde5f225
16 changed files with 966 additions and 3 deletions

View File

@@ -85,6 +85,7 @@ define("PATH_DATA_MAILTEMPLATES", PATH_DATA_SITE . "mailTemplates/");
define("PATH_DATA_PUBLIC", PATH_DATA_SITE . "public/"); define("PATH_DATA_PUBLIC", PATH_DATA_SITE . "public/");
define("PATH_CONTROLLERS", PATH_CORE . "controllers" . PATH_SEP); define("PATH_CONTROLLERS", PATH_CORE . "controllers" . PATH_SEP);
define("PATH_SKIN_ENGINE", PATH_CORE . "skinEngine" . PATH_SEP); define("PATH_SKIN_ENGINE", PATH_CORE . "skinEngine" . PATH_SEP);
define("PATH_IMAGES_ENVIRONMENT_USERS", PATH_DATA_SITE . "usersPhotographies" . PATH_SEP);
G::defineConstants(); G::defineConstants();
/** /**

View File

@@ -0,0 +1,248 @@
<?php
namespace Tests\unit\workflow\engine\classes\PmFunctions;
use ProcessMaker\Model\GroupUser;
use ProcessMaker\Model\Groupwf;
use ProcessMaker\Model\RbacUsers;
use ProcessMaker\Model\User;
use RBAC;
use Tests\TestCase;
class PMFNewUserTest extends TestCase
{
/**
* Creates the setUp method
*/
public function setUp()
{
if (!defined('PPP_NUMERICAL_CHARACTER_REQUIRED')) {
define('PPP_NUMERICAL_CHARACTER_REQUIRED', 1);
}
if (!defined('PPP_UPPERCASE_CHARACTER_REQUIRED')) {
define('PPP_UPPERCASE_CHARACTER_REQUIRED', 1);
}
if (!defined('PPP_SPECIAL_CHARACTER_REQUIRED')) {
define('PPP_SPECIAL_CHARACTER_REQUIRED', 1);
}
}
/**
* It tests the PMFNewUser() function
*
* @test
*/
public function it_should_test_the_pmfnewuser_function()
{
global $RBAC;
$user = User::where('USR_ID', '=', 1)->get()->first();
$_SESSION['USER_LOGGED'] = $user['USR_UID'];
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
$RBAC->initRBAC();
$RBAC->loadUserRolePermission('PROCESSMAKER', $_SESSION['USER_LOGGED']);
$group = factory(Groupwf::class)->create();
$result = PMFNewUser("test", "Test123*", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, $group['GRP_UID']);
$query = GroupUser::select();
$r = $query->get()->values()->toArray();
$this->assertEquals($r[0]['GRP_UID'], $result['groupUid']);
$this->assertEquals($r[0]['USR_UID'], $result['userUid']);
$query = RbacUsers::select()->where('USR_UID', $result['userUid']);
$r = $query->get()->values()->toArray();
$this->assertNotEmpty($r);
$this->assertEquals($result['userUid'], $r[0]['USR_UID']);
$this->assertEquals($result['username'], $r[0]['USR_USERNAME']);
}
/**
* It tests the exception user is required in the PMFNewUser() function
*
* @test
*/
public function it_should_test_exception_user_required()
{
$this->expectExceptionMessage('**ID_USERNAME_REQUIRED**');
PMFNewUser("", "test123", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
}
/**
* It tests the exception lastname is required in the PMFNewUser() function
*
* @test
*/
public function it_should_test_exception_lastname_required()
{
$this->expectExceptionMessage('**ID_MSG_ERROR_USR_LASTNAME**');
PMFNewUser("test", "test123", "test", "", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
}
/**
* It tests the exception firstname is required in the PMFNewUser() function
*
* @test
*/
public function it_should_test_exception_firstname_required()
{
$this->expectExceptionMessage('**ID_MSG_ERROR_USR_FIRSTNAME**');
PMFNewUser("test", "test123", "", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
}
/**
* It tests the exception password is required in the PMFNewUser() function
*
* @test
*/
public function it_should_test_exception_password_required()
{
$this->expectExceptionMessage('**ID_PASSWD_REQUIRED**');
PMFNewUser("test", "", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
}
/**
* It tests the exception email is required in the PMFNewUser() function
*
* @test
*/
public function it_should_test_exception_email_required()
{
$this->expectExceptionMessage('**ID_EMAIL_IS_REQUIRED**');
PMFNewUser("test", "test123", "test", "test", "", "PROCESSMAKER_ADMIN", null, null, null);
}
/**
* It tests the email format exception in the PMFNewUser() function
*
* @test
*/
public function it_should_test_email_format_exception()
{
$this->expectExceptionMessage('**ID_EMAIL_INVALID**');
PMFNewUser("test2", "Test123*", "test", "test", "test@test", "PROCESSMAKER_ADMIN", null, null, null);
}
/**
* It tests the due date format exception in the PMFNewUser() function
*
* @test
*/
public function it_should_test_duedate_format_exception()
{
$this->expectExceptionMessage('**ID_INVALID_DATA**');
PMFNewUser("test2", "test123", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", '121212', null, null);
}
/**
* It tests the status exception in the PMFNewUser() function
*
* @test
*/
public function it_should_test_status_exception()
{
$this->expectExceptionMessage('**ID_INVALID_DATA**');
PMFNewUser("test2", "test123", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, 'ACTI', null);
}
/**
* It tests the rol exception in the PMFNewUser() function
*
* @test
*/
public function it_should_test_rol_exception()
{
$this->expectExceptionMessage('**ID_INVALID_ROLE**');
PMFNewUser("test2", "test13", "test", "test", "test@test.com", "PROCESSMAKER_ADM", null, null, null);
}
/**
* It tests the password surprases exception in the PMFNewUser() function
*
* @test
*/
public function it_should_test_password_surprases_exception()
{
$this->expectExceptionMessage('**ID_PASSWORD_SURPRASES**');
PMFNewUser("test2", "123456789012345678901234567890", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
}
/**
* It tests the password numerical character required exception in the PMFNewUser() function
*
* @test
*/
public function it_should_test_password_numerical_exception()
{
$this->expectExceptionMessage('**ID_PPP_NUMERICAL_CHARACTER_REQUIRED**');
PMFNewUser("test2", "TestA*", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
}
/**
* It tests the password uppercase character required exception in the PMFNewUser() function
*
* @test
*/
public function it_should_test_password_uppercase_exception()
{
$this->expectExceptionMessage('**ID_PPP_UPPERCASE_CHARACTER_REQUIRED**');
PMFNewUser("test2", "test1*", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
}
/**
* It tests the password special character required exception in the PMFNewUser() function
*
* @test
*/
public function it_should_test_password_special_character_exception()
{
$this->expectExceptionMessage('**ID_PPP_SPECIAL_CHARACTER_REQUIRED**');
PMFNewUser("test2", "Test1", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
}
/**
* It tests the password below exception in the PMFNewUser() function
*
* @test
*/
public function it_should_test_password_below_exception()
{
$this->expectExceptionMessage('**ID_PASSWORD_BELOW**');
PMFNewUser("test2", "test", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
}
/**
* It tests the username exists exception in the PMFNewUser() function
*
* @test
*/
public function it_should_test_username_exists_exception()
{
$this->expectExceptionMessage('**ID_USERNAME_ALREADY_EXISTS**');
PMFNewUser("test", "Test12345*", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, null);
}
/**
* It tests the email is invalid exception in the PMFNewUser() function
*
* @test
*/
public function it_should_test_email_invalid_exception()
{
$this->expectExceptionMessage('**ID_EMAIL_INVALID**');
PMFNewUser("test3", "Test12345*", "test", "test", "test@test", "PROCESSMAKER_ADMIN", null, null, null);
}
/**
* It tests the group does not exists exception in the PMFNewUser() function
*
* @test
*/
public function it_should_test_group_doesnot_exists_exception()
{
$this->expectExceptionMessage('**ID_GROUP_DOESNT_EXIST**');
PMFNewUser("test3", "Test12345*", "test", "test", "test@test.com", "PROCESSMAKER_ADMIN", null, null, '1234');
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use ProcessMaker\Model\GroupUser;
use ProcessMaker\Model\Groupwf;
use ProcessMaker\Model\RbacUsers;
use ProcessMaker\Model\User;
use Tests\TestCase;
/**
* Class ProcessTest
*
* @coversDefaultClass \ProcessMaker\Model\GroupUser
*/
class GroupUserTest extends TestCase
{
use DatabaseTransactions;
/**
* It tests the assignUserToGroup() method
*
* @test
*/
public function it_should_test_the_assign_user_to_group_method()
{
$rbacUser = factory(RbacUsers::class)->create();
$user = factory(User::class)->create([
'USR_UID' => $rbacUser['USR_UID'],
'USR_USERNAME' => $rbacUser['USR_USERNAME'],
'USR_PASSWORD' => $rbacUser['USR_PASSWORD'],
'USR_FIRSTNAME' => $rbacUser['USR_FIRSTNAME'],
'USR_LASTNAME' => $rbacUser['USR_LASTNAME'],
'USR_EMAIL' => $rbacUser['USR_EMAIL'],
]);
$group = factory(Groupwf::class)->create();
GroupUser::assignUserToGroup($rbacUser['USR_UID'], $user['USR_ID'], $group['GRP_UID'], $group['GRP_ID']);
$query = GroupUser::select()->where('GRP_ID', $group['GRP_ID'])->where('USR_ID', $user['USR_ID']);
$res = $query->get()->values()->toArray();
$this->assertNotEmpty($res);
}
/**
* It tests the verifyUserIsInGroup() method
*
* @test
*/
public function it_should_test_the_verify_user_is_in_group_method()
{
$rbacUser = factory(RbacUsers::class)->create();
$user = factory(User::class)->create([
'USR_UID' => $rbacUser['USR_UID'],
'USR_USERNAME' => $rbacUser['USR_USERNAME'],
'USR_PASSWORD' => $rbacUser['USR_PASSWORD'],
'USR_FIRSTNAME' => $rbacUser['USR_FIRSTNAME'],
'USR_LASTNAME' => $rbacUser['USR_LASTNAME'],
'USR_EMAIL' => $rbacUser['USR_EMAIL'],
]);
$group = factory(Groupwf::class)->create();
$res = GroupUser::verifyUserIsInGroup($user['USR_ID'], $group['GRP_ID']);
$this->assertFalse($res);
GroupUser::assignUserToGroup($rbacUser['USR_UID'], $user['USR_ID'], $group['GRP_UID'], $group['GRP_ID']);
$res = GroupUser::verifyUserIsInGroup($user['USR_ID'], $group['GRP_ID']);
$this->assertTrue($res);
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use ProcessMaker\Model\Groupwf;
use Tests\TestCase;
/**
* Class ProcessTest
*
* @coversDefaultClass \ProcessMaker\Model\Groupwf
*/
class GroupwfTest extends TestCase
{
use DatabaseTransactions;
/**
* It tests the verifyGroupExists() method
*
* @test
*/
public function it_should_test_the_verify_group_exists_method()
{
$groupWf = factory(Groupwf::class)->create();
$res = Groupwf::verifyGroupExists($groupWf['GRP_UID']);
$this->assertTrue($res);
$res = Groupwf::verifyGroupExists('12345');
$this->assertFalse($res);
}
/**
* It tests the getGroupId() method
*
* @test
*/
public function it_should_test_the_get_group_id_method()
{
$groupWf = factory(Groupwf::class)->create();
$res = Groupwf::getGroupId($groupWf['GRP_UID']);
$this->assertNotEmpty($res);
$this->assertEquals($res['GRP_ID'], $groupWf['GRP_ID']);
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use ProcessMaker\Model\RbacRoles;
use Tests\TestCase;
/**
* Class ProcessTest
*
* @coversDefaultClass \ProcessMaker\Model\RbacRoles
*/
class RbacRolesTest extends TestCase
{
use DatabaseTransactions;
/**
* It tests the getRolUidByCode() method
*
* @test
*/
public function it_should_test_the_get_rol_uid_by_code_method()
{
$rol1 = factory(RbacRoles::class)->create([
'ROL_CODE' => 'TEST_ROLE'
]);
$rolUid = RbacRoles::getRolUidByCode('TEST_ROLE');
$this->assertEquals($rolUid['ROL_UID'], $rol1->ROL_UID);
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
use G;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use ProcessMaker\Model\RbacRoles;
use ProcessMaker\Model\RbacUsers;
use Tests\TestCase;
/**
* Class ProcessTest
*
* @coversDefaultClass \ProcessMaker\Model\SubProcess
*/
class RbacUsersTest extends TestCase
{
use DatabaseTransactions;
/**
* It tests the verifyUsernameExists() method
*
* @test
*/
public function it_should_test_the_verify_username_exists_method()
{
$rbacUser = factory(RbacUsers::class)->create([
'USR_USERNAME' => 'test'
]);
$res = RbacUsers::verifyUsernameExists('test');
$this->assertTrue($res);
$res = RbacUsers::verifyUsernameExists('test2');
$this->assertFalse($res);
}
/**
* It tests the createUser() method
*
* @test
*/
public function it_should_test_the_create_user_method()
{
$roles = factory(RbacRoles::class)->create();
$data = [
'USR_UID' => G::generateUniqueID(),
'USR_USERNAME' => 'test',
'USR_PASSWORD' => 'sample',
'USR_FIRSTNAME' => 'test',
'USR_LASTNAME' => 'test',
'USR_EMAIL' => 'test@test.com',
'USR_DUE_DATE' => '2021-01-01',
'USR_CREATE_DATE' => '2021-01-01',
'USR_UPDATE_DATE' => '2021-01-01',
'USR_STATUS_ID' => 1,
'USR_AUTH_TYPE' => '',
'UID_AUTH_SOURCE' => '',
'USR_AUTH_USER_DN' => '',
'USR_AUTH_SUPERVISOR_DN' => '',
'ROL_UID' => $roles['ROL_UID']
];
$res = RbacUsers::createUser($data);
$this->assertNotEmpty($res);
}
/**
* It tests the verifyUserExists() method
*
* @test
*/
public function it_should_test_the_verify_user_exists_method()
{
$rbacUser = factory(RbacUsers::class)->create();
$res = RbacUsers::verifyUserExists($rbacUser['USR_UID']);
$this->assertTrue($res);
$res = RbacUsers::verifyUserExists('12345');
$this->assertFalse($res);
}
}

View File

@@ -189,4 +189,39 @@ class UserTest extends TestCase
$results = User::getAllInformation($user->USR_ID); $results = User::getAllInformation($user->USR_ID);
$this->assertNotEmpty($results); $this->assertNotEmpty($results);
} }
/**
* It test get the createUser() method
*
* @covers \ProcessMaker\Model\User::createUser()
* @test
*/
public function it_should_test_the_create_user_method()
{
$usrData = [
'USR_UID' => G::generateUniqueID(),
'USR_USERNAME' => 'test',
'USR_PASSWORD' => 'sample',
'USR_FIRSTNAME' => 'test',
'USR_LASTNAME' => 'test',
'USR_EMAIL' => 'test@sample.com',
'USR_DUE_DATE' => '2021-12-12',
'USR_CREATE_DATE' => '2021-12-12',
'USR_UPDATE_DATE' => '2021-12-12',
'USR_STATUS' => 'ACTIVE',
'USR_STATUS_ID' => 1,
'USR_COUNTRY' => '',
'USR_CITY' => '',
'USR_LOCATION' => '',
'USR_ADDRESS' => '',
'USR_PHONE' => '',
'USR_FAX' => '',
'USR_CELLULAR' => '',
'USR_ZIP_CODE' => '',
'DEP_UID' => '',
'USR_POSITION' => '',
'USR_RESUME' => ''
];
$res = User::createUser($usrData);
$this->assertInternalType('integer', $res);
}
} }

View File

@@ -1,12 +1,17 @@
<?php <?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use ProcessMaker\BusinessModel\Cases as BusinessModelCases; use ProcessMaker\BusinessModel\Cases as BusinessModelCases;
use ProcessMaker\Core\System; use ProcessMaker\Core\System;
use ProcessMaker\Model\GroupUser;
use ProcessMaker\Model\Groupwf;
use ProcessMaker\Model\RbacRoles;
use ProcessMaker\Model\RbacUsers;
use ProcessMaker\Model\User;
use ProcessMaker\Plugins\PluginRegistry; use ProcessMaker\Plugins\PluginRegistry;
use ProcessMaker\Util\ElementTranslation; use ProcessMaker\Util\ElementTranslation;
use ProcessMaker\Validation\SqlBlacklist; use ProcessMaker\Validation\SqlBlacklist;
use Illuminate\Support\Facades\DB;
/** /**
* ProcessMaker has made a number of its PHP functions available be used in triggers and conditions. * ProcessMaker has made a number of its PHP functions available be used in triggers and conditions.
@@ -4013,6 +4018,202 @@ function PMFSendMessageToGroup(
return 1; return 1;
} }
/**
* @method
*
* Create a new user
*
* @name PMFNewUser
* @label PMF New User
*
* @param string | $username
* @param string | $password
* @param string | $firstname
* @param string | $lastname
* @param string | $email
* @param string | $role
* @param string | $dueDate = null
* @param string | $status = null
* @param string | $group =null
*
* @return array | $response | Response
*/
function PMFNewUser(
$username,
$password,
$firstname,
$lastname,
$email,
$role,
$dueDate = null,
$status = null,
$group = null)
{
if (empty($username)) {
throw new Exception(G::LoadTranslation('ID_USERNAME_REQUIRED'));
}
if (empty($firstname)) {
throw new Exception(G::LoadTranslation('ID_MSG_ERROR_USR_FIRSTNAME'));
}
if (empty($lastname)) {
throw new Exception(G::LoadTranslation('ID_MSG_ERROR_USR_LASTNAME'));
}
if (empty($password)) {
throw new Exception(G::LoadTranslation('ID_PASSWD_REQUIRED'));
}
if (empty($email)) {
throw new Exception(G::LoadTranslation('ID_EMAIL_IS_REQUIRED'));
}
if (!empty($dueDate) && $dueDate != 'null' && $dueDate != '' && $dueDate) {
if (!preg_match("/^(\d{4})-(\d{2})-(\d{2})$/", $dueDate, $match)) {
throw new Exception(G::LoadTranslation('ID_INVALID_DATA'));
} else {
$dueDate = mktime(
0,
0,
0,
intval($match[2]),
intval($match[3]),
intval($match[1])
);
}
} else {
$expirationDate = 1;
$envFile = PATH_CONFIG . 'env.ini';
if (file_exists($envFile)) {
$sysConf = System::getSystemConfiguration($envFile);
if (isset($sysConf['expiration_year']) && $sysConf['expiration_year'] > 0) {
$expirationDate = abs($sysConf['expiration_year']);
}
}
$dueDate = mktime(0, 0, 0, 12, 31, date("Y") + $expirationDate);
}
if (!empty($status) && $status != null && $status != "" && $status) {
if ($status != "ACTIVE" && $status != "INACTIVE" && $status != "VACATION") {
throw new Exception(G::LoadTranslation('ID_INVALID_DATA'));
}
} else {
$status = "ACTIVE";
}
$rolUid = RbacRoles::getRolUidByCode($role);
if (empty($rolUid)) {
throw new Exception(G::LoadTranslation('ID_INVALID_ROLE'));
}
$userProperties = new UsersProperties();
$validation = $userProperties->validatePassword($password, '', 0);
if (in_array('ID_PPP_MAXIMUM_LENGTH', $validation)) {
throw new Exception(G::LoadTranslation('ID_PASSWORD_SURPRASES'));
}
if (in_array('ID_PPP_MINIMUM_LENGTH', $validation)) {
throw new Exception(G::LoadTranslation('ID_PASSWORD_BELOW'));
}
if (in_array('ID_PPP_NUMERICAL_CHARACTER_REQUIRED', $validation)) {
throw new Exception(G::LoadTranslation('ID_PPP_NUMERICAL_CHARACTER_REQUIRED'));
}
if (in_array('ID_PPP_UPPERCASE_CHARACTER_REQUIRED', $validation)) {
throw new Exception(G::LoadTranslation('ID_PPP_UPPERCASE_CHARACTER_REQUIRED'));
}
if (in_array('ID_PPP_SPECIAL_CHARACTER_REQUIRED', $validation)) {
throw new Exception(G::LoadTranslation('ID_PPP_SPECIAL_CHARACTER_REQUIRED'));
}
if (RbacUsers::verifyUsernameExists($username)) {
throw new Exception(G::LoadTranslation('ID_USERNAME_ALREADY_EXISTS'));
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new Exception(G::LoadTranslation('ID_EMAIL_INVALID'));
}
if (!is_null($group) && $group != '' && !Groupwf::verifyGroupExists($group)) {
throw new Exception(G::LoadTranslation('ID_GROUP_DOESNT_EXIST'));
}
switch ($status) {
case 'ACTIVE':
$statusId = 1;
break;
case 'INACTIVE':
$statusId = 0;
break;
case 'VACATION':
$statusId = 0;
break;
}
$usrUid = G::generateUniqueID();
$data = [
'USR_UID' => $usrUid,
'USR_USERNAME' => $username,
'USR_PASSWORD' => Bootstrap::hashPassword($password),
'USR_FIRSTNAME' => $firstname,
'USR_LASTNAME' => $lastname,
'USR_EMAIL' => $email,
'USR_DUE_DATE' => date('Y-m-d', $dueDate),
'USR_CREATE_DATE' => date("Y-m-d H:i:s"),
'USR_UPDATE_DATE' => date("Y-m-d H:i:s"),
'USR_STATUS' => $status,
'USR_AUTH_TYPE' => '',
'UID_AUTH_SOURCE' => '',
'USR_AUTH_USER_DN' => "",
'USR_AUTH_SUPERVISOR_DN' => "",
'USR_STATUS_ID' => $statusId,
'USR_COUNTRY' => '',
'USR_CITY' => '',
'USR_LOCATION' => '',
'USR_ADDRESS' => '',
'USR_PHONE' => '',
'USR_FAX' => '',
'USR_CELLULAR' => '',
'USR_ZIP_CODE' => '',
'DEP_UID' => '',
'USR_POSITION' => '',
'USR_RESUME' => '',
'ROL_CODE' => $role,
'ROL_UID' => $rolUid['ROL_UID']
];
RbacUsers::createUser($data);
$usrId = User::createUser($data);
$data['USR_ID'] = $usrId;
if (!is_null($group) && $group != '') {
$grpId = Groupwf::getGroupId($group);
$data['GRP_ID'] = $grpId['GRP_ID'];
GroupUser::assignUserToGroup($usrUid, $usrUid, $group, $grpId['GRP_ID']);
}
$response = [
'userUid' => $data['USR_UID'],
'userId' => $data['USR_ID'],
'username' => $data['USR_USERNAME'],
'password' => $data['USR_PASSWORD'],
'firstname' => $data['USR_FIRSTNAME'],
'lastname' => $data['USR_LASTNAME'],
'email' => $data['USR_EMAIL'],
'role' => $data['ROL_CODE'],
'dueDate' => $data['USR_DUE_DATE'],
'status' => $data['USR_STATUS'],
'groupUid' => $group
];
return $response;
}
//Start - Private functions //Start - Private functions

View File

@@ -457,6 +457,12 @@ msgstr "The mail is invalid"
msgid "Mail To is required, or uncheck the Send a Test Mail option" msgid "Mail To is required, or uncheck the Send a Test Mail option"
msgstr "Mail To is required, or uncheck the Send a Test Mail option" msgstr "Mail To is required, or uncheck the Send a Test Mail option"
# TRANSLATION
# JAVASCRIPT/ID_EMAIL_IS_REQUIRED
#: JAVASCRIPT/ID_EMAIL_IS_REQUIRED
msgid "Email is required"
msgstr "Email is required"
# TRANSLATION # TRANSLATION
# JAVASCRIPT/ID_EMPTY_NODENAME # JAVASCRIPT/ID_EMPTY_NODENAME
#: JAVASCRIPT/ID_EMPTY_NODENAME #: JAVASCRIPT/ID_EMPTY_NODENAME
@@ -21197,6 +21203,12 @@ msgstr "The current password is incorrect"
msgid "Password is longer than the maximum allowed length" msgid "Password is longer than the maximum allowed length"
msgstr "Password is longer than the maximum allowed length" msgstr "Password is longer than the maximum allowed length"
# TRANSLATION
# LABEL/ID_PASSWORD_BELOW
#: LABEL/ID_PASSWORD_BELOW
msgid "Password is below than the maximum allowed length"
msgstr "Password is below than the maximum allowed length"
# TRANSLATION # TRANSLATION
# LABEL/ID_PASSWORD_TESTING # LABEL/ID_PASSWORD_TESTING
#: LABEL/ID_PASSWORD_TESTING #: LABEL/ID_PASSWORD_TESTING
@@ -27881,6 +27893,12 @@ msgstr "Reassign to:"
msgid "The row '{USR_UID}' in table USER doesn't exist!" msgid "The row '{USR_UID}' in table USER doesn't exist!"
msgstr "The row '{USR_UID}' in table USER doesn't exist!" msgstr "The row '{USR_UID}' in table USER doesn't exist!"
# TRANSLATION
# LABEL/ID_GROUP_DOESNT_EXIST
#: LABEL/ID_GROUP_DOESNT_EXIST
msgid "The group '{GRP_UID}' doesn't exist!"
msgstr "The group '{GRP_UID}' doesn't exist!"
# TRANSLATION # TRANSLATION
# LABEL/ID_USER_WITH_ROLE # LABEL/ID_USER_WITH_ROLE
#: LABEL/ID_USER_WITH_ROLE #: LABEL/ID_USER_WITH_ROLE

View File

@@ -56870,6 +56870,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'JAVASCRIPT','ID_EDIT_STAGES_MAP','en','Edit Stages Map','2014-01-15') , ( 'JAVASCRIPT','ID_EDIT_STAGES_MAP','en','Edit Stages Map','2014-01-15') ,
( 'JAVASCRIPT','ID_EMAIL_INVALID','en','The mail is invalid','2014-01-15') , ( 'JAVASCRIPT','ID_EMAIL_INVALID','en','The mail is invalid','2014-01-15') ,
( 'JAVASCRIPT','ID_EMAIL_REQUIRED','en','Mail To is required, or uncheck the Send a Test Mail option','2014-01-15') , ( 'JAVASCRIPT','ID_EMAIL_REQUIRED','en','Mail To is required, or uncheck the Send a Test Mail option','2014-01-15') ,
( 'JAVASCRIPT','ID_EMAIL_IS_REQUIRED','en','Email is required','2021-04-08') ,
( 'JAVASCRIPT','ID_EMPTY_NODENAME','en','The field name contains spaces or it''s empty!','2014-01-15') , ( 'JAVASCRIPT','ID_EMPTY_NODENAME','en','The field name contains spaces or it''s empty!','2014-01-15') ,
( 'JAVASCRIPT','ID_ENABLE_WORKSPACE_CONFIRM','en','Do you want enable the selected workspace?','2014-01-15') , ( 'JAVASCRIPT','ID_ENABLE_WORKSPACE_CONFIRM','en','Do you want enable the selected workspace?','2014-01-15') ,
( 'JAVASCRIPT','ID_END_OF_PROCESS','en','End of process','2014-01-15') , ( 'JAVASCRIPT','ID_END_OF_PROCESS','en','End of process','2014-01-15') ,
@@ -60429,6 +60430,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_PASSWORD_CURRENT_ENTER','en','Enter the current password','2014-01-15') , ( 'LABEL','ID_PASSWORD_CURRENT_ENTER','en','Enter the current password','2014-01-15') ,
( 'LABEL','ID_PASSWORD_CURRENT_INCORRECT','en','The current password is incorrect','2014-01-15') , ( 'LABEL','ID_PASSWORD_CURRENT_INCORRECT','en','The current password is incorrect','2014-01-15') ,
( 'LABEL','ID_PASSWORD_SURPRASES','en','Password is longer than the maximum allowed length','2015-01-16') , ( 'LABEL','ID_PASSWORD_SURPRASES','en','Password is longer than the maximum allowed length','2015-01-16') ,
( 'LABEL','ID_PASSWORD_BELOW','en','Password is below than the maximum allowed length','2021-04-08') ,
( 'LABEL','ID_PASSWORD_TESTING','en','Testing password','2014-01-15') , ( 'LABEL','ID_PASSWORD_TESTING','en','Testing password','2014-01-15') ,
( 'LABEL','ID_PATH','en','Path','2014-01-15') , ( 'LABEL','ID_PATH','en','Path','2014-01-15') ,
( 'LABEL','ID_PAUSE','en','Pause','2014-01-15') , ( 'LABEL','ID_PAUSE','en','Pause','2014-01-15') ,
@@ -61608,6 +61610,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_USER_SAVE_FAIL','en','Failed saving User Assigned to Task','2014-01-15') , ( 'LABEL','ID_USER_SAVE_FAIL','en','Failed saving User Assigned to Task','2014-01-15') ,
( 'LABEL','ID_USER_TO_REASSIGN','en','Reassign to:','2014-01-15') , ( 'LABEL','ID_USER_TO_REASSIGN','en','Reassign to:','2014-01-15') ,
( 'LABEL','ID_USER_UID_DOESNT_EXIST','en','The row ''{USR_UID}'' in table USER doesn''t exist!','2014-01-15') , ( 'LABEL','ID_USER_UID_DOESNT_EXIST','en','The row ''{USR_UID}'' in table USER doesn''t exist!','2014-01-15') ,
( 'LABEL','ID_GROUP_DOESNT_EXIST','en','The group ''{GRP_UID}'' doesn''t exist!','2021-04-08') ,
( 'LABEL','ID_USER_WITH_ROLE','en','Users with role','2014-01-15') , ( 'LABEL','ID_USER_WITH_ROLE','en','Users with role','2014-01-15') ,
( 'LABEL','ID_USE_ALPHANUMERIC_CHARACTERS_INCLUDING','en','Please just use alphanumeric characters including: {0}','2020-12-22') , ( 'LABEL','ID_USE_ALPHANUMERIC_CHARACTERS_INCLUDING','en','Please just use alphanumeric characters including: {0}','2020-12-22') ,
( 'LABEL','ID_USE_LANGUAGE_URL','en','Use the language of URL','2014-08-08') , ( 'LABEL','ID_USE_LANGUAGE_URL','en','Use the language of URL','2014-08-08') ,

View File

@@ -2,7 +2,11 @@
namespace ProcessMaker\Model; namespace ProcessMaker\Model;
use Exception;
use G;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use ProcessMaker\Model\Groupwf;
use ProcessMaker\Model\RbacUsers;
class GroupUser extends Model class GroupUser extends Model
{ {
@@ -57,5 +61,57 @@ class GroupUser extends Model
return $groups; return $groups;
} }
}
/**
* Verify if a user is already assigned to a group
*
* @param int $usrId
* @param int $grpId
*
* @return boolean
*/
public static function verifyUserIsInGroup($usrId, $grpId)
{
$query = GroupUser::select()->where('GRP_ID', $grpId)->where('USR_ID', $usrId);
if (empty($query->get()->values()->toArray())) {
return false;
}
return true;
}
/**
* Assign user to group
*
* @param string $usrUid
* @param int $usrId
* @param string $grpUid
* @param int $grpId
*
* @return void
* @throws Exception
*/
public static function assignUserToGroup($usrUid, $usrId, $grpUid, $grpId)
{
if (!RbacUsers::verifyUserExists($usrUid)) {
return ['message' => G::loadTranslation('ID_USER_NOT_REGISTERED_SYSTEM')];
}
if (!Groupwf::verifyGroupExists($grpUid)) {
return ['message' => G::loadTranslation('ID_GROUP_NOT_REGISTERED_SYSTEM')];
}
if (GroupUser::verifyUserIsInGroup($usrId, $grpId)) {
return ['message' => G::loadTranslation('ID_USER_ALREADY_EXISTS_GROUP')];
}
try {
$data = [
'GRP_UID' => $grpUid,
'GRP_ID' => $grpId,
'USR_UID' => $usrUid,
'USR_ID' => $usrId,
];
GroupUser::insert($data);
} catch (Exception $e) {
throw new Exception("Error: {$e->getMessage()}.");
}
}
}

View File

@@ -42,5 +42,31 @@ class Groupwf extends Model
{ {
return $query->where('GRP_UID', $uid); return $query->where('GRP_UID', $uid);
} }
}
/**
* Verify if group exists
*
* @param string $grpUid
* @return boolean
*/
public static function verifyGroupExists($grpUid)
{
$query = Groupwf::select()->group($grpUid);
if (empty($query->get()->values()->toArray())) {
return false;
}
return true;
}
/**
* Get group Id
*
* @param string $grpUid
* @return array
*/
public static function getGroupId($grpUid)
{
$query = Groupwf::select('GRP_ID')->where('GRP_UID', $grpUid);
return $query->get()->first()->toArray();
}
}

View File

@@ -9,4 +9,22 @@ class RbacRoles extends Model
protected $table = 'RBAC_ROLES'; protected $table = 'RBAC_ROLES';
public $timestamps = false; public $timestamps = false;
/**
* Get rol Uid by code
*
* @param string $rolCode
*
* @return array
*/
public static function getRolUidByCode($rolCode)
{
$query = RbacRoles::select('ROL_UID')->where('ROL_CODE', $rolCode);
$query = $query->get()->first();
if (is_null($query)) {
return [];
} else {
return $query->toArray();
}
}
} }

View File

@@ -2,11 +2,77 @@
namespace ProcessMaker\Model; namespace ProcessMaker\Model;
use Exception;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use ProcessMaker\Model\RbacUsersRoles;
class RbacUsers extends Model class RbacUsers extends Model
{ {
protected $table = 'RBAC_USERS'; protected $table = 'RBAC_USERS';
public $timestamps = false; public $timestamps = false;
/**
* Create a new user
*
* @param array $data
* @return array
* @throws Exception
*/
public static function createUser($data)
{
try {
$dataInsert = [
'USR_UID' => $data['USR_UID'],
'USR_USERNAME' => $data['USR_USERNAME'],
'USR_PASSWORD' => $data['USR_PASSWORD'],
'USR_FIRSTNAME' => $data['USR_FIRSTNAME'],
'USR_LASTNAME' => $data['USR_LASTNAME'],
'USR_EMAIL' => $data['USR_EMAIL'],
'USR_DUE_DATE' => $data['USR_DUE_DATE'],
'USR_CREATE_DATE' => $data['USR_CREATE_DATE'],
'USR_UPDATE_DATE' => $data['USR_UPDATE_DATE'],
'USR_STATUS' => $data['USR_STATUS_ID'],
'USR_AUTH_TYPE' => $data['USR_AUTH_TYPE'],
'UID_AUTH_SOURCE' => $data['UID_AUTH_SOURCE'],
'USR_AUTH_USER_DN' => $data['USR_AUTH_USER_DN'],
'USR_AUTH_SUPERVISOR_DN' => $data['USR_AUTH_SUPERVISOR_DN'],
];
RbacUsers::insert($dataInsert);
RbacUsersRoles::assignRolToUser($data['USR_UID'], $data['ROL_UID']);
} catch (Exception $e) {
throw new Exception("Error: {$e->getMessage()}.");
}
return $data;
}
/**
* Verify if username exists
*
* @param string $username
* @return boolean
*/
public static function verifyUsernameExists($username)
{
$query = RbacUsers::select()->where('USR_USERNAME', $username);
$result = $query->get()->values()->toArray();
if (empty($result)) {
return false;
}
return true;
}
/**
* Verify if user exists
*
* @param string $usrUid
* @return boolean
*/
public static function verifyUserExists($usrUid)
{
$query = RbacUsers::select()->where('USR_UID', $usrUid);
if (empty($query->get()->values()->toArray())) {
return false;
}
return true;
}
} }

View File

@@ -9,4 +9,19 @@ class RbacUsersRoles extends Model
protected $table = 'RBAC_USERS_ROLES'; protected $table = 'RBAC_USERS_ROLES';
public $timestamps = false; public $timestamps = false;
/**
* Assign rol to user
*
* @param string $userUid
* @param string $rolUid
*
* @return void
*/
public static function assignRolToUser($userUid, $rolUid)
{
RbacUsersRoles::insert([
'USR_UID' => $userUid,
'ROL_UID' => $rolUid
]);
}
} }

View File

@@ -31,6 +31,49 @@ class User extends Model
return $this->belongsTo(GroupUser::class, 'USR_UID', 'USR_UID'); return $this->belongsTo(GroupUser::class, 'USR_UID', 'USR_UID');
} }
/**
* Creates a user
*
* @param array $data
*
* @return integer
* @throws Exception
*/
public static function createUser($data)
{
try {
$usrData = [
'USR_UID' => $data['USR_UID'],
'USR_USERNAME' => $data['USR_USERNAME'],
'USR_PASSWORD' => $data['USR_PASSWORD'],
'USR_FIRSTNAME' => $data['USR_FIRSTNAME'],
'USR_LASTNAME' => $data['USR_LASTNAME'],
'USR_EMAIL' => $data['USR_EMAIL'],
'USR_DUE_DATE' => $data['USR_DUE_DATE'],
'USR_CREATE_DATE' => $data['USR_CREATE_DATE'],
'USR_UPDATE_DATE' => $data['USR_UPDATE_DATE'],
'USR_STATUS' => $data['USR_STATUS'],
'USR_STATUS_ID' => $data['USR_STATUS_ID'],
'USR_COUNTRY' => $data['USR_COUNTRY'],
'USR_CITY' => $data['USR_CITY'],
'USR_LOCATION' => $data['USR_LOCATION'],
'USR_ADDRESS' => $data['USR_ADDRESS'],
'USR_PHONE' => $data['USR_PHONE'],
'USR_FAX' => $data['USR_FAX'],
'USR_CELLULAR' => $data['USR_CELLULAR'],
'USR_ZIP_CODE' => $data['USR_ZIP_CODE'],
'DEP_UID' => $data['DEP_UID'],
'USR_POSITION' => $data['USR_POSITION'],
'USR_RESUME' => $data['USR_RESUME'],
'USR_ROLE' => $data['ROL_CODE']
];
$usrId = User::insertGetId($usrData);
return $usrId;
} catch(Exception $e) {
throw new Exception("Error: {$e->getMessage()}.");
}
}
/** /**
* Scope for query to get the user by USR_UID * Scope for query to get the user by USR_UID
* *