mirror of
https://github.com/nikdoof/pocket-id.git
synced 2025-12-13 23:02:17 +00:00
feat: add sorting for tables
This commit is contained in:
@@ -3,8 +3,8 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"github.com/stonith404/pocket-id/backend/internal/dto"
|
"github.com/stonith404/pocket-id/backend/internal/dto"
|
||||||
"github.com/stonith404/pocket-id/backend/internal/middleware"
|
"github.com/stonith404/pocket-id/backend/internal/middleware"
|
||||||
|
"github.com/stonith404/pocket-id/backend/internal/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/stonith404/pocket-id/backend/internal/service"
|
"github.com/stonith404/pocket-id/backend/internal/service"
|
||||||
@@ -23,12 +23,16 @@ type AuditLogController struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (alc *AuditLogController) listAuditLogsForUserHandler(c *gin.Context) {
|
func (alc *AuditLogController) listAuditLogsForUserHandler(c *gin.Context) {
|
||||||
|
var sortedPaginationRequest utils.SortedPaginationRequest
|
||||||
|
if err := c.ShouldBindQuery(&sortedPaginationRequest); err != nil {
|
||||||
|
c.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
userID := c.GetString("userID")
|
userID := c.GetString("userID")
|
||||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
||||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("limit", "10"))
|
|
||||||
|
|
||||||
// Fetch audit logs for the user
|
// Fetch audit logs for the user
|
||||||
logs, pagination, err := alc.auditLogService.ListAuditLogsForUser(userID, page, pageSize)
|
logs, pagination, err := alc.auditLogService.ListAuditLogsForUser(userID, sortedPaginationRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Error(err)
|
c.Error(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
"github.com/stonith404/pocket-id/backend/internal/dto"
|
"github.com/stonith404/pocket-id/backend/internal/dto"
|
||||||
"github.com/stonith404/pocket-id/backend/internal/middleware"
|
"github.com/stonith404/pocket-id/backend/internal/middleware"
|
||||||
"github.com/stonith404/pocket-id/backend/internal/service"
|
"github.com/stonith404/pocket-id/backend/internal/service"
|
||||||
|
"github.com/stonith404/pocket-id/backend/internal/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -153,11 +153,14 @@ func (oc *OidcController) getClientHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (oc *OidcController) listClientsHandler(c *gin.Context) {
|
func (oc *OidcController) listClientsHandler(c *gin.Context) {
|
||||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
||||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("limit", "10"))
|
|
||||||
searchTerm := c.Query("search")
|
searchTerm := c.Query("search")
|
||||||
|
var sortedPaginationRequest utils.SortedPaginationRequest
|
||||||
|
if err := c.ShouldBindQuery(&sortedPaginationRequest); err != nil {
|
||||||
|
c.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
clients, pagination, err := oc.oidcService.ListClients(searchTerm, page, pageSize)
|
clients, pagination, err := oc.oidcService.ListClients(searchTerm, sortedPaginationRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Error(err)
|
c.Error(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"github.com/stonith404/pocket-id/backend/internal/dto"
|
"github.com/stonith404/pocket-id/backend/internal/dto"
|
||||||
"github.com/stonith404/pocket-id/backend/internal/middleware"
|
"github.com/stonith404/pocket-id/backend/internal/middleware"
|
||||||
"github.com/stonith404/pocket-id/backend/internal/service"
|
"github.com/stonith404/pocket-id/backend/internal/service"
|
||||||
|
"github.com/stonith404/pocket-id/backend/internal/utils"
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,11 +37,14 @@ type UserController struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (uc *UserController) listUsersHandler(c *gin.Context) {
|
func (uc *UserController) listUsersHandler(c *gin.Context) {
|
||||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
||||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("limit", "10"))
|
|
||||||
searchTerm := c.Query("search")
|
searchTerm := c.Query("search")
|
||||||
|
var sortedPaginationRequest utils.SortedPaginationRequest
|
||||||
|
if err := c.ShouldBindQuery(&sortedPaginationRequest); err != nil {
|
||||||
|
c.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
users, pagination, err := uc.UserService.ListUsers(searchTerm, page, pageSize)
|
users, pagination, err := uc.UserService.ListUsers(searchTerm, sortedPaginationRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Error(err)
|
c.Error(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/stonith404/pocket-id/backend/internal/dto"
|
"github.com/stonith404/pocket-id/backend/internal/dto"
|
||||||
"github.com/stonith404/pocket-id/backend/internal/middleware"
|
"github.com/stonith404/pocket-id/backend/internal/middleware"
|
||||||
"github.com/stonith404/pocket-id/backend/internal/service"
|
"github.com/stonith404/pocket-id/backend/internal/service"
|
||||||
|
"github.com/stonith404/pocket-id/backend/internal/utils"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewUserGroupController(group *gin.RouterGroup, jwtAuthMiddleware *middleware.JwtAuthMiddleware, userGroupService *service.UserGroupService) {
|
func NewUserGroupController(group *gin.RouterGroup, jwtAuthMiddleware *middleware.JwtAuthMiddleware, userGroupService *service.UserGroupService) {
|
||||||
@@ -28,16 +27,20 @@ type UserGroupController struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ugc *UserGroupController) list(c *gin.Context) {
|
func (ugc *UserGroupController) list(c *gin.Context) {
|
||||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
||||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("limit", "10"))
|
|
||||||
searchTerm := c.Query("search")
|
searchTerm := c.Query("search")
|
||||||
|
var sortedPaginationRequest utils.SortedPaginationRequest
|
||||||
|
if err := c.ShouldBindQuery(&sortedPaginationRequest); err != nil {
|
||||||
|
c.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
groups, pagination, err := ugc.UserGroupService.List(searchTerm, page, pageSize)
|
groups, pagination, err := ugc.UserGroupService.List(searchTerm, sortedPaginationRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Error(err)
|
c.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Map the user groups to DTOs. The user count can't be mapped directly, so we have to do it manually.
|
||||||
var groupsDto = make([]dto.UserGroupDtoWithUserCount, len(groups))
|
var groupsDto = make([]dto.UserGroupDtoWithUserCount, len(groups))
|
||||||
for i, group := range groups {
|
for i, group := range groups {
|
||||||
var groupDto dto.UserGroupDtoWithUserCount
|
var groupDto dto.UserGroupDtoWithUserCount
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import (
|
|||||||
type AuditLog struct {
|
type AuditLog struct {
|
||||||
Base
|
Base
|
||||||
|
|
||||||
Event AuditLogEvent
|
Event AuditLogEvent `sortable:"true"`
|
||||||
IpAddress string
|
IpAddress string `sortable:"true"`
|
||||||
Country string
|
Country string `sortable:"true"`
|
||||||
City string
|
City string `sortable:"true"`
|
||||||
UserAgent string
|
UserAgent string `sortable:"true"`
|
||||||
UserID string
|
UserID string
|
||||||
Data AuditLogData
|
Data AuditLogData
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
|
|
||||||
// Base contains common columns for all tables.
|
// Base contains common columns for all tables.
|
||||||
type Base struct {
|
type Base struct {
|
||||||
ID string `gorm:"primaryKey;not null"`
|
ID string `gorm:"primaryKey;not null"`
|
||||||
CreatedAt model.DateTime
|
CreatedAt model.DateTime `sortable:"true"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Base) BeforeCreate(_ *gorm.DB) (err error) {
|
func (b *Base) BeforeCreate(_ *gorm.DB) (err error) {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type OidcAuthorizationCode struct {
|
|||||||
type OidcClient struct {
|
type OidcClient struct {
|
||||||
Base
|
Base
|
||||||
|
|
||||||
Name string
|
Name string `sortable:"true"`
|
||||||
Secret string
|
Secret string
|
||||||
CallbackURLs CallbackURLs
|
CallbackURLs CallbackURLs
|
||||||
ImageType *string
|
ImageType *string
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import (
|
|||||||
type User struct {
|
type User struct {
|
||||||
Base
|
Base
|
||||||
|
|
||||||
Username string
|
Username string `sortable:"true"`
|
||||||
Email string
|
Email string `sortable:"true"`
|
||||||
FirstName string
|
FirstName string `sortable:"true"`
|
||||||
LastName string
|
LastName string `sortable:"true"`
|
||||||
IsAdmin bool
|
IsAdmin bool `sortable:"true"`
|
||||||
|
|
||||||
CustomClaims []CustomClaim
|
CustomClaims []CustomClaim
|
||||||
UserGroups []UserGroup `gorm:"many2many:user_groups_users;"`
|
UserGroups []UserGroup `gorm:"many2many:user_groups_users;"`
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package model
|
|||||||
|
|
||||||
type UserGroup struct {
|
type UserGroup struct {
|
||||||
Base
|
Base
|
||||||
FriendlyName string
|
FriendlyName string `sortable:"true"`
|
||||||
Name string `gorm:"unique"`
|
Name string `gorm:"unique" sortable:"true"`
|
||||||
Users []User `gorm:"many2many:user_groups_users;"`
|
Users []User `gorm:"many2many:user_groups_users;"`
|
||||||
CustomClaims []CustomClaim
|
CustomClaims []CustomClaim
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,11 +84,11 @@ func (s *AuditLogService) CreateNewSignInWithEmail(ipAddress, userAgent, userID
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListAuditLogsForUser retrieves all audit logs for a given user ID
|
// ListAuditLogsForUser retrieves all audit logs for a given user ID
|
||||||
func (s *AuditLogService) ListAuditLogsForUser(userID string, page int, pageSize int) ([]model.AuditLog, utils.PaginationResponse, error) {
|
func (s *AuditLogService) ListAuditLogsForUser(userID string, sortedPaginationRequest utils.SortedPaginationRequest) ([]model.AuditLog, utils.PaginationResponse, error) {
|
||||||
var logs []model.AuditLog
|
var logs []model.AuditLog
|
||||||
query := s.db.Model(&model.AuditLog{}).Where("user_id = ?", userID).Order("created_at desc")
|
query := s.db.Model(&model.AuditLog{}).Where("user_id = ?", userID)
|
||||||
|
|
||||||
pagination, err := utils.Paginate(page, pageSize, query, &logs)
|
pagination, err := utils.PaginateAndSort(sortedPaginationRequest, query, &logs)
|
||||||
return logs, pagination, err
|
return logs, pagination, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ func (s *OidcService) GetClient(clientID string) (model.OidcClient, error) {
|
|||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OidcService) ListClients(searchTerm string, page int, pageSize int) ([]model.OidcClient, utils.PaginationResponse, error) {
|
func (s *OidcService) ListClients(searchTerm string, sortedPaginationRequest utils.SortedPaginationRequest) ([]model.OidcClient, utils.PaginationResponse, error) {
|
||||||
var clients []model.OidcClient
|
var clients []model.OidcClient
|
||||||
|
|
||||||
query := s.db.Preload("CreatedBy").Model(&model.OidcClient{})
|
query := s.db.Preload("CreatedBy").Model(&model.OidcClient{})
|
||||||
@@ -176,7 +176,7 @@ func (s *OidcService) ListClients(searchTerm string, page int, pageSize int) ([]
|
|||||||
query = query.Where("name LIKE ?", searchPattern)
|
query = query.Where("name LIKE ?", searchPattern)
|
||||||
}
|
}
|
||||||
|
|
||||||
pagination, err := utils.Paginate(page, pageSize, query, &clients)
|
pagination, err := utils.PaginateAndSort(sortedPaginationRequest, query, &clients)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.PaginationResponse{}, err
|
return nil, utils.PaginationResponse{}, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,14 +17,26 @@ func NewUserGroupService(db *gorm.DB) *UserGroupService {
|
|||||||
return &UserGroupService{db: db}
|
return &UserGroupService{db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserGroupService) List(name string, page int, pageSize int) (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) {
|
||||||
query := s.db.Preload("CustomClaims").Model(&model.UserGroup{})
|
query := s.db.Preload("CustomClaims").Model(&model.UserGroup{})
|
||||||
|
|
||||||
if name != "" {
|
if name != "" {
|
||||||
query = query.Where("name LIKE ?", "%"+name+"%")
|
query = query.Where("name LIKE ?", "%"+name+"%")
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err = utils.Paginate(page, pageSize, query, &groups)
|
// As userCount is not a column we need to manually sort it
|
||||||
|
isValidSortDirection := sortedPaginationRequest.Sort.Direction == "asc" || sortedPaginationRequest.Sort.Direction == "desc"
|
||||||
|
if sortedPaginationRequest.Sort.Column == "userCount" && isValidSortDirection {
|
||||||
|
query = query.Select("user_groups.*, COUNT(user_groups_users.user_id)").
|
||||||
|
Joins("LEFT JOIN user_groups_users ON user_groups.id = user_groups_users.user_group_id").
|
||||||
|
Group("user_groups.id").
|
||||||
|
Order("COUNT(user_groups_users.user_id) " + sortedPaginationRequest.Sort.Direction)
|
||||||
|
|
||||||
|
response, err := utils.Paginate(sortedPaginationRequest.Pagination.Page, sortedPaginationRequest.Pagination.Limit, query, &groups)
|
||||||
|
return groups, response, err
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err = utils.PaginateAndSort(sortedPaginationRequest, query, &groups)
|
||||||
return groups, response, err
|
return groups, response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func NewUserService(db *gorm.DB, jwtService *JwtService, auditLogService *AuditL
|
|||||||
return &UserService{db: db, jwtService: jwtService, auditLogService: auditLogService}
|
return &UserService{db: db, jwtService: jwtService, auditLogService: auditLogService}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserService) ListUsers(searchTerm string, page int, pageSize int) ([]model.User, utils.PaginationResponse, error) {
|
func (s *UserService) ListUsers(searchTerm string, sortedPaginationRequest utils.SortedPaginationRequest) ([]model.User, utils.PaginationResponse, error) {
|
||||||
var users []model.User
|
var users []model.User
|
||||||
query := s.db.Model(&model.User{})
|
query := s.db.Model(&model.User{})
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ func (s *UserService) ListUsers(searchTerm string, page int, pageSize int) ([]mo
|
|||||||
query = query.Where("email LIKE ? OR first_name LIKE ? OR username LIKE ?", searchPattern, searchPattern, searchPattern)
|
query = query.Where("email LIKE ? OR first_name LIKE ? OR username LIKE ?", searchPattern, searchPattern, searchPattern)
|
||||||
}
|
}
|
||||||
|
|
||||||
pagination, err := utils.Paginate(page, pageSize, query, &users)
|
pagination, err := utils.PaginateAndSort(sortedPaginationRequest, query, &users)
|
||||||
return users, pagination, err
|
return users, pagination, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PaginationResponse struct {
|
type PaginationResponse struct {
|
||||||
@@ -11,7 +12,36 @@ type PaginationResponse struct {
|
|||||||
ItemsPerPage int `json:"itemsPerPage"`
|
ItemsPerPage int `json:"itemsPerPage"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Paginate(page int, pageSize int, db *gorm.DB, result interface{}) (PaginationResponse, error) {
|
type SortedPaginationRequest struct {
|
||||||
|
Pagination struct {
|
||||||
|
Page int `form:"pagination[page]"`
|
||||||
|
Limit int `form:"pagination[limit]"`
|
||||||
|
} `form:"pagination"`
|
||||||
|
Sort struct {
|
||||||
|
Column string `form:"sort[column]"`
|
||||||
|
Direction string `form:"sort[direction]"`
|
||||||
|
} `form:"sort"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func PaginateAndSort(sortedPaginationRequest SortedPaginationRequest, query *gorm.DB, result interface{}) (PaginationResponse, error) {
|
||||||
|
pagination := sortedPaginationRequest.Pagination
|
||||||
|
sort := sortedPaginationRequest.Sort
|
||||||
|
|
||||||
|
capitalizedSortColumn := CapitalizeFirstLetter(sort.Column)
|
||||||
|
|
||||||
|
sortField, sortFieldFound := reflect.TypeOf(result).Elem().Elem().FieldByName(capitalizedSortColumn)
|
||||||
|
isSortable := sortField.Tag.Get("sortable") == "true"
|
||||||
|
isValidSortOrder := sort.Direction == "asc" || sort.Direction == "desc"
|
||||||
|
|
||||||
|
if sortFieldFound && isSortable && isValidSortOrder {
|
||||||
|
query = query.Order(CamelCaseToSnakeCase(sort.Column) + " " + sort.Direction)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Paginate(pagination.Page, pagination.Limit, query, result)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func Paginate(page int, pageSize int, query *gorm.DB, result interface{}) (PaginationResponse, error) {
|
||||||
if page < 1 {
|
if page < 1 {
|
||||||
page = 1
|
page = 1
|
||||||
}
|
}
|
||||||
@@ -25,11 +55,11 @@ func Paginate(page int, pageSize int, db *gorm.DB, result interface{}) (Paginati
|
|||||||
offset := (page - 1) * pageSize
|
offset := (page - 1) * pageSize
|
||||||
|
|
||||||
var totalItems int64
|
var totalItems int64
|
||||||
if err := db.Count(&totalItems).Error; err != nil {
|
if err := query.Count(&totalItems).Error; err != nil {
|
||||||
return PaginationResponse{}, err
|
return PaginationResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := db.Offset(offset).Limit(pageSize).Find(result).Error; err != nil {
|
if err := query.Offset(offset).Limit(pageSize).Find(result).Error; err != nil {
|
||||||
return PaginationResponse{}, err
|
return PaginationResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GenerateRandomAlphanumericString generates a random alphanumeric string of the given length
|
// GenerateRandomAlphanumericString generates a random alphanumeric string of the given length
|
||||||
@@ -41,3 +42,23 @@ func GetHostnameFromURL(rawURL string) string {
|
|||||||
func StringPointer(s string) *string {
|
func StringPointer(s string) *string {
|
||||||
return &s
|
return &s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CapitalizeFirstLetter(s string) string {
|
||||||
|
if s == "" {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
runes := []rune(s)
|
||||||
|
runes[0] = unicode.ToUpper(runes[0])
|
||||||
|
return string(runes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CamelCaseToSnakeCase(s string) string {
|
||||||
|
var result []rune
|
||||||
|
for i, r := range s {
|
||||||
|
if unicode.IsUpper(r) && i > 0 {
|
||||||
|
result = append(result, '_')
|
||||||
|
}
|
||||||
|
result = append(result, unicode.ToLower(r))
|
||||||
|
}
|
||||||
|
return string(result)
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,26 +5,44 @@
|
|||||||
import * as Select from '$lib/components/ui/select';
|
import * as Select from '$lib/components/ui/select';
|
||||||
import * as Table from '$lib/components/ui/table/index.js';
|
import * as Table from '$lib/components/ui/table/index.js';
|
||||||
import Empty from '$lib/icons/empty.svelte';
|
import Empty from '$lib/icons/empty.svelte';
|
||||||
import type { Paginated } from '$lib/types/pagination.type';
|
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';
|
||||||
import { debounced } from '$lib/utils/debounce-util';
|
import { debounced } from '$lib/utils/debounce-util';
|
||||||
|
import { cn } from '$lib/utils/style';
|
||||||
|
import { ChevronDown } from 'lucide-svelte';
|
||||||
import type { Snippet } from 'svelte';
|
import type { Snippet } from 'svelte';
|
||||||
|
import Button from './ui/button/button.svelte';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
items,
|
items,
|
||||||
|
requestOptions = $bindable(),
|
||||||
selectedIds = $bindable(),
|
selectedIds = $bindable(),
|
||||||
withoutSearch = false,
|
withoutSearch = false,
|
||||||
fetchItems,
|
defaultSort,
|
||||||
|
onRefresh,
|
||||||
columns,
|
columns,
|
||||||
rows
|
rows
|
||||||
}: {
|
}: {
|
||||||
items: Paginated<T>;
|
items: Paginated<T>;
|
||||||
|
requestOptions?: SearchPaginationSortRequest;
|
||||||
selectedIds?: string[];
|
selectedIds?: string[];
|
||||||
withoutSearch?: boolean;
|
withoutSearch?: boolean;
|
||||||
fetchItems: (search: string, page: number, limit: number) => Promise<Paginated<T>>;
|
defaultSort?: { column: string; direction: 'asc' | 'desc' };
|
||||||
columns: (string | { label: string; hidden?: boolean })[];
|
onRefresh: (requestOptions: SearchPaginationSortRequest) => Promise<Paginated<T>>;
|
||||||
|
columns: { label: string; hidden?: boolean; sortColumn?: string }[];
|
||||||
rows: Snippet<[{ item: T }]>;
|
rows: Snippet<[{ item: T }]>;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
|
if (!requestOptions) {
|
||||||
|
requestOptions = {
|
||||||
|
search: '',
|
||||||
|
sort: defaultSort,
|
||||||
|
pagination: {
|
||||||
|
page: items.pagination.currentPage,
|
||||||
|
limit: items.pagination.itemsPerPage
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let availablePageSizes: number[] = [10, 20, 50, 100];
|
let availablePageSizes: number[] = [10, 20, 50, 100];
|
||||||
|
|
||||||
let allChecked = $derived.by(() => {
|
let allChecked = $derived.by(() => {
|
||||||
@@ -38,7 +56,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
const onSearch = debounced(async (searchValue: string) => {
|
const onSearch = debounced(async (searchValue: string) => {
|
||||||
items = await fetchItems(searchValue, 1, items.pagination.itemsPerPage);
|
requestOptions.search = searchValue;
|
||||||
|
onRefresh(requestOptions);
|
||||||
}, 300);
|
}, 300);
|
||||||
|
|
||||||
async function onAllCheck(checked: boolean) {
|
async function onAllCheck(checked: boolean) {
|
||||||
@@ -59,11 +78,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function onPageChange(page: number) {
|
async function onPageChange(page: number) {
|
||||||
items = await fetchItems('', page, items.pagination.itemsPerPage);
|
requestOptions!.pagination = { limit: items.pagination.itemsPerPage, page };
|
||||||
|
onRefresh(requestOptions!);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onPageSizeChange(size: number) {
|
async function onPageSizeChange(size: number) {
|
||||||
items = await fetchItems('', 1, size);
|
requestOptions!.pagination = { limit: size, page: 1 };
|
||||||
|
onRefresh(requestOptions!);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onSort(column?: string, direction: 'asc' | 'desc' = 'asc') {
|
||||||
|
if (!column) return;
|
||||||
|
|
||||||
|
requestOptions!.sort = { column, direction };
|
||||||
|
onRefresh(requestOptions!);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -92,11 +120,31 @@
|
|||||||
</Table.Head>
|
</Table.Head>
|
||||||
{/if}
|
{/if}
|
||||||
{#each columns as column}
|
{#each columns as column}
|
||||||
{#if typeof column === 'string'}
|
<Table.Head class={cn(column.hidden && 'sr-only', column.sortColumn && 'px-0')}>
|
||||||
<Table.Head>{column}</Table.Head>
|
{#if column.sortColumn}
|
||||||
{:else}
|
<Button
|
||||||
<Table.Head class={column.hidden ? 'sr-only' : ''}>{column.label}</Table.Head>
|
variant="ghost"
|
||||||
{/if}
|
class="flex items-center"
|
||||||
|
on:click={() =>
|
||||||
|
onSort(
|
||||||
|
column.sortColumn,
|
||||||
|
requestOptions.sort?.direction === 'desc' ? 'asc' : 'desc'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{column.label}
|
||||||
|
{#if requestOptions.sort?.column === column.sortColumn}
|
||||||
|
<ChevronDown
|
||||||
|
class={cn(
|
||||||
|
'ml-2 h-4 w-4',
|
||||||
|
requestOptions.sort?.direction === 'asc' ? 'rotate-180' : ''
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</Button>
|
||||||
|
{:else}
|
||||||
|
{column.label}
|
||||||
|
{/if}
|
||||||
|
</Table.Head>
|
||||||
{/each}
|
{/each}
|
||||||
</Table.Row>
|
</Table.Row>
|
||||||
</Table.Header>
|
</Table.Header>
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import type { AuditLog } from '$lib/types/audit-log.type';
|
import type { AuditLog } from '$lib/types/audit-log.type';
|
||||||
import type { Paginated, PaginationRequest } from '$lib/types/pagination.type';
|
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';
|
||||||
import APIService from './api-service';
|
import APIService from './api-service';
|
||||||
|
|
||||||
class AuditLogService extends APIService {
|
class AuditLogService extends APIService {
|
||||||
async list(pagination?: PaginationRequest) {
|
async list(options?: SearchPaginationSortRequest) {
|
||||||
const res = await this.api.get('/audit-logs', {
|
const res = await this.api.get('/audit-logs', {
|
||||||
params: pagination
|
params: options
|
||||||
});
|
});
|
||||||
return res.data as Paginated<AuditLog>;
|
return res.data as Paginated<AuditLog>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
import type { AuthorizeResponse, OidcClient, OidcClientCreate } from '$lib/types/oidc.type';
|
import type { AuthorizeResponse, OidcClient, OidcClientCreate } from '$lib/types/oidc.type';
|
||||||
import type { Paginated, PaginationRequest } from '$lib/types/pagination.type';
|
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';
|
||||||
import APIService from './api-service';
|
import APIService from './api-service';
|
||||||
|
|
||||||
class OidcService extends APIService {
|
class OidcService extends APIService {
|
||||||
async authorize(clientId: string, scope: string, callbackURL: string, nonce?: string, codeChallenge?: string, codeChallengeMethod?: string) {
|
async authorize(
|
||||||
|
clientId: string,
|
||||||
|
scope: string,
|
||||||
|
callbackURL: string,
|
||||||
|
nonce?: string,
|
||||||
|
codeChallenge?: string,
|
||||||
|
codeChallengeMethod?: string
|
||||||
|
) {
|
||||||
const res = await this.api.post('/oidc/authorize', {
|
const res = await this.api.post('/oidc/authorize', {
|
||||||
scope,
|
scope,
|
||||||
nonce,
|
nonce,
|
||||||
@@ -16,7 +23,14 @@ class OidcService extends APIService {
|
|||||||
return res.data as AuthorizeResponse;
|
return res.data as AuthorizeResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
async authorizeNewClient(clientId: string, scope: string, callbackURL: string, nonce?: string, codeChallenge?: string, codeChallengeMethod?: string) {
|
async authorizeNewClient(
|
||||||
|
clientId: string,
|
||||||
|
scope: string,
|
||||||
|
callbackURL: string,
|
||||||
|
nonce?: string,
|
||||||
|
codeChallenge?: string,
|
||||||
|
codeChallengeMethod?: string
|
||||||
|
) {
|
||||||
const res = await this.api.post('/oidc/authorize/new-client', {
|
const res = await this.api.post('/oidc/authorize/new-client', {
|
||||||
scope,
|
scope,
|
||||||
nonce,
|
nonce,
|
||||||
@@ -29,12 +43,9 @@ class OidcService extends APIService {
|
|||||||
return res.data as AuthorizeResponse;
|
return res.data as AuthorizeResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
async listClients(search?: string, pagination?: PaginationRequest) {
|
async listClients(options?: SearchPaginationSortRequest) {
|
||||||
const res = await this.api.get('/oidc/clients', {
|
const res = await this.api.get('/oidc/clients', {
|
||||||
params: {
|
params: options
|
||||||
search,
|
|
||||||
...pagination
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return res.data as Paginated<OidcClient>;
|
return res.data as Paginated<OidcClient>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Paginated, PaginationRequest } from '$lib/types/pagination.type';
|
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';
|
||||||
import type {
|
import type {
|
||||||
UserGroupCreate,
|
UserGroupCreate,
|
||||||
UserGroupWithUserCount,
|
UserGroupWithUserCount,
|
||||||
@@ -7,12 +7,9 @@ import type {
|
|||||||
import APIService from './api-service';
|
import APIService from './api-service';
|
||||||
|
|
||||||
export default class UserGroupService extends APIService {
|
export default class UserGroupService extends APIService {
|
||||||
async list(search?: string, pagination?: PaginationRequest) {
|
async list(options?: SearchPaginationSortRequest) {
|
||||||
const res = await this.api.get('/user-groups', {
|
const res = await this.api.get('/user-groups', {
|
||||||
params: {
|
params: options
|
||||||
search,
|
|
||||||
...pagination
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return res.data as Paginated<UserGroupWithUserCount>;
|
return res.data as Paginated<UserGroupWithUserCount>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
import type { Paginated, PaginationRequest } from '$lib/types/pagination.type';
|
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';
|
||||||
import type { User, UserCreate } from '$lib/types/user.type';
|
import type { User, UserCreate } from '$lib/types/user.type';
|
||||||
import APIService from './api-service';
|
import APIService from './api-service';
|
||||||
|
|
||||||
export default class UserService extends APIService {
|
export default class UserService extends APIService {
|
||||||
async list(search?: string, pagination?: PaginationRequest) {
|
async list(options?: SearchPaginationSortRequest) {
|
||||||
const res = await this.api.get('/users', {
|
const res = await this.api.get('/users', {
|
||||||
params: {
|
params: options
|
||||||
search,
|
|
||||||
...pagination
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return res.data as Paginated<User>;
|
return res.data as Paginated<User>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,17 @@ export type PaginationRequest = {
|
|||||||
limit: number;
|
limit: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type SortRequest = {
|
||||||
|
column: string;
|
||||||
|
direction: "asc" | "desc";
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SearchPaginationSortRequest = {
|
||||||
|
search?: string,
|
||||||
|
pagination?: PaginationRequest;
|
||||||
|
sort?: SortRequest;
|
||||||
|
}
|
||||||
|
|
||||||
export type PaginationResponse = {
|
export type PaginationResponse = {
|
||||||
totalPages: number;
|
totalPages: number;
|
||||||
totalItems: number;
|
totalItems: number;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
import * as Table from '$lib/components/ui/table';
|
import * as Table from '$lib/components/ui/table';
|
||||||
import OIDCService from '$lib/services/oidc-service';
|
import OIDCService from '$lib/services/oidc-service';
|
||||||
import type { OidcClient } from '$lib/types/oidc.type';
|
import type { OidcClient } from '$lib/types/oidc.type';
|
||||||
import type { Paginated, PaginationRequest } from '$lib/types/pagination.type';
|
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';
|
||||||
import { axiosErrorToast } from '$lib/utils/error-util';
|
import { axiosErrorToast } from '$lib/utils/error-util';
|
||||||
import { LucidePencil, LucideTrash } from 'lucide-svelte';
|
import { LucidePencil, LucideTrash } from 'lucide-svelte';
|
||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
let { clients: initialClients }: { clients: Paginated<OidcClient> } = $props();
|
let { clients: initialClients }: { clients: Paginated<OidcClient> } = $props();
|
||||||
let clients = $state<Paginated<OidcClient>>(initialClients);
|
let clients = $state<Paginated<OidcClient>>(initialClients);
|
||||||
let oneTimeLink = $state<string | null>(null);
|
let oneTimeLink = $state<string | null>(null);
|
||||||
|
let requestOptions: SearchPaginationSortRequest | undefined = $state();
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
clients = initialClients;
|
clients = initialClients;
|
||||||
@@ -21,12 +22,6 @@
|
|||||||
|
|
||||||
const oidcService = new OIDCService();
|
const oidcService = new OIDCService();
|
||||||
|
|
||||||
let pagination = $state<PaginationRequest>({
|
|
||||||
page: 1,
|
|
||||||
limit: 10
|
|
||||||
});
|
|
||||||
let search = $state('');
|
|
||||||
|
|
||||||
async function deleteClient(client: OidcClient) {
|
async function deleteClient(client: OidcClient) {
|
||||||
openConfirmDialog({
|
openConfirmDialog({
|
||||||
title: `Delete ${client.name}`,
|
title: `Delete ${client.name}`,
|
||||||
@@ -37,7 +32,7 @@
|
|||||||
action: async () => {
|
action: async () => {
|
||||||
try {
|
try {
|
||||||
await oidcService.removeClient(client.id);
|
await oidcService.removeClient(client.id);
|
||||||
clients = await oidcService.listClients(search, pagination);
|
clients = await oidcService.listClients(requestOptions!);
|
||||||
toast.success('OIDC client deleted successfully');
|
toast.success('OIDC client deleted successfully');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
axiosErrorToast(e);
|
axiosErrorToast(e);
|
||||||
@@ -46,16 +41,17 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchItems(search: string, page: number, limit: number) {
|
|
||||||
return oidcService.listClients(search, { page, limit });
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<AdvancedTable
|
<AdvancedTable
|
||||||
items={clients}
|
items={clients}
|
||||||
{fetchItems}
|
{requestOptions}
|
||||||
columns={['Logo', 'Name', { label: 'Actions', hidden: true }]}
|
onRefresh={async(o) => clients = await oidcService.listClients(o)}
|
||||||
|
columns={[
|
||||||
|
{ label: 'Logo' },
|
||||||
|
{ label: 'Name', sortColumn: 'name' },
|
||||||
|
{ label: 'Actions', hidden: true }
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
{#snippet rows({ item })}
|
{#snippet rows({ item })}
|
||||||
<Table.Cell class="w-8 font-medium">
|
<Table.Cell class="w-8 font-medium">
|
||||||
|
|||||||
@@ -5,7 +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 type { Paginated } 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';
|
||||||
import { LucidePencil, LucideTrash } from 'lucide-svelte';
|
import { LucidePencil, LucideTrash } from 'lucide-svelte';
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
$props();
|
$props();
|
||||||
|
|
||||||
let userGroups = $state<Paginated<UserGroupWithUserCount>>(initialUserGroups);
|
let userGroups = $state<Paginated<UserGroupWithUserCount>>(initialUserGroups);
|
||||||
|
let requestOptions: SearchPaginationSortRequest | undefined = $state();
|
||||||
|
|
||||||
const userGroupService = new UserGroupService();
|
const userGroupService = new UserGroupService();
|
||||||
|
|
||||||
@@ -29,7 +30,7 @@
|
|||||||
action: async () => {
|
action: async () => {
|
||||||
try {
|
try {
|
||||||
await userGroupService.remove(userGroup.id);
|
await userGroupService.remove(userGroup.id);
|
||||||
userGroups = await userGroupService.list();
|
userGroups = await userGroupService.list(requestOptions!);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
axiosErrorToast(e);
|
axiosErrorToast(e);
|
||||||
}
|
}
|
||||||
@@ -38,13 +39,19 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchItems(search: string, page: number, limit: number) {
|
|
||||||
return userGroupService.list(search, { page, limit });
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<AdvancedTable items={userGroups} {fetchItems} columns={['Friendly Name', 'Name', 'User Count', {label: "Actions", hidden: true}]}>
|
<AdvancedTable
|
||||||
|
items={userGroups}
|
||||||
|
onRefresh={async (o) => (userGroups = await userGroupService.list(o))}
|
||||||
|
{requestOptions}
|
||||||
|
columns={[
|
||||||
|
{ label: 'Friendly Name', sortColumn: 'friendlyName' },
|
||||||
|
{ label: 'Name', sortColumn: 'name' },
|
||||||
|
{ label: 'User Count', sortColumn: 'userCount' },
|
||||||
|
{ label: 'Actions', hidden: true }
|
||||||
|
]}
|
||||||
|
>
|
||||||
{#snippet rows({ item })}
|
{#snippet rows({ item })}
|
||||||
<Table.Cell>{item.friendlyName}</Table.Cell>
|
<Table.Cell>{item.friendlyName}</Table.Cell>
|
||||||
<Table.Cell>{item.name}</Table.Cell>
|
<Table.Cell>{item.name}</Table.Cell>
|
||||||
|
|||||||
@@ -13,16 +13,15 @@
|
|||||||
const userService = new UserService();
|
const userService = new UserService();
|
||||||
|
|
||||||
let users = $state(initialUsers);
|
let users = $state(initialUsers);
|
||||||
|
|
||||||
function fetchItems(search: string, page: number, limit: number) {
|
|
||||||
return userService.list(search, { page, limit });
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<AdvancedTable
|
<AdvancedTable
|
||||||
items={users}
|
items={users}
|
||||||
{fetchItems}
|
onRefresh={async (o) => (users = await userService.list(o))}
|
||||||
columns={['Name', 'Email']}
|
columns={[
|
||||||
|
{ label: 'Name', sortColumn: 'name' },
|
||||||
|
{ label: 'Email', sortColumn: 'email' }
|
||||||
|
]}
|
||||||
bind:selectedIds={selectedUserIds}
|
bind:selectedIds={selectedUserIds}
|
||||||
>
|
>
|
||||||
{#snippet rows({ item })}
|
{#snippet rows({ item })}
|
||||||
|
|||||||
@@ -7,7 +7,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 UserService from '$lib/services/user-service';
|
import UserService from '$lib/services/user-service';
|
||||||
import type { Paginated } from '$lib/types/pagination.type';
|
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';
|
||||||
import type { User } from '$lib/types/user.type';
|
import type { User } from '$lib/types/user.type';
|
||||||
import { axiosErrorToast } from '$lib/utils/error-util';
|
import { axiosErrorToast } from '$lib/utils/error-util';
|
||||||
import { LucideLink, LucidePencil, LucideTrash } from 'lucide-svelte';
|
import { LucideLink, LucidePencil, LucideTrash } from 'lucide-svelte';
|
||||||
@@ -15,20 +15,13 @@
|
|||||||
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';
|
||||||
|
|
||||||
let { users: initialUsers }: { users: Paginated<User> } = $props();
|
let { users = $bindable() }: { users: Paginated<User> } = $props();
|
||||||
let users = $state<Paginated<User>>(initialUsers);
|
let requestOptions: SearchPaginationSortRequest | undefined = $state();
|
||||||
$effect(() => {
|
|
||||||
users = initialUsers;
|
|
||||||
});
|
|
||||||
|
|
||||||
let userIdToCreateOneTimeLink: string | null = $state(null);;
|
let userIdToCreateOneTimeLink: string | null = $state(null);
|
||||||
|
|
||||||
const userService = new UserService();
|
const userService = new UserService();
|
||||||
|
|
||||||
function fetchItems(search: string, page: number, limit: number) {
|
|
||||||
return userService.list(search, { page, limit });
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteUser(user: User) {
|
async function deleteUser(user: User) {
|
||||||
openConfirmDialog({
|
openConfirmDialog({
|
||||||
title: `Delete ${user.firstName} ${user.lastName}`,
|
title: `Delete ${user.firstName} ${user.lastName}`,
|
||||||
@@ -39,7 +32,7 @@
|
|||||||
action: async () => {
|
action: async () => {
|
||||||
try {
|
try {
|
||||||
await userService.remove(user.id);
|
await userService.remove(user.id);
|
||||||
users = await userService.list();
|
users = await userService.list(requestOptions!);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
axiosErrorToast(e);
|
axiosErrorToast(e);
|
||||||
}
|
}
|
||||||
@@ -52,16 +45,34 @@
|
|||||||
|
|
||||||
<AdvancedTable
|
<AdvancedTable
|
||||||
items={users}
|
items={users}
|
||||||
{fetchItems}
|
{requestOptions}
|
||||||
|
onRefresh={async (options) => (users = await userService.list(options))}
|
||||||
columns={[
|
columns={[
|
||||||
'First name',
|
{
|
||||||
'Last name',
|
label: 'First name',
|
||||||
'Email',
|
sortColumn: 'firstName'
|
||||||
'Username',
|
},
|
||||||
'Role',
|
{
|
||||||
{ label: 'Actions', hidden: true }
|
label: 'Last name',
|
||||||
|
sortColumn: 'lastName'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Email',
|
||||||
|
sortColumn: 'email'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Username',
|
||||||
|
sortColumn: 'username'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Role',
|
||||||
|
sortColumn: 'isAdmin'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Actions',
|
||||||
|
hidden: true
|
||||||
|
}
|
||||||
]}
|
]}
|
||||||
withoutSearch
|
|
||||||
>
|
>
|
||||||
{#snippet rows({ item })}
|
{#snippet rows({ item })}
|
||||||
<Table.Cell>{item.firstName}</Table.Cell>
|
<Table.Cell>{item.firstName}</Table.Cell>
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import type { PageServerLoad } from './$types';
|
|||||||
export const load: PageServerLoad = async ({ cookies }) => {
|
export const load: PageServerLoad = async ({ cookies }) => {
|
||||||
const auditLogService = new AuditLogService(cookies.get('access_token'));
|
const auditLogService = new AuditLogService(cookies.get('access_token'));
|
||||||
const auditLogs = await auditLogService.list({
|
const auditLogs = await auditLogService.list({
|
||||||
limit: 15,
|
sort: {
|
||||||
page: 1,
|
column: 'createdAt',
|
||||||
|
direction: 'desc'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
auditLogs
|
auditLogs
|
||||||
|
|||||||
@@ -11,13 +11,6 @@
|
|||||||
|
|
||||||
const auditLogService = new AuditLogService();
|
const auditLogService = new AuditLogService();
|
||||||
|
|
||||||
async function fetchItems(search: string, page: number, limit: number) {
|
|
||||||
return await auditLogService.list({
|
|
||||||
page,
|
|
||||||
limit
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function toFriendlyEventString(event: string) {
|
function toFriendlyEventString(event: string) {
|
||||||
const words = event.split('_');
|
const words = event.split('_');
|
||||||
const capitalizedWords = words.map((word) => {
|
const capitalizedWords = words.map((word) => {
|
||||||
@@ -29,8 +22,16 @@
|
|||||||
|
|
||||||
<AdvancedTable
|
<AdvancedTable
|
||||||
items={auditLogs}
|
items={auditLogs}
|
||||||
{fetchItems}
|
onRefresh={async (options) => (auditLogs = await auditLogService.list(options))}
|
||||||
columns={['Time', 'Event', 'Approximate Location', 'IP Address', 'Device', 'Client']}
|
defaultSort={{ column: 'createdAt', direction: 'desc' }}
|
||||||
|
columns={[
|
||||||
|
{ label: 'Time', sortColumn: 'createdAt' },
|
||||||
|
{ label: 'Event', sortColumn: 'event' },
|
||||||
|
{ label: 'Approximate Location', sortColumn: 'city' },
|
||||||
|
{ label: 'IP Address', sortColumn: 'ipAddress' },
|
||||||
|
{ label: 'Device', sortColumn: 'device' },
|
||||||
|
{ label: 'Client' }
|
||||||
|
]}
|
||||||
withoutSearch
|
withoutSearch
|
||||||
>
|
>
|
||||||
{#snippet rows({ item })}
|
{#snippet rows({ item })}
|
||||||
|
|||||||
Reference in New Issue
Block a user