Merge branch 'module/users' into dev
This commit is contained in:
@@ -1,61 +0,0 @@
|
|||||||
<script>
|
|
||||||
import { onMount } from 'svelte';
|
|
||||||
|
|
||||||
import { api } from '../../urls.svelte.js';
|
|
||||||
import { t } from '../../translations.svelte.js';
|
|
||||||
import { user } from '../../user.svelte.js';
|
|
||||||
|
|
||||||
let connections = $state([]);
|
|
||||||
|
|
||||||
async function loadConnections(){
|
|
||||||
const url = api('user/oidc/connected');
|
|
||||||
const resp = await fetch(url,{credentials:'include'});
|
|
||||||
if (resp.ok){
|
|
||||||
const arr = await resp.json();
|
|
||||||
while (connections.length) connections.pop();
|
|
||||||
for (let entry of arr) connections.push(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(loadConnections);
|
|
||||||
|
|
||||||
async function unlink(connection){
|
|
||||||
const url = api('user/oidc/connected');
|
|
||||||
const resp = await fetch(url,{
|
|
||||||
method : 'DELETE',
|
|
||||||
credentials : 'include',
|
|
||||||
body : JSON.stringify(connection)
|
|
||||||
});
|
|
||||||
if (resp.ok){
|
|
||||||
loadConnections();
|
|
||||||
} else {
|
|
||||||
alert('failed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{#if connections.length>0}
|
|
||||||
<fieldset tabindex="0">
|
|
||||||
<legend>{t('connected_services')}</legend>
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>{t('service')}</th>
|
|
||||||
<th>{t('foreign_id')}</th>
|
|
||||||
<th>{t('actions')}</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{#each connections as connection,i}
|
|
||||||
<tr>
|
|
||||||
<td>{connection.service_id}</td>
|
|
||||||
<td>{connection.foreign_id}</td>
|
|
||||||
<td>
|
|
||||||
<button onclick={() => unlink(connection)}>{t('unlink')}</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{/each}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</fieldset>
|
|
||||||
{/if}
|
|
||||||
@@ -1,17 +1,19 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { useTinyRouter } from 'svelte-tiny-router';
|
import { useTinyRouter } from 'svelte-tiny-router';
|
||||||
|
|
||||||
import { api } from '../../urls.svelte.js';
|
import { api, drop, get } from '../../urls.svelte.js';
|
||||||
import { t } from '../../translations.svelte.js';
|
import { t } from '../../translations.svelte.js';
|
||||||
import { user } from '../../user.svelte.js';
|
import { user } from '../../user.svelte.js';
|
||||||
|
|
||||||
const router = useTinyRouter();
|
const router = useTinyRouter();
|
||||||
|
|
||||||
|
let connections = $state({});
|
||||||
let services = $state([]);
|
let services = $state([]);
|
||||||
|
|
||||||
async function connect(service){
|
async function connect(service){
|
||||||
const url = api(`user/oidc/redirect/${service}`);
|
const url = api(`user/oidc/redirect/${service}`);
|
||||||
const resp = await fetch(url,{credentials:'include'});
|
const resp = await get(url);
|
||||||
if (resp.ok){
|
if (resp.ok){
|
||||||
var json = await resp.json();
|
var json = await resp.json();
|
||||||
if (json.authorization_endpoint) {
|
if (json.authorization_endpoint) {
|
||||||
@@ -22,26 +24,48 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function dropConn(service){
|
||||||
|
const url = api(`user/oidc/${service}`);
|
||||||
|
const resp = await drop(url);
|
||||||
|
if (resp.ok) loadConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load(){
|
||||||
|
await loadButtons();
|
||||||
|
loadConnections();
|
||||||
|
}
|
||||||
|
|
||||||
async function loadButtons(){
|
async function loadButtons(){
|
||||||
const url = api(`user/oidc/buttons`);
|
const url = api(`user/oidc/buttons`);
|
||||||
const resp = await fetch(url,{credentials:'include'});
|
const resp = await get(url);
|
||||||
if (resp.ok){
|
if (resp.ok) services = await resp.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadConnections(){
|
||||||
|
const url = api('user/oidc/connected');
|
||||||
|
const resp = await get(url);
|
||||||
|
if (resp.ok) {
|
||||||
const json = await resp.json();
|
const json = await resp.json();
|
||||||
while (services.length) services.pop();
|
connections = {};
|
||||||
for (let service of json) services.push(service);
|
for (let conn of json) connections[conn.service_id] = conn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function drop(service){
|
async function unlink(connection){
|
||||||
const url = api(`user/oidc/${service}`);
|
const url = api('user/oidc/connected');
|
||||||
const resp = await fetch(url,{
|
const resp = await fetch(url,{
|
||||||
|
method : 'DELETE',
|
||||||
credentials : 'include',
|
credentials : 'include',
|
||||||
method : 'DELETE'
|
body : JSON.stringify(connection)
|
||||||
});
|
});
|
||||||
if (resp.ok) loadButtons();
|
if (resp.ok){
|
||||||
|
loadConnections();
|
||||||
|
} else {
|
||||||
|
alert('failed');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(loadButtons);
|
onMount(load);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<fieldset tabindex="0">
|
<fieldset tabindex="0">
|
||||||
@@ -55,6 +79,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{t('service')}</th>
|
<th>{t('service')}</th>
|
||||||
|
<th>{t('foreign_id')}</th>
|
||||||
<th>{t('actions')}</th>
|
<th>{t('actions')}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -62,13 +87,23 @@
|
|||||||
{#each services as service,i}
|
{#each services as service,i}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{service}</td>
|
<td>{service}</td>
|
||||||
|
{#if connections[service]}
|
||||||
|
<td>
|
||||||
|
{connections[service].foreign_id}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button onclick={() => unlink(connections[service])}>{t('unlink')}</button>
|
||||||
|
</td>
|
||||||
|
{:else}
|
||||||
|
<td></td>
|
||||||
<td>
|
<td>
|
||||||
<button onclick={() => connect(service)}>{t('connect_service')}</button>
|
<button onclick={() => connect(service)}>{t('connect_service')}</button>
|
||||||
{#if user.permissions.includes('MANAGE_LOGIN_SERVICES')}
|
{#if user.permissions.includes('MANAGE_LOGIN_SERVICES')}
|
||||||
<button onclick={() => router.navigate(`/user/oidc/edit/${service}`)}>{t('edit')}</button>
|
<button onclick={() => router.navigate(`/user/oidc/edit/${service}`)}>{t('edit')}</button>
|
||||||
<button onclick={() => drop(service)}>{t('delete')}</button>
|
<button onclick={() => dropConn(service)}>{t('delete')}</button>
|
||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
|
{/if}
|
||||||
</tr>
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
import { user } from '../../user.svelte.js';
|
import { user } from '../../user.svelte.js';
|
||||||
import { t } from '../../translations.svelte.js';
|
import { t } from '../../translations.svelte.js';
|
||||||
|
|
||||||
import Services from './ConnectedServices.svelte';
|
|
||||||
import LoginServiceList from './LoginServices.svelte';
|
import LoginServiceList from './LoginServices.svelte';
|
||||||
import Profile from './Profile.svelte';
|
import Profile from './Profile.svelte';
|
||||||
import UserList from './List.svelte';
|
import UserList from './List.svelte';
|
||||||
@@ -19,7 +18,6 @@
|
|||||||
<h1>{t('user_module')}</h1>
|
<h1>{t('user_module')}</h1>
|
||||||
|
|
||||||
<Profile />
|
<Profile />
|
||||||
<Services />
|
|
||||||
|
|
||||||
{#if user.permissions.includes('LIST_USERS')}
|
{#if user.permissions.includes('LIST_USERS')}
|
||||||
<UserList />
|
<UserList />
|
||||||
|
|||||||
Reference in New Issue
Block a user