Skip to content

Commit b1a7f21

Browse files
committed
Add support for LDAP objects
1 parent 26a257c commit b1a7f21

File tree

10 files changed

+88
-46
lines changed

10 files changed

+88
-46
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@freenit-framework/core",
3-
"version": "0.0.53",
3+
"version": "0.0.54",
44
"private": false,
55
"author": "Goran Mekić <meka@tilda.center>",
66
"license": "BSD-2-Clause",

src/lib/Profile.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
import { onMount } from 'svelte'
3+
import { utils } from '$lib'
34
45
let { store } = $props()
56
@@ -9,10 +10,10 @@
910
</script>
1011

1112
<div class="root">
12-
<div>ID: {store.user.profile.id || store.user.profile.dn}</div>
13+
<div>ID: {utils.id(store.user.profile)}</div>
1314
<div>Email: {store.user.profile.email}</div>
1415
<div>
15-
Active: {store.user.profile.active || store.user.profile.userClass == 'enabled' ? 'yes' : 'no'}
16+
Active: {store.user.profile.active ? 'yes' : 'no'}
1617
</div>
1718
<div>Admin: {store.user.profile.admin ? 'yes' : 'no'}</div>
1819
</div>

src/lib/Role.svelte

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { onMount } from 'svelte'
3-
import { error } from '$lib/notification'
3+
import { notification, utils } from '$lib'
44
import Spinner from './Spinner.svelte'
55
66
let loading = $state(true)
@@ -13,10 +13,10 @@
1313
store.user.fetchAll(),
1414
])
1515
if (!roleResponse.ok) {
16-
error(roleResponse.statusText)
16+
notification.error(roleResponse.statusText)
1717
}
1818
if (!userResponse.ok) {
19-
error(userResponse.statusText)
19+
notification.error(userResponse.statusText)
2020
}
2121
loading = false
2222
})
@@ -38,18 +38,12 @@
3838
const toggleMembership = (user: any) => async (event: any) => {
3939
let response
4040
if (event.target.checked) {
41-
response = await store.role.assign(
42-
store.role.detail.id ?? store.role.detail.dn,
43-
user.id ?? user.dn,
44-
)
41+
response = await store.role.assign(utils.name(store.role.detail), utils.uid(user))
4542
} else {
46-
response = await store.role.deassign(
47-
store.role.detail.id ?? store.role.detail.dn,
48-
user.id ?? user.dn,
49-
)
43+
response = await store.role.deassign(utils.name(store.role.detail), utils.uid(user))
5044
}
5145
if (!response.ok) {
52-
error(response.statusText)
46+
notification.error(response.statusText)
5347
} else {
5448
if (store.role.detail.users) {
5549
store.role.detail.users = [...store.role.detail.users, user]
@@ -62,14 +56,14 @@
6256
const fetchPrevious = async () => {
6357
const response = await store.user.fetchAll(store.user.list.page - 1)
6458
if (!response.ok) {
65-
error(response.statusText)
59+
notification.error(response.statusText)
6660
}
6761
}
6862
6963
const fetchNext = async () => {
7064
const response = await store.user.fetchAll(store.user.list.page + 1)
7165
if (!response.ok) {
72-
error(response.statusText)
66+
notification.error(response.statusText)
7367
}
7468
}
7569
</script>
@@ -87,10 +81,10 @@
8781
<div class="heading">Admin</div>
8882
<div class="heading">Member</div>
8983
{#each store.user.list.data as user}
90-
<div class="data">{user.id || user.dn}</div>
91-
<a class="data" href={`/users/${user.id ?? user.dn}`}>{user.email}</a>
84+
<div class="data">{utils.uid(user)}</div>
85+
<a class="data" href={`/users/${utils.uid(user)}`}>{user.email}</a>
9286
<div class="data">
93-
<input disabled type="checkbox" checked={user.active ?? user.userClass == 'enabled'} />
87+
<input disabled type="checkbox" checked={user.active} />
9488
</div>
9589
<div class="data">
9690
<input disabled type="checkbox" checked={user.admin} />

src/lib/Roles.svelte

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import { onMount } from 'svelte'
33
import Modal from '$lib/Modal.svelte'
4-
import { error } from '$lib/notification'
4+
import { notification, utils } from '$lib'
55
import Input from './Input.svelte'
66
import Spinner from './Spinner.svelte'
77
@@ -14,22 +14,22 @@
1414
loading = true
1515
const response = await store.role.fetchAll()
1616
if (!response.ok) {
17-
error(response.statusText)
17+
notification.nerror(response.statusText)
1818
}
1919
loading = false
2020
})
2121
2222
async function fetchPrevious() {
2323
const response = await store.role.fetchAll(store.role.list.page - 1)
2424
if (!response.ok) {
25-
error(response.statusText)
25+
notification.error(response.statusText)
2626
}
2727
}
2828
2929
async function fetchNext() {
3030
const response = await store.role.fetchAll(store.role.list.page + 1)
3131
if (!response.ok) {
32-
error(response.statusText)
32+
notification.error(response.statusText)
3333
}
3434
}
3535
@@ -42,7 +42,7 @@
4242
event.preventDefault()
4343
const response = await store.role.create({ name })
4444
if (!response.ok) {
45-
error(response.statusText)
45+
notification.error(response.statusText)
4646
}
4747
name = ''
4848
showCreate = false
@@ -63,10 +63,10 @@
6363
<div class="heading">Name</div>
6464
{#each store.role.list.data as role}
6565
<div class="data">
66-
<a href={`/roles/${role.id || role.dn}`}>{role.id || role.dn}</a>
66+
<a href={`/roles/${utils.name(role)}`}>{utils.id(role)}</a>
6767
</div>
6868
<div class="data">
69-
<a href={`/roles/${role.id || role.dn}`}>{role.name || role.cn}</a>
69+
<a href={`/roles/${utils.name(role)}`}>{utils.name(role)}</a>
7070
</div>
7171
<div class="border"></div>
7272
{/each}

src/lib/User.svelte

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { onMount } from 'svelte'
3-
import { error } from '$lib/notification'
3+
import { notification, utils } from '$lib'
44
import Spinner from './Spinner.svelte'
55
66
let { pk = 0, store } = $props()
@@ -13,10 +13,10 @@
1313
store.role.fetchAll(),
1414
])
1515
if (!userResponse.ok) {
16-
error(userResponse.statusText)
16+
notification.error(userResponse.statusText)
1717
}
1818
if (!roleResponse.ok) {
19-
error(roleResponse.statusText)
19+
notification.error(roleResponse.statusText)
2020
}
2121
loading = false
2222
})
@@ -41,21 +41,21 @@
4141
)
4242
}
4343
if (!response.ok) {
44-
error(response.statusText)
44+
notification.error(response.statusText)
4545
}
4646
}
4747
4848
async function fetchPrevious() {
4949
const response = await store.role.fetchAll(store.role.list.page - 1)
5050
if (!response.ok) {
51-
error(response.statusText)
51+
notification.error(response.statusText)
5252
}
5353
}
5454
5555
async function fetchNext() {
5656
const response = await store.role.fetchAll(store.role.list.page + 1)
5757
if (!response.ok) {
58-
error(response.statusText)
58+
notification.error(response.statusText)
5959
}
6060
}
6161
</script>
@@ -72,8 +72,8 @@
7272
<div class="heading">Member</div>
7373

7474
{#each store.role.list.data as role}
75-
<div class="data">{role.id ?? role.dn}</div>
76-
<a class="data" href={`/roles/${role.id ?? role.dn}`}>{role.name ?? role.cn}</a>
75+
<div class="data">{utils.id(role)}</div>
76+
<a class="data" href={`/roles/${utils.name(role)}`}>{utils.name(role)}</a>
7777
<div class="data">
7878
<input type="checkbox" checked={member(role)} onchange={toggleMembership(role)} />
7979
</div>

src/lib/Users.svelte

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { onMount } from 'svelte'
3-
import { error } from '$lib/notification'
3+
import { notification, utils } from '$lib'
44
import Spinner from './Spinner.svelte'
55
66
let loading = $state(true)
@@ -9,22 +9,22 @@
99
onMount(async () => {
1010
const response = await store.user.fetchAll()
1111
if (!response.ok) {
12-
error(response.statusText)
12+
notification.error(response.statusText)
1313
}
1414
loading = false
1515
})
1616
1717
async function fetchPrevious() {
1818
const response = await store.user.fetchAll(store.user.list.page - 1)
1919
if (!response.ok) {
20-
error(response.statusText)
20+
notification.error(response.statusText)
2121
}
2222
}
2323
2424
async function fetchNext() {
2525
const response = await store.user.fetchAll(store.user.list.page + 1)
2626
if (!response.ok) {
27-
error(response.statusText)
27+
notification.error(response.statusText)
2828
}
2929
}
3030
</script>
@@ -40,12 +40,12 @@
4040
<div class="heading">Active</div>
4141
<div class="heading">Admin</div>
4242
{#each store.user.list.data as user}
43-
<div class="data">{user.id || user.dn}</div>
43+
<div class="data">{utils.uid(user)}</div>
4444
<div class="data">
45-
<a href={`/users/${user.id || user.dn}`}>{user.email}</a>
45+
<a href={`/users/${utils.uid(user)}`}>{user.email}</a>
4646
</div>
4747
<div class="data">
48-
<input disabled type="checkbox" checked={user.active || user.userClass == 'enabled'} />
48+
<input disabled type="checkbox" checked={user.active} />
4949
</div>
5050
<div class="data">
5151
<input disabled={!store.user.profile.admin} type="checkbox" checked={user.admin} />

src/lib/base-store/auth.svelte.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { methods } from '..'
1+
import { methods, utils } from '..'
22

33
export default class AuthStore {
44
access = $state(new Date(0))
@@ -38,7 +38,7 @@ export default class AuthStore {
3838
}
3939

4040
loggedin = () => {
41-
return Boolean(this.store.user.profile.id)
41+
return Boolean(utils.id(this.store.user.profile))
4242
}
4343

4444
register = async (email: string, password: string) => {

src/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ export { default as Users } from './Users.svelte'
1818
export { default as methods } from './methods'
1919
export { default as BaseStore } from './base-store'
2020
export * as notification from './notification'
21+
export * as utils from './utils'

src/lib/utils.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
export const dbtype = (data) => {
2+
if (!data) {
3+
return null
4+
}
5+
if (data.id) {
6+
return 'sql'
7+
}
8+
if (data.dn) {
9+
return 'ldap'
10+
}
11+
}
12+
13+
export const id = (data) => {
14+
const dbt = dbtype(data)
15+
if (dbt === 'sql') {
16+
return data.id
17+
}
18+
if (dbt === 'ldap') {
19+
return data.dn
20+
}
21+
}
22+
23+
export const uid = (data) => {
24+
const dbt = dbtype(data)
25+
if (dbt === 'sql') {
26+
return data.id
27+
}
28+
if (dbt === 'ldap') {
29+
if (data.uidNumber) {
30+
return data.uidNumber
31+
}
32+
if (data.gidNumber) {
33+
return data.gidNumber
34+
}
35+
}
36+
}
37+
38+
export const name = (data) => {
39+
const dbt = dbtype(data)
40+
if (dbt === 'sql') {
41+
return data.name
42+
}
43+
if (dbt === 'ldap') {
44+
return data.cn
45+
}
46+
}

0 commit comments

Comments
 (0)