Skip to content

Commit dbed831

Browse files
committed
Adding return URL parameter into extension URL generator endpoint.
1 parent 3d022a5 commit dbed831

6 files changed

Lines changed: 34 additions & 21 deletions

File tree

app/V1Module/presenters/ExtensionsPresenter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ public function checkUrl(string $extId, string $instanceId)
6060
* Return URL refering to the extension with properly injected temporary JWT token.
6161
* @GET
6262
* @Param(type="query", name="locale", required=false, validation="string:2")
63+
* @Param(type="query", name="return", required=false, validation="string")
6364
*/
64-
public function actionUrl(string $extId, string $instanceId, ?string $locale)
65+
public function actionUrl(string $extId, string $instanceId, ?string $locale, ?string $return)
6566
{
6667
$user = $this->getCurrentUser();
6768
$extension = $this->extensions->getExtension($extId);
@@ -78,7 +79,7 @@ public function actionUrl(string $extId, string $instanceId, ?string $locale)
7879
$locale = $this->getCurrentUserLocale();
7980
}
8081

81-
$this->sendSuccessResponse($extension->getUrl($token, $locale));
82+
$this->sendSuccessResponse($extension->getUrl($token, $locale, $return ?? ''));
8283
}
8384

8485
public function checkToken(string $extId)

app/V1Module/presenters/NotificationsPresenter.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,14 @@ public function checkCreate()
103103

104104
/**
105105
* Create notification with given attributes
106-
* @Param(type="post", name="groupsIds", validation="array", description="Identification of groups")
107-
* @Param(type="post", name="visibleFrom", validation="timestamp", description="Date from which is notification visible")
108-
* @Param(type="post", name="visibleTo", validation="timestamp", description="Date to which is notification visible")
109-
* @Param(type="post", name="role", validation="string:1..", description="Users with this role and its children can see notification")
106+
* @Param(type="post", name="groupsIds", validation="array",
107+
* description="Identification of groups")
108+
* @Param(type="post", name="visibleFrom", validation="timestamp",
109+
* description="Date from which is notification visible")
110+
* @Param(type="post", name="visibleTo", validation="timestamp",
111+
* description="Date to which is notification visible")
112+
* @Param(type="post", name="role", validation="string:1..",
113+
* description="Users with this role and its children can see notification")
110114
* @Param(type="post", name="type", validation="string", description="Type of the notification (custom)")
111115
* @Param(type="post", name="localizedTexts", validation="array", description="Text of notification")
112116
* @POST
@@ -218,9 +222,12 @@ public function checkUpdate(string $id)
218222
* @POST
219223
* @param string $id
220224
* @Param(type="post", name="groupsIds", validation="array", description="Identification of groups")
221-
* @Param(type="post", name="visibleFrom", validation="timestamp", description="Date from which is notification visible")
222-
* @Param(type="post", name="visibleTo", validation="timestamp", description="Date to which is notification visible")
223-
* @Param(type="post", name="role", validation="string:1..", description="Users with this role and its children can see notification")
225+
* @Param(type="post", name="visibleFrom", validation="timestamp",
226+
* description="Date from which is notification visible")
227+
* @Param(type="post", name="visibleTo", validation="timestamp",
228+
* description="Date to which is notification visible")
229+
* @Param(type="post", name="role", validation="string:1..",
230+
* description="Users with this role and its children can see notification")
224231
* @Param(type="post", name="type", validation="string", description="Type of the notification (custom)")
225232
* @Param(type="post", name="localizedTexts", validation="array", description="Text of notification")
226233
* @throws NotFoundException

app/config/config.local.neon.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ parameters:
8080
caption: # to be displayed in UI; could be also single string (for all localizations)
8181
cs: "Český popisek"
8282
en: "English Caption"
83-
url: "https://extetrnal.domain.com/recodex/extension?token={token}&locale={locale}" # '{token}' and '{locale}' are placeholders
83+
# in URL, '{*}' are placeholders for auth token, locale (en/cs), and return URL
84+
url: "https://extetrnal.domain.com/recodex/extension?token={token}&locale={locale}&return={return}"
8485
urlTokenExpiration: 60 # [s] how long a temporary url token lasts
8586
token: # generated from tmp tokens passed via URL so the ext. tool can access ReCodEx API
8687
expiration: 86400 # [s] how long a full token lasts

app/helpers/Extensions/ExtensionConfig.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ExtensionConfig
3131
* URL template for the external service. The template may hold the following placeholders:
3232
* - {token} - will be replaced with URL-encoded temporary token
3333
* - {locale} - will be replaced with a language identifier ('en', 'cs', ...) based on currently selected language
34+
* - {return} - will be replaced with a return URL (so the user can be returned back from the ext to the same page)
3435
*/
3536
private string $url;
3637

@@ -118,16 +119,18 @@ public function getCaption(): string|array
118119
}
119120

120121
/**
121-
* Get formatted URL. A template is injected a token and current locale.
122+
* Get formatted URL. A template is injected a token, current locale, and return URL.
122123
* @param string $token already serialized JWT
123124
* @param string $locale language identification ('en', 'cs', ...)
125+
* @param string $return URL to which the user should return from the extension
124126
* @return string an instantiated URL template
125127
*/
126-
public function getUrl(string $token, string $locale): string
128+
public function getUrl(string $token, string $locale = '', string $return = ''): string
127129
{
128130
$url = $this->url;
129131
$url = str_replace('{token}', urlencode($token), $url);
130132
$url = str_replace('{locale}', urlencode($locale), $url);
133+
$url = str_replace('{return}', urlencode($return), $url);
131134
return $url;
132135
}
133136

tests/Presenters/ExtensionsPresenter.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,19 @@ class TestExtensionsPresenter extends Tester\TestCase
8686
$currentUser = PresenterTestHelper::getUser($this->container, "submitUser1@example.com");
8787
$instanceId = $currentUser->getInstances()->first()->getId();
8888

89-
$this->injectExtension('test', 'Test', 'https://test.example.com/{token}/{locale}');
89+
$this->injectExtension('test', 'Test', 'https://test.example.com/{token}/{locale}?return={return}');
90+
$returnUrl = 'http://back.com?foo=bar';
9091

9192
$payload = PresenterTestHelper::performPresenterRequest(
9293
$this->presenter,
9394
'V1:Extensions',
9495
'GET',
95-
['action' => 'url', 'extId' => 'test', 'instanceId' => $instanceId, 'locale' => 'de']
96+
['action' => 'url', 'extId' => 'test', 'instanceId' => $instanceId, 'locale' => 'de', 'return' => $returnUrl]
9697
);
9798

9899
Assert::type('string', $payload);
99100
Assert::true(str_starts_with($payload, 'https://test.example.com/'));
100-
Assert::true(str_ends_with($payload, '/de'));
101+
Assert::true(str_ends_with($payload, '/de?return=' . urlencode($returnUrl)));
101102
$tokens = explode('/', $payload);
102103
Assert::count(5, $tokens);
103104
$token = $this->accessManager->decodeToken($tokens[3]);

tests/Presenters/NotificationsPresenter.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ class TestNotificationsPresenter extends Tester\TestCase
7575
PresenterTestHelper::loginDefaultAdmin($this->container);
7676
// Demo group does not have notification,
7777
// so only one global should be returned
78-
$group = current(
79-
$this->presenter->groups->findFiltered(
80-
null,
81-
null,
82-
"Demo group"
83-
)
78+
$groups = $this->presenter->groups->findFiltered(
79+
null,
80+
null,
81+
"Demo group"
8482
);
83+
Assert::count(1, $groups);
84+
$group = current($groups);
8585

8686
$request = new Nette\Application\Request(
8787
"V1:Notifications",

0 commit comments

Comments
 (0)