HOR-3210
Web Entry 2.0 Rest - Generate Link EP
This commit is contained in:
@@ -34,6 +34,8 @@ class WebEntryEventTest extends \WorkflowTestCase
|
||||
'ID_INVALID_VALUE_CAN_NOT_BE_EMPTY({0})');
|
||||
$this->setTranslation('ID_UNDEFINED_VALUE_IS_REQUIRED',
|
||||
'ID_UNDEFINED_VALUE_IS_REQUIRED({0})');
|
||||
$this->setTranslation('ID_WEB_ENTRY_EVENT_DOES_NOT_EXIST',
|
||||
'ID_WEB_ENTRY_EVENT_DOES_NOT_EXIST({0})');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -579,6 +581,65 @@ class WebEntryEventTest extends \WorkflowTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ProcessMaker\BusinessModel\WebEntryEvent::generateLink
|
||||
* @category HOR-3210:5
|
||||
*/
|
||||
public function testGenerateLinkSingleDefaultAnonymous()
|
||||
{
|
||||
$processUid = $this->processUid;
|
||||
$entryEvents = $this->object->getWebEntryEvents($processUid);
|
||||
$webEntry = $this->getWebEntry($entryEvents[0]);
|
||||
$link = $this->object->generateLink($processUid, $entryEvents[0]['WEE_UID']);
|
||||
$this->assertEquals($this->getSimpleWebEntryUrl($webEntry), $link);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ProcessMaker\BusinessModel\WebEntryEvent::generateLink
|
||||
* @category HOR-3210:5
|
||||
*/
|
||||
public function testGenerateLinkMultipleAnon()
|
||||
{
|
||||
$processUid = $this->processUid2;
|
||||
$entryEvents = $this->object->getWebEntryEvents($processUid);
|
||||
$this->assertCount(1, $entryEvents,
|
||||
'Expected 1 event with web entry in process WebEntry2');
|
||||
$criteria = new \Criteria();
|
||||
$criteria->add(\BpmnEventPeer::PRJ_UID, $processUid);
|
||||
$criteria->add(\BpmnEventPeer::EVN_NAME, 'simple start');
|
||||
$event = \BpmnEventPeer::doSelectOne($criteria);
|
||||
$data = [
|
||||
'EVN_UID' => $event->getEvnUid(),
|
||||
'ACT_UID' => $entryEvents[0]['ACT_UID'],
|
||||
'WE_AUTHENTICATION' => 'ANONYMOUS',
|
||||
'USR_UID' => $this->adminUid,
|
||||
'WE_TYPE' => 'MULTIPLE',
|
||||
'WEE_TITLE' => $event->getEvnUid(),
|
||||
];
|
||||
$this->object->create($processUid, $this->adminUid, $data);
|
||||
$entryEvents2 = $this->object->getWebEntryEvents($processUid);
|
||||
foreach ($entryEvents2 as $entryEvent) {
|
||||
if ($entryEvent['EVN_UID'] === $event->getEvnUid()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$webEntry = $this->getWebEntry($entryEvent);
|
||||
$link = $this->object->generateLink($processUid, $entryEvent['WEE_UID']);
|
||||
$this->assertEquals($this->getSimpleWebEntryUrl($webEntry), $link);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ProcessMaker\BusinessModel\WebEntryEvent::generateLink
|
||||
* @category HOR-3210:5
|
||||
*/
|
||||
public function testGenerateLinkForMissingWE()
|
||||
{
|
||||
$processUid = $this->processUid;
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('ID_WEB_ENTRY_EVENT_DOES_NOT_EXIST(WEE_UID)');
|
||||
$link = $this->object->generateLink($processUid, 'INVALID-UID');
|
||||
}
|
||||
|
||||
/**
|
||||
* get a dynaform
|
||||
* @return type
|
||||
|
||||
@@ -1073,4 +1073,42 @@ class WebEntryEvent
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Web Entry 2.0 Rest - Generate Link EP
|
||||
*
|
||||
* @category PROD-181,HOR-3210
|
||||
* @link https://processmaker.atlassian.net/browse/PROD-181 Web Entry 2 Feature definition
|
||||
* @link https://processmaker.atlassian.net/browse/HOR-3210 Generate link specification
|
||||
* @group webentry2
|
||||
*/
|
||||
public function generateLink($prj_uid, $wee_uid)
|
||||
{
|
||||
$webEntryEvent = \WebEntryEventPeer::retrieveByPK($wee_uid);
|
||||
if (empty($webEntryEvent)) {
|
||||
throw new \Exception(
|
||||
\G::LoadTranslation("ID_WEB_ENTRY_EVENT_DOES_NOT_EXIST", array("WEE_UID", $wee_uid))
|
||||
);
|
||||
}
|
||||
$webEntry = \WebEntryPeer::retrieveByPK($webEntryEvent->getWeeWeUid());
|
||||
if (empty($webEntryEvent)) {
|
||||
throw new \Exception(
|
||||
\G::LoadTranslation(
|
||||
"ID_WEB_ENTRY_EVENT_DOES_NOT_EXIST",
|
||||
array("WE_UID", $webEntryEvent->getWeeWeUid())
|
||||
)
|
||||
);
|
||||
}
|
||||
if ($webEntry->getWeLinkGeneration() === 'ADVANCED') {
|
||||
$domain = $webEntry->getWeLinkDomain();
|
||||
$url = $domain . "/sys".SYS_SYS."/".
|
||||
$webEntry->getWeLinkLanguage()."/".
|
||||
$webEntry->getWeLinkSkin()."/".$prj_uid;
|
||||
return $url."/".$webEntry->getWeUid().'.php';
|
||||
} else {
|
||||
$http = (\G::is_https()) ? "https://" : "http://";
|
||||
$url = $http.$_SERVER["HTTP_HOST"]."/sys".SYS_SYS."/".SYS_LANG."/".SYS_SKIN."/".$prj_uid;
|
||||
return $url."/".$webEntry->getWeData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ use \Luracast\Restler\RestException;
|
||||
*/
|
||||
class WebEntryEvent extends Api
|
||||
{
|
||||
/**
|
||||
* @var \ProcessMaker\BusinessModel\WebEntryEvent $webEntryEvent
|
||||
*/
|
||||
private $webEntryEvent;
|
||||
|
||||
/**
|
||||
@@ -140,5 +143,19 @@ class WebEntryEvent extends Api
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @url GET /:prj_uid/web-entry-event/:wee_uid/generate-link
|
||||
* @class AccessControl {@permission PM_FACTORY}
|
||||
*
|
||||
*/
|
||||
public function generateLink($prj_uid, $wee_uid)
|
||||
{
|
||||
try {
|
||||
$this->webEntryEvent->generateLink($prj_uid, $wee_uid);
|
||||
} catch (\Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user