Skip to content

Commit 53db418

Browse files
committed
Cleanup oauth2 admin settings
- Use more vue components - Add link to doc Signed-off-by: Carl Schwan <[email protected]>
1 parent d3f66e2 commit 53db418

File tree

8 files changed

+66
-29
lines changed

8 files changed

+66
-29
lines changed

apps/oauth2/lib/Settings/Admin.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,23 @@
2828

2929
use OCA\OAuth2\Db\ClientMapper;
3030
use OCP\AppFramework\Http\TemplateResponse;
31-
use OCP\IInitialStateService;
31+
use OCP\AppFramework\Services\IInitialState;
3232
use OCP\Settings\ISettings;
33+
use OCP\IURLGenerator;
3334

3435
class Admin implements ISettings {
36+
private IInitialState $initialState;
37+
private ClientMapper $clientMapper;
38+
private IURLGenerator $urlGenerator;
3539

36-
/** @var IInitialStateService */
37-
private $initialStateService;
38-
39-
/** @var ClientMapper */
40-
private $clientMapper;
41-
42-
public function __construct(IInitialStateService $initialStateService,
43-
ClientMapper $clientMapper) {
44-
$this->initialStateService = $initialStateService;
40+
public function __construct(
41+
IInitialState $initialState,
42+
ClientMapper $clientMapper,
43+
IURLGenerator $urlGenerator
44+
) {
45+
$this->initialState = $initialState;
4546
$this->clientMapper = $clientMapper;
47+
$this->urlGenerator = $urlGenerator;
4648
}
4749

4850
public function getForm(): TemplateResponse {
@@ -58,7 +60,8 @@ public function getForm(): TemplateResponse {
5860
'clientSecret' => $client->getSecret(),
5961
];
6062
}
61-
$this->initialStateService->provideInitialState('oauth2', 'clients', $result);
63+
$this->initialState->provideInitialState('clients', $result);
64+
$this->initialState->provideInitialState('oauth2-doc-link', $this->urlGenerator->linkToDocs('admin-oauth2'));
6265

6366
return new TemplateResponse(
6467
'oauth2',

apps/oauth2/src/App.vue

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
-
2121
-->
2222
<template>
23-
<div id="oauth2" class="section">
24-
<h2>{{ t('oauth2', 'OAuth 2.0 clients') }}</h2>
25-
<p class="settings-hint">
26-
{{ t('oauth2', 'OAuth 2.0 allows external services to request access to {instanceName}.', { instanceName: OC.theme.name}) }}
27-
</p>
23+
<SettingsSection :title="t('oauth2', 'OAuth 2.0 clients')"
24+
:description="t('oauth2', 'OAuth 2.0 allows external services to request access to {instanceName}.', { instanceName })"
25+
:doc-url="oauthDocLink">
2826
<table v-if="clients.length > 0" class="grid">
2927
<thead>
3028
<tr>
@@ -56,20 +54,28 @@
5654
type="url"
5755
name="redirectUri"
5856
:placeholder="t('oauth2', 'Redirection URI')">
59-
<input type="submit" class="button" :value="t('oauth2', 'Add')">
57+
<Button class="inline-button">
58+
{{ t('oauth2', 'Add') }}
59+
</Button>
6060
</form>
61-
</div>
61+
</SettingsSection>
6262
</template>
6363

6464
<script>
6565
import axios from '@nextcloud/axios'
6666
import OAuthItem from './components/OAuthItem'
6767
import { generateUrl } from '@nextcloud/router'
68+
import { getCapabilities } from '@nextcloud/capabilities'
69+
import SettingsSection from '@nextcloud/vue/dist/Components/SettingsSection'
70+
import Button from '@nextcloud/vue/dist/Components/Button'
71+
import { loadState } from '@nextcloud/initial-state'
6872
6973
export default {
7074
name: 'App',
7175
components: {
7276
OAuthItem,
77+
SettingsSection,
78+
Button,
7379
},
7480
props: {
7581
clients: {
@@ -85,8 +91,14 @@ export default {
8591
errorMsg: '',
8692
error: false,
8793
},
94+
oauthDocLink: loadState('oauth2', 'oauth2-doc-link'),
8895
}
8996
},
97+
computed: {
98+
instanceName() {
99+
return getCapabilities().theming.name
100+
},
101+
},
90102
methods: {
91103
deleteClient(id) {
92104
axios.delete(generateUrl('apps/oauth2/clients/{id}', { id }))
@@ -122,4 +134,10 @@ export default {
122134
table {
123135
max-width: 800px;
124136
}
137+
138+
/** Overwrite button height and position to be aligned with the text input */
139+
.inline-button {
140+
min-height: 34px !important;
141+
display: inline-flex !important;
142+
}
125143
</style>

apps/oauth2/src/components/OAuthItem.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,29 @@
4242
</table>
4343
</td>
4444
<td class="action-column">
45-
<span><a class="icon-delete has-tooltip" :title="t('oauth2', 'Delete')" @click="$emit('delete', id)" /></span>
45+
<Button type="tertiary-no-background"
46+
:aria-label="t('oauth2', 'Delete')"
47+
@click="$emit('delete', id)">
48+
<template #icon>
49+
<Delete :size="20"
50+
:title="t('oauth2', 'Delete')" />
51+
</template>
52+
</Button>
4653
</td>
4754
</tr>
4855
</template>
4956

5057
<script>
58+
59+
import Delete from 'vue-material-design-icons/Delete'
60+
import Button from '@nextcloud/vue/dist/Components/Button'
61+
5162
export default {
5263
name: 'OAuthItem',
64+
components: {
65+
Delete,
66+
Button,
67+
},
5368
props: {
5469
client: {
5570
type: Object,

apps/oauth2/tests/Settings/AdminTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
use OCA\OAuth2\Db\ClientMapper;
2727
use OCA\OAuth2\Settings\Admin;
2828
use OCP\AppFramework\Http\TemplateResponse;
29-
use OCP\IInitialStateService;
29+
use OCP\AppFramework\Services\IInitialState;
30+
use OCP\IURLGenerator;
3031
use PHPUnit\Framework\MockObject\MockObject;
3132
use Test\TestCase;
3233

@@ -36,18 +37,18 @@ class AdminTest extends TestCase {
3637
private $admin;
3738

3839
/** @var IInitialStateService|MockObject */
39-
private $initialStateService;
40+
private $initialState;
4041

4142
/** @var ClientMapper|MockObject */
4243
private $clientMapper;
4344

4445
protected function setUp(): void {
4546
parent::setUp();
4647

47-
$this->initialStateService = $this->createMock(IInitialStateService::class);
48+
$this->initialState = $this->createMock(IInitialState::class);
4849
$this->clientMapper = $this->createMock(ClientMapper::class);
4950

50-
$this->admin = new Admin($this->initialStateService, $this->clientMapper);
51+
$this->admin = new Admin($this->initialState, $this->clientMapper, $this->createMock(IURLGenerator::class));
5152
}
5253

5354
public function testGetForm() {

dist/core-common.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core-common.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/oauth2-oauth2.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/oauth2-oauth2.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)