PMCORE-3050 Rest Services - CRUD My task column settings
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\src\ProcessMaker\Model;
|
||||
|
||||
use G;
|
||||
use ProcessMaker\Model\UserConfig;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UserConfigTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Setup method,
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Teardown method.
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* It test the method getSetting.
|
||||
* @test
|
||||
* @covers \ProcessMaker\Model\UserConfig::getSetting()
|
||||
*/
|
||||
public function it_should_test_getSetting()
|
||||
{
|
||||
$id = 1;
|
||||
$name = "test";
|
||||
$setting = json_encode(["test" => 1]);
|
||||
$result = UserConfig::addSetting($id, $name, $setting);
|
||||
|
||||
//assert get
|
||||
$result = UserConfig::getSetting($id, $name);
|
||||
$this->assertArrayHasKey("id", $result);
|
||||
$this->assertArrayHasKey("name", $result);
|
||||
$this->assertArrayHasKey("setting", $result);
|
||||
$this->assertEquals($result["id"], $id);
|
||||
$this->assertEquals($result["name"], $name);
|
||||
$this->assertEquals($result["setting"], json_decode($setting));
|
||||
}
|
||||
|
||||
/**
|
||||
* It test the method addSetting.
|
||||
* @test
|
||||
* @covers \ProcessMaker\Model\UserConfig::addSetting()
|
||||
*/
|
||||
public function it_should_test_addSetting()
|
||||
{
|
||||
$id = 1;
|
||||
$name = "test";
|
||||
$setting = json_encode(["test" => 1]);
|
||||
|
||||
$result = UserConfig::addSetting($id, $name, $setting);
|
||||
$this->assertArrayHasKey("id", $result);
|
||||
$this->assertArrayHasKey("name", $result);
|
||||
$this->assertArrayHasKey("setting", $result);
|
||||
$this->assertEquals($result["id"], $id);
|
||||
$this->assertEquals($result["name"], $name);
|
||||
$this->assertEquals($result["setting"], json_decode($setting));
|
||||
}
|
||||
|
||||
/**
|
||||
* It test the method editSetting.
|
||||
* @test
|
||||
* @covers \ProcessMaker\Model\UserConfig::editSetting()
|
||||
*/
|
||||
public function it_should_test_editSetting()
|
||||
{
|
||||
$id = 1;
|
||||
$name = "test";
|
||||
$setting = json_encode(["test" => 1]);
|
||||
$result = UserConfig::addSetting($id, $name, $setting);
|
||||
|
||||
//assert edit
|
||||
$setting = json_encode(["test" => 2, "test2" => 3]);
|
||||
$result = UserConfig::editSetting($id, $name, $setting);
|
||||
$this->assertArrayHasKey("id", $result);
|
||||
$this->assertArrayHasKey("name", $result);
|
||||
$this->assertArrayHasKey("setting", $result);
|
||||
$this->assertEquals($result["id"], $id);
|
||||
$this->assertEquals($result["name"], $name);
|
||||
$this->assertEquals($result["setting"], json_decode($setting));
|
||||
}
|
||||
|
||||
/**
|
||||
* It test the method deleteSetting.
|
||||
* @test
|
||||
* @covers \ProcessMaker\Model\UserConfig::deleteSetting()
|
||||
*/
|
||||
public function it_should_test_deleteSetting()
|
||||
{
|
||||
$id = 2;
|
||||
$name = "test2";
|
||||
$setting = json_encode(["test2" => 1]);
|
||||
$result = UserConfig::addSetting($id, $name, $setting);
|
||||
|
||||
//assert delete
|
||||
$result = UserConfig::deleteSetting($id, $name);
|
||||
$this->assertArrayHasKey("id", $result);
|
||||
$this->assertArrayHasKey("name", $result);
|
||||
$this->assertArrayHasKey("setting", $result);
|
||||
$this->assertEquals($result["id"], $id);
|
||||
$this->assertEquals($result["name"], $name);
|
||||
}
|
||||
}
|
||||
19
workflow/engine/classes/model/UserConfig.php
Normal file
19
workflow/engine/classes/model/UserConfig.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
require_once 'classes/model/om/BaseUserConfig.php';
|
||||
|
||||
|
||||
/**
|
||||
* Skeleton subclass for representing a row from the 'USER_CONFIG' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
* @package classes.model
|
||||
*/
|
||||
class UserConfig extends BaseUserConfig {
|
||||
|
||||
} // UserConfig
|
||||
23
workflow/engine/classes/model/UserConfigPeer.php
Normal file
23
workflow/engine/classes/model/UserConfigPeer.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
// include base peer class
|
||||
require_once 'classes/model/om/BaseUserConfigPeer.php';
|
||||
|
||||
// include object class
|
||||
include_once 'classes/model/UserConfig.php';
|
||||
|
||||
|
||||
/**
|
||||
* Skeleton subclass for performing query and update operations on the 'USER_CONFIG' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
* @package classes.model
|
||||
*/
|
||||
class UserConfigPeer extends BaseUserConfigPeer {
|
||||
|
||||
} // UserConfigPeer
|
||||
76
workflow/engine/classes/model/map/UserConfigMapBuilder.php
Normal file
76
workflow/engine/classes/model/map/UserConfigMapBuilder.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
require_once 'propel/map/MapBuilder.php';
|
||||
include_once 'creole/CreoleTypes.php';
|
||||
|
||||
|
||||
/**
|
||||
* This class adds structure of 'USER_CONFIG' table to 'workflow' DatabaseMap object.
|
||||
*
|
||||
*
|
||||
*
|
||||
* These statically-built map classes are used by Propel to do runtime db structure discovery.
|
||||
* For example, the createSelectSql() method checks the type of a given column used in an
|
||||
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
|
||||
* (i.e. if it's a text column type).
|
||||
*
|
||||
* @package workflow.classes.model.map
|
||||
*/
|
||||
class UserConfigMapBuilder
|
||||
{
|
||||
|
||||
/**
|
||||
* The (dot-path) name of this class
|
||||
*/
|
||||
const CLASS_NAME = 'classes.model.map.UserConfigMapBuilder';
|
||||
|
||||
/**
|
||||
* The database map.
|
||||
*/
|
||||
private $dbMap;
|
||||
|
||||
/**
|
||||
* Tells us if this DatabaseMapBuilder is built so that we
|
||||
* don't have to re-build it every time.
|
||||
*
|
||||
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
|
||||
*/
|
||||
public function isBuilt()
|
||||
{
|
||||
return ($this->dbMap !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the databasemap this map builder built.
|
||||
*
|
||||
* @return the databasemap
|
||||
*/
|
||||
public function getDatabaseMap()
|
||||
{
|
||||
return $this->dbMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* The doBuild() method builds the DatabaseMap
|
||||
*
|
||||
* @return void
|
||||
* @throws PropelException
|
||||
*/
|
||||
public function doBuild()
|
||||
{
|
||||
$this->dbMap = Propel::getDatabaseMap('workflow');
|
||||
|
||||
$tMap = $this->dbMap->addTable('USER_CONFIG');
|
||||
$tMap->setPhpName('UserConfig');
|
||||
|
||||
$tMap->setUseIdGenerator(false);
|
||||
|
||||
$tMap->addPrimaryKey('USR_ID', 'UsrId', 'string', CreoleTypes::BIGINT, true, 20);
|
||||
|
||||
$tMap->addPrimaryKey('USC_NAME', 'UscName', 'string', CreoleTypes::VARCHAR, true, 255);
|
||||
|
||||
$tMap->addColumn('USC_SETTING', 'UscSetting', 'string', CreoleTypes::LONGVARCHAR, true, null);
|
||||
|
||||
} // doBuild()
|
||||
|
||||
} // UserConfigMapBuilder
|
||||
638
workflow/engine/classes/model/om/BaseUserConfig.php
Normal file
638
workflow/engine/classes/model/om/BaseUserConfig.php
Normal file
File diff suppressed because it is too large
Load Diff
567
workflow/engine/classes/model/om/BaseUserConfigPeer.php
Normal file
567
workflow/engine/classes/model/om/BaseUserConfigPeer.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -6102,4 +6102,13 @@
|
||||
<column name="UEA_OWNER" type="BIGINT" size="20" required="false"/>
|
||||
<column name="UEA_DATE_CREATE" type="TIMESTAMP" required="false"/>
|
||||
</table>
|
||||
<table name="USER_CONFIG" idMethod="native">
|
||||
<vendor type="mysql">
|
||||
<parameter name="Engine" value="InnoDB"/>
|
||||
<parameter name="Collation" value="utf8"/>
|
||||
</vendor>
|
||||
<column name="USR_ID" type="BIGINT" size="20" required="true" primaryKey="true"/>
|
||||
<column name="USC_NAME" type="VARCHAR" size="255" required="true" primaryKey="true"/>
|
||||
<column name="USC_SETTING" type="LONGVARCHAR" required="true"/>
|
||||
</table>
|
||||
</database>
|
||||
|
||||
@@ -3388,5 +3388,19 @@ CREATE TABLE `USER_EXTENDED_ATTRIBUTES`
|
||||
`UEA_DATE_CREATE` DATETIME,
|
||||
PRIMARY KEY (`UEA_ID`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET='utf8';
|
||||
#-----------------------------------------------------------------------------
|
||||
#-- USER_CONFIG
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
DROP TABLE IF EXISTS `USER_CONFIG`;
|
||||
|
||||
|
||||
CREATE TABLE `USER_CONFIG`
|
||||
(
|
||||
`USR_ID` BIGINT(20) NOT NULL,
|
||||
`USC_NAME` VARCHAR(255) NOT NULL,
|
||||
`USC_SETTING` MEDIUMTEXT NOT NULL,
|
||||
PRIMARY KEY (`USR_ID`,`USC_NAME`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET='utf8';
|
||||
# This restores the fkey checks, after having unset them earlier
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
96
workflow/engine/src/ProcessMaker/Model/UserConfig.php
Normal file
96
workflow/engine/src/ProcessMaker/Model/UserConfig.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use stdClass;
|
||||
|
||||
class UserConfig extends Model
|
||||
{
|
||||
/**
|
||||
* Bind table.
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'USER_CONFIG';
|
||||
|
||||
/**
|
||||
* Column timestamps.
|
||||
* @var boolean
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* Get user setting.
|
||||
* @param int $id
|
||||
* @param string $name
|
||||
* @return mix array|null
|
||||
*/
|
||||
public static function getSetting(int $id, string $name)
|
||||
{
|
||||
$userConfig = UserConfig::where('USR_ID', '=', $id)
|
||||
->where('USC_NAME', '=', $name)
|
||||
->get()
|
||||
->first();
|
||||
if (empty($userConfig)) {
|
||||
return null;
|
||||
}
|
||||
return [
|
||||
"id" => $userConfig->USR_ID,
|
||||
"name" => $userConfig->USC_NAME,
|
||||
"setting" => json_decode($userConfig->USC_SETTING)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add user setting.
|
||||
* @param int $id
|
||||
* @param string $name
|
||||
* @param string $setting
|
||||
* @return mix array|null
|
||||
*/
|
||||
public static function addSetting(int $id, string $name, string $setting)
|
||||
{
|
||||
$userConfig = UserConfig::getSetting($id, $name);
|
||||
if (empty($userConfig)) {
|
||||
$model = new UserConfig();
|
||||
$model->USR_ID = $id;
|
||||
$model->USC_NAME = $name;
|
||||
$model->USC_SETTING = $setting;
|
||||
$model->save();
|
||||
|
||||
$userConfig = UserConfig::getSetting($id, $name);
|
||||
}
|
||||
return $userConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit user setting.
|
||||
* @param int $id
|
||||
* @param string $name
|
||||
* @param string $setting
|
||||
* @return mix array|null
|
||||
*/
|
||||
public static function editSetting(int $id, string $name, string $setting)
|
||||
{
|
||||
UserConfig::where('USR_ID', '=', $id)
|
||||
->where('USC_NAME', '=', $name)
|
||||
->update(["USC_SETTING" => $setting]);
|
||||
|
||||
return UserConfig::getSetting($id, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user setting.
|
||||
* @param int $id
|
||||
* @param string $name
|
||||
* @return mix array|null
|
||||
*/
|
||||
public static function deleteSetting(int $id, string $name)
|
||||
{
|
||||
$userConfig = UserConfig::getSetting($id, $name);
|
||||
UserConfig::where('USR_ID', '=', $id)
|
||||
->where('USC_NAME', '=', $name)
|
||||
->delete();
|
||||
return $userConfig;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ use ProcessMaker\BusinessModel\Cases\Unassigned;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\Process;
|
||||
use ProcessMaker\Model\User;
|
||||
use ProcessMaker\Model\UserConfig;
|
||||
use ProcessMaker\Model\Task;
|
||||
use ProcessMaker\Services\Api;
|
||||
use ProcessMaker\Util\DateTime;
|
||||
@@ -732,4 +733,66 @@ class Home extends Api
|
||||
throw new RestException(404, "Process with Uid '{$processUid}'.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user setting.
|
||||
* @params int $id
|
||||
* @params string $name
|
||||
* @url GET /config
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @access protected
|
||||
* @class AccessControl {@permission PM_CASES}
|
||||
*/
|
||||
public function doGetConfig(int $id, string $name)
|
||||
{
|
||||
return UserConfig::getSetting($id, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add user setting.
|
||||
* @params int $id
|
||||
* @params string $name
|
||||
* @params string $setting
|
||||
* @url POST /config
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @access protected
|
||||
* @class AccessControl {@permission PM_CASES}
|
||||
*/
|
||||
public function doPostConfig(int $id, string $name, string $setting)
|
||||
{
|
||||
return UserConfig::addSetting($id, $name, $setting);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user setting.
|
||||
* @params int $id
|
||||
* @params string $name
|
||||
* @params string $setting
|
||||
* @url PUT /config
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @access protected
|
||||
* @class AccessControl {@permission PM_CASES}
|
||||
*/
|
||||
public function doPutConfig(int $id, string $name, string $setting)
|
||||
{
|
||||
return UserConfig::editSetting($id, $name, $setting);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user setting.
|
||||
* @params int $id
|
||||
* @params string $name
|
||||
* @url DELETE /config
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @access protected
|
||||
* @class AccessControl {@permission PM_CASES}
|
||||
*/
|
||||
public function doDeleteConfig(int $id, string $name)
|
||||
{
|
||||
return UserConfig::deleteSetting($id, $name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user