mirror of
https://github.com/nikdoof/pocket-id.git
synced 2025-12-14 15:22:18 +00:00
feat: allow LDAP users and groups to be deleted if LDAP gets disabled
This commit is contained in:
@@ -42,7 +42,7 @@ func initRouter(db *gorm.DB, appConfigService *service.AppConfigService) {
|
|||||||
customClaimService := service.NewCustomClaimService(db)
|
customClaimService := service.NewCustomClaimService(db)
|
||||||
oidcService := service.NewOidcService(db, jwtService, appConfigService, auditLogService, customClaimService)
|
oidcService := service.NewOidcService(db, jwtService, appConfigService, auditLogService, customClaimService)
|
||||||
testService := service.NewTestService(db, appConfigService)
|
testService := service.NewTestService(db, appConfigService)
|
||||||
userGroupService := service.NewUserGroupService(db)
|
userGroupService := service.NewUserGroupService(db, appConfigService)
|
||||||
ldapService := service.NewLdapService(db, appConfigService, userService, userGroupService)
|
ldapService := service.NewLdapService(db, appConfigService, userService, userGroupService)
|
||||||
|
|
||||||
rateLimitMiddleware := middleware.NewRateLimitMiddleware()
|
rateLimitMiddleware := middleware.NewRateLimitMiddleware()
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ var defaultDbConfig = model.AppConfig{
|
|||||||
LdapEnabled: model.AppConfigVariable{
|
LdapEnabled: model.AppConfigVariable{
|
||||||
Key: "ldapEnabled",
|
Key: "ldapEnabled",
|
||||||
Type: "bool",
|
Type: "bool",
|
||||||
|
IsPublic: true,
|
||||||
DefaultValue: "false",
|
DefaultValue: "false",
|
||||||
},
|
},
|
||||||
LdapUrl: model.AppConfigVariable{
|
LdapUrl: model.AppConfigVariable{
|
||||||
|
|||||||
@@ -11,10 +11,11 @@ import (
|
|||||||
|
|
||||||
type UserGroupService struct {
|
type UserGroupService struct {
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
|
appConfigService *AppConfigService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUserGroupService(db *gorm.DB) *UserGroupService {
|
func NewUserGroupService(db *gorm.DB, appConfigService *AppConfigService) *UserGroupService {
|
||||||
return &UserGroupService{db: db}
|
return &UserGroupService{db: db, appConfigService: appConfigService}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserGroupService) List(name string, sortedPaginationRequest utils.SortedPaginationRequest) (groups []model.UserGroup, response utils.PaginationResponse, err error) {
|
func (s *UserGroupService) List(name string, sortedPaginationRequest utils.SortedPaginationRequest) (groups []model.UserGroup, response utils.PaginationResponse, err error) {
|
||||||
@@ -51,7 +52,8 @@ func (s *UserGroupService) Delete(id string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if group.LdapID != nil {
|
// Disallow deleting the group if it is an LDAP group and LDAP is enabled
|
||||||
|
if group.LdapID != nil && s.appConfigService.DbConfig.LdapEnabled.Value == "true" {
|
||||||
return &common.LdapUserGroupUpdateError{}
|
return &common.LdapUserGroupUpdateError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +85,8 @@ func (s *UserGroupService) Update(id string, input dto.UserGroupCreateDto, allow
|
|||||||
return model.UserGroup{}, err
|
return model.UserGroup{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if group.LdapID != nil && !allowLdapUpdate {
|
// Disallow updating the group if it is an LDAP group and LDAP is enabled
|
||||||
|
if !allowLdapUpdate && group.LdapID != nil && s.appConfigService.DbConfig.LdapEnabled.Value == "true" {
|
||||||
return model.UserGroup{}, &common.LdapUserGroupUpdateError{}
|
return model.UserGroup{}, &common.LdapUserGroupUpdateError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,11 @@ type UserService struct {
|
|||||||
jwtService *JwtService
|
jwtService *JwtService
|
||||||
auditLogService *AuditLogService
|
auditLogService *AuditLogService
|
||||||
emailService *EmailService
|
emailService *EmailService
|
||||||
|
appConfigService *AppConfigService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUserService(db *gorm.DB, jwtService *JwtService, auditLogService *AuditLogService, emailService *EmailService) *UserService {
|
func NewUserService(db *gorm.DB, jwtService *JwtService, auditLogService *AuditLogService, emailService *EmailService, appConfigService *AppConfigService) *UserService {
|
||||||
return &UserService{db: db, jwtService: jwtService, auditLogService: auditLogService, emailService: emailService}
|
return &UserService{db: db, jwtService: jwtService, auditLogService: auditLogService, emailService: emailService, appConfigService: appConfigService}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserService) ListUsers(searchTerm string, sortedPaginationRequest utils.SortedPaginationRequest) ([]model.User, utils.PaginationResponse, error) {
|
func (s *UserService) ListUsers(searchTerm string, sortedPaginationRequest utils.SortedPaginationRequest) ([]model.User, utils.PaginationResponse, error) {
|
||||||
@@ -52,7 +53,8 @@ func (s *UserService) DeleteUser(userID string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.LdapID != nil {
|
// Disallow deleting the user if it is an LDAP user and LDAP is enabled
|
||||||
|
if user.LdapID != nil && s.appConfigService.DbConfig.LdapEnabled.Value == "true" {
|
||||||
return &common.LdapUserUpdateError{}
|
return &common.LdapUserUpdateError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +88,8 @@ func (s *UserService) UpdateUser(userID string, updatedUser dto.UserCreateDto, u
|
|||||||
return model.User{}, err
|
return model.User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.LdapID != nil && !allowLdapUpdate {
|
// Disallow updating the user if it is an LDAP group and LDAP is enabled
|
||||||
|
if !allowLdapUpdate && user.LdapID != nil && s.appConfigService.DbConfig.LdapEnabled.Value == "true" {
|
||||||
return model.User{}, &common.LdapUserUpdateError{}
|
return model.User{}, &common.LdapUserUpdateError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export type AppConfig = {
|
|||||||
appName: string;
|
appName: string;
|
||||||
allowOwnAccountEdit: boolean;
|
allowOwnAccountEdit: boolean;
|
||||||
emailOneTimeAccessEnabled: boolean;
|
emailOneTimeAccessEnabled: boolean;
|
||||||
|
ldapEnabled: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AllAppConfig = AppConfig & {
|
export type AllAppConfig = AppConfig & {
|
||||||
@@ -18,7 +19,6 @@ export type AllAppConfig = AppConfig & {
|
|||||||
smtpSkipCertVerify: boolean;
|
smtpSkipCertVerify: boolean;
|
||||||
emailLoginNotificationEnabled: boolean;
|
emailLoginNotificationEnabled: boolean;
|
||||||
// LDAP
|
// LDAP
|
||||||
ldapEnabled: boolean;
|
|
||||||
ldapUrl: string;
|
ldapUrl: string;
|
||||||
ldapBindDn: string;
|
ldapBindDn: string;
|
||||||
ldapBindPassword: string;
|
ldapBindPassword: string;
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
</Alert.Root>
|
</Alert.Root>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<fieldset disabled={!$appConfigStore.allowOwnAccountEdit || !!account.ldapId}>
|
<fieldset disabled={!$appConfigStore.allowOwnAccountEdit || (!!account.ldapId && $appConfigStore.ldapEnabled)}>
|
||||||
<Card.Root>
|
<Card.Root>
|
||||||
<Card.Header>
|
<Card.Header>
|
||||||
<Card.Title>Account Details</Card.Title>
|
<Card.Title>Account Details</Card.Title>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
import UserGroupForm from '../user-group-form.svelte';
|
import UserGroupForm from '../user-group-form.svelte';
|
||||||
import UserSelection from '../user-selection.svelte';
|
import UserSelection from '../user-selection.svelte';
|
||||||
|
import appConfigStore from '$lib/stores/application-configuration-store';
|
||||||
|
|
||||||
let { data } = $props();
|
let { data } = $props();
|
||||||
let userGroup = $state({
|
let userGroup = $state({
|
||||||
@@ -88,11 +89,11 @@
|
|||||||
<UserSelection
|
<UserSelection
|
||||||
{users}
|
{users}
|
||||||
bind:selectedUserIds={userGroup.userIds}
|
bind:selectedUserIds={userGroup.userIds}
|
||||||
selectionDisabled={!!userGroup.ldapId}
|
selectionDisabled={!!userGroup.ldapId && $appConfigStore.ldapEnabled}
|
||||||
/>
|
/>
|
||||||
{/await}
|
{/await}
|
||||||
<div class="mt-5 flex justify-end">
|
<div class="mt-5 flex justify-end">
|
||||||
<Button disabled={!!userGroup.ldapId} on:click={() => updateUserGroupUsers(userGroup.userIds)}
|
<Button disabled={!!userGroup.ldapId && $appConfigStore.ldapEnabled} on:click={() => updateUserGroupUsers(userGroup.userIds)}
|
||||||
>Save</Button
|
>Save</Button
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import FormInput from '$lib/components/form-input.svelte';
|
import FormInput from '$lib/components/form-input.svelte';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
|
import appConfigStore from '$lib/stores/application-configuration-store';
|
||||||
import type { UserGroupCreate } from '$lib/types/user-group.type';
|
import type { UserGroupCreate } from '$lib/types/user-group.type';
|
||||||
import { createForm } from '$lib/utils/form-util';
|
import { createForm } from '$lib/utils/form-util';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
@@ -14,7 +15,7 @@
|
|||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
let isLoading = $state(false);
|
let isLoading = $state(false);
|
||||||
let inputDisabled = $derived(!!existingUserGroup?.ldapId);
|
let inputDisabled = $derived(!!existingUserGroup?.ldapId && $appConfigStore.ldapEnabled);
|
||||||
let hasManualNameEdit = $state(!!existingUserGroup?.friendlyName);
|
let hasManualNameEdit = $state(!!existingUserGroup?.friendlyName);
|
||||||
|
|
||||||
const userGroup = {
|
const userGroup = {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import * as DropdownMenu from '$lib/components/ui/dropdown-menu';
|
import * as DropdownMenu from '$lib/components/ui/dropdown-menu';
|
||||||
import * as Table from '$lib/components/ui/table';
|
import * as Table from '$lib/components/ui/table';
|
||||||
import UserGroupService from '$lib/services/user-group-service';
|
import UserGroupService from '$lib/services/user-group-service';
|
||||||
|
import appConfigStore from '$lib/stores/application-configuration-store';
|
||||||
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';
|
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';
|
||||||
import type { UserGroup, UserGroupWithUserCount } from '$lib/types/user-group.type';
|
import type { UserGroup, UserGroupWithUserCount } from '$lib/types/user-group.type';
|
||||||
import { axiosErrorToast } from '$lib/utils/error-util';
|
import { axiosErrorToast } from '$lib/utils/error-util';
|
||||||
@@ -68,7 +69,7 @@
|
|||||||
<DropdownMenu.Item href="/settings/admin/user-groups/{item.id}"
|
<DropdownMenu.Item href="/settings/admin/user-groups/{item.id}"
|
||||||
><LucidePencil class="mr-2 h-4 w-4" /> Edit</DropdownMenu.Item
|
><LucidePencil class="mr-2 h-4 w-4" /> Edit</DropdownMenu.Item
|
||||||
>
|
>
|
||||||
{#if !item.ldapId}
|
{#if !item.ldapId || !$appConfigStore.ldapEnabled}
|
||||||
<DropdownMenu.Item
|
<DropdownMenu.Item
|
||||||
class="text-red-500 focus:!text-red-700"
|
class="text-red-500 focus:!text-red-700"
|
||||||
on:click={() => deleteUserGroup(item)}
|
on:click={() => deleteUserGroup(item)}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import CheckboxWithLabel from '$lib/components/checkbox-with-label.svelte';
|
import CheckboxWithLabel from '$lib/components/checkbox-with-label.svelte';
|
||||||
import FormInput from '$lib/components/form-input.svelte';
|
import FormInput from '$lib/components/form-input.svelte';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
|
import appConfigStore from '$lib/stores/application-configuration-store';
|
||||||
import type { User, UserCreate } from '$lib/types/user.type';
|
import type { User, UserCreate } from '$lib/types/user.type';
|
||||||
import { createForm } from '$lib/utils/form-util';
|
import { createForm } from '$lib/utils/form-util';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
@@ -15,7 +16,7 @@
|
|||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
let isLoading = $state(false);
|
let isLoading = $state(false);
|
||||||
let inputDisabled = $derived(!!existingUser?.ldapId);
|
let inputDisabled = $derived(!!existingUser?.ldapId && $appConfigStore.ldapEnabled);
|
||||||
|
|
||||||
const user = {
|
const user = {
|
||||||
firstName: existingUser?.firstName || '',
|
firstName: existingUser?.firstName || '',
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
import Ellipsis from 'lucide-svelte/icons/ellipsis';
|
import Ellipsis from 'lucide-svelte/icons/ellipsis';
|
||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
import OneTimeLinkModal from './one-time-link-modal.svelte';
|
import OneTimeLinkModal from './one-time-link-modal.svelte';
|
||||||
|
import appConfigStore from '$lib/stores/application-configuration-store';
|
||||||
|
|
||||||
let { users = $bindable() }: { users: Paginated<User> } = $props();
|
let { users = $bindable() }: { users: Paginated<User> } = $props();
|
||||||
let requestOptions: SearchPaginationSortRequest | undefined = $state();
|
let requestOptions: SearchPaginationSortRequest | undefined = $state();
|
||||||
@@ -95,7 +96,7 @@
|
|||||||
<DropdownMenu.Item onclick={() => goto(`/settings/admin/users/${item.id}`)}
|
<DropdownMenu.Item onclick={() => goto(`/settings/admin/users/${item.id}`)}
|
||||||
><LucidePencil class="mr-2 h-4 w-4" /> Edit</DropdownMenu.Item
|
><LucidePencil class="mr-2 h-4 w-4" /> Edit</DropdownMenu.Item
|
||||||
>
|
>
|
||||||
{#if !item.ldapId}
|
{#if !item.ldapId || !$appConfigStore.ldapEnabled}
|
||||||
<DropdownMenu.Item
|
<DropdownMenu.Item
|
||||||
class="text-red-500 focus:!text-red-700"
|
class="text-red-500 focus:!text-red-700"
|
||||||
onclick={() => deleteUser(item)}
|
onclick={() => deleteUser(item)}
|
||||||
|
|||||||
Reference in New Issue
Block a user