refac: stale test entries, failing web tests, Postgre backup bug, Hardcoded MySQL table count, Stale Postgre connection in test, own-scope visibility filter, GetAll ignoring its error, JSON tags in use-case types, 31 copies of DESKTOP_QUERY, ProfileView endpoint paths
This commit is contained in:
1 parent
efecdee200
commit
5d6f378fce
87 files changed
+696
-373
No files matched your search
@@ -139,7 +139,12 @@ func (h *LoginHandler) Register(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (h *LoginHandler) RegistrationStatus(w http.ResponseWriter, _ *http.Request) {
|
||||
body, _ := json.Marshal(map[string]bool{"open": h.CreateUseCase.IsRegistrationOpen()})
|
||||
open, err := h.CreateUseCase.IsRegistrationOpen()
|
||||
if err != nil {
|
||||
http.Error(w, apperr.RegistrationFailedErrorMessage, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
body, _ := json.Marshal(map[string]bool{"open": open})
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
_, _ = w.Write(body)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package auth
|
||||
import (
|
||||
"RenewCMS/api/pkg/apperr"
|
||||
"RenewCMS/api/pkg/claims"
|
||||
"RenewCMS/api/pkg/payload"
|
||||
"RenewCMS/api/pkg/publicuser"
|
||||
"RenewCMS/internal/domain/author"
|
||||
"RenewCMS/internal/domain/role"
|
||||
@@ -33,9 +34,9 @@ type meAuthor struct {
|
||||
}
|
||||
|
||||
type meAccess struct {
|
||||
Role useCases.RoleRef `json:"role"`
|
||||
Permissions []role.Grant `json:"permissions"`
|
||||
RoleAssignedBy *useCases.RoleAssigner `json:"role_assigned_by"`
|
||||
Role payload.RoleRef `json:"role"`
|
||||
Permissions []role.Grant `json:"permissions"`
|
||||
RoleAssignedBy *payload.RoleAssigner `json:"role_assigned_by"`
|
||||
}
|
||||
|
||||
type meResponse struct {
|
||||
@@ -46,9 +47,9 @@ type meResponse struct {
|
||||
|
||||
func toMeAccess(access useCases.Access) meAccess {
|
||||
return meAccess{
|
||||
Role: useCases.NewRoleRef(access.Role),
|
||||
Role: payload.RoleRefOf(useCases.NewRoleRef(access.Role)),
|
||||
Permissions: access.Permissions,
|
||||
RoleAssignedBy: access.RoleAssignedBy,
|
||||
RoleAssignedBy: payload.RoleAssignerPtrOf(access.RoleAssignedBy),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package ownership
|
||||
import (
|
||||
"RenewCMS/api/pkg/access"
|
||||
"RenewCMS/api/pkg/apperr"
|
||||
"RenewCMS/api/pkg/payload"
|
||||
validator "RenewCMS/api/pkg/validator"
|
||||
"RenewCMS/internal/domain/user"
|
||||
"RenewCMS/internal/infrastructure/useCases"
|
||||
@@ -45,7 +46,7 @@ func (h *Handler) Transfer(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
body, err := json.Marshal(transferred)
|
||||
body, err := json.Marshal(payload.OwnershipTransferOf(transferred))
|
||||
if err != nil {
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -3,6 +3,7 @@ package role
|
||||
import (
|
||||
"RenewCMS/api/pkg/access"
|
||||
"RenewCMS/api/pkg/apperr"
|
||||
"RenewCMS/api/pkg/payload"
|
||||
validator "RenewCMS/api/pkg/validator"
|
||||
domain "RenewCMS/internal/domain/role"
|
||||
"RenewCMS/internal/infrastructure/useCases"
|
||||
@@ -152,7 +153,7 @@ func (h *Handler) List(w http.ResponseWriter, _ *http.Request) {
|
||||
writeRoleError(w, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, listed)
|
||||
writeJSON(w, http.StatusOK, payload.RoleViewsOf(listed))
|
||||
}
|
||||
|
||||
func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -165,7 +166,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
||||
writeRoleError(w, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, found)
|
||||
writeJSON(w, http.StatusOK, payload.RoleViewOf(found))
|
||||
}
|
||||
|
||||
func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -180,7 +181,7 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
|
||||
writeRoleError(w, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusCreated, created)
|
||||
writeJSON(w, http.StatusCreated, payload.RoleViewOf(created))
|
||||
}
|
||||
|
||||
func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -199,7 +200,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||
writeRoleError(w, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, updated)
|
||||
writeJSON(w, http.StatusOK, payload.RoleViewOf(updated))
|
||||
}
|
||||
|
||||
func (h *Handler) Reset(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -216,7 +217,7 @@ func (h *Handler) Reset(w http.ResponseWriter, r *http.Request) {
|
||||
writeRoleError(w, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, restored)
|
||||
writeJSON(w, http.StatusOK, payload.RoleViewOf(restored))
|
||||
}
|
||||
|
||||
func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"RenewCMS/api/pkg/access"
|
||||
"RenewCMS/api/pkg/apperr"
|
||||
"RenewCMS/api/pkg/claims"
|
||||
"RenewCMS/api/pkg/payload"
|
||||
validator "RenewCMS/api/pkg/validator"
|
||||
"RenewCMS/internal/domain/invite"
|
||||
"RenewCMS/internal/domain/user"
|
||||
@@ -30,34 +31,34 @@ type CreateInviteRequest struct {
|
||||
}
|
||||
|
||||
type inviteResponse struct {
|
||||
ID uint32 `json:"id"`
|
||||
Kind string `json:"kind"`
|
||||
Email string `json:"email"`
|
||||
Status string `json:"status"`
|
||||
Role useCases.RoleRef `json:"role"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
ID uint32 `json:"id"`
|
||||
Kind string `json:"kind"`
|
||||
Email string `json:"email"`
|
||||
Status string `json:"status"`
|
||||
Role payload.RoleRef `json:"role"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
}
|
||||
|
||||
type inviteListItem struct {
|
||||
ID uint32 `json:"id"`
|
||||
Kind string `json:"kind"`
|
||||
Email string `json:"email"`
|
||||
Role *useCases.RoleRef `json:"role"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ID uint32 `json:"id"`
|
||||
Kind string `json:"kind"`
|
||||
Email string `json:"email"`
|
||||
Role *payload.RoleRef `json:"role"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type userListItem struct {
|
||||
ID uint32 `json:"id"`
|
||||
Kind string `json:"kind"`
|
||||
Username string `json:"username"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Email string `json:"email"`
|
||||
Role *useCases.RoleRef `json:"role"`
|
||||
RoleAssignedBy *useCases.RoleAssigner `json:"role_assigned_by"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ID uint32 `json:"id"`
|
||||
Kind string `json:"kind"`
|
||||
Username string `json:"username"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Email string `json:"email"`
|
||||
Role *payload.RoleRef `json:"role"`
|
||||
RoleAssignedBy *payload.RoleAssigner `json:"role_assigned_by"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func NewInviteHandler(createInvite *useCases.CreateInviteUseCase, cancelInvite *useCases.CancelInviteUseCase, renewInvite *useCases.RenewInviteUseCase, listUsersAndInvites *useCases.ListUsersAndInvitesUseCase) *InviteHandler {
|
||||
@@ -107,7 +108,7 @@ func writeInviteResponse(w http.ResponseWriter, status int, entry useCases.Invit
|
||||
Kind: useCases.EntryKindInvite,
|
||||
Email: entry.Email,
|
||||
Status: string(entry.StatusAt(time.Now())),
|
||||
Role: entry.Role,
|
||||
Role: payload.RoleRefOf(entry.Role),
|
||||
CreatedAt: entry.CreatedAt,
|
||||
ExpiresAt: entry.ExpiresAt,
|
||||
})
|
||||
@@ -212,7 +213,7 @@ func (h *InviteHandler) ListUsers(w http.ResponseWriter, _ *http.Request) {
|
||||
ID: entry.ID,
|
||||
Kind: entry.Kind,
|
||||
Email: entry.Email,
|
||||
Role: entry.Role,
|
||||
Role: payload.RoleRefPtrOf(entry.Role),
|
||||
Status: entry.Status,
|
||||
CreatedAt: entry.CreatedAt,
|
||||
})
|
||||
|
||||
@@ -2,6 +2,7 @@ package user
|
||||
|
||||
import (
|
||||
"RenewCMS/api/pkg/apperr"
|
||||
"RenewCMS/api/pkg/payload"
|
||||
"RenewCMS/internal/domain/role"
|
||||
"RenewCMS/internal/infrastructure/useCases"
|
||||
"encoding/json"
|
||||
@@ -16,8 +17,8 @@ func userListItemOf(entry useCases.DirectoryEntry) userListItem {
|
||||
Username: entry.Username,
|
||||
DisplayName: entry.DisplayName,
|
||||
Email: entry.Email,
|
||||
Role: entry.Role,
|
||||
RoleAssignedBy: entry.RoleAssignedBy,
|
||||
Role: payload.RoleRefPtrOf(entry.Role),
|
||||
RoleAssignedBy: payload.RoleAssignerPtrOf(entry.RoleAssignedBy),
|
||||
Status: entry.Status,
|
||||
CreatedAt: entry.CreatedAt,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package payload
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/role"
|
||||
"RenewCMS/internal/infrastructure/useCases"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RoleRef struct {
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
BuiltIn bool `json:"built_in"`
|
||||
Locked bool `json:"locked"`
|
||||
}
|
||||
|
||||
type RoleAssigner struct {
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type RoleEditor struct {
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type RoleView struct {
|
||||
role.Role
|
||||
Members int `json:"members"`
|
||||
UpdatedAt *time.Time `json:"updated_at"`
|
||||
UpdatedBy *RoleEditor `json:"updated_by"`
|
||||
}
|
||||
|
||||
type OwnershipSuccessor struct {
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type OwnershipPredecessor struct {
|
||||
ID uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Role RoleRef `json:"role"`
|
||||
}
|
||||
|
||||
type OwnershipTransfer struct {
|
||||
Owner OwnershipSuccessor `json:"owner"`
|
||||
FormerOwner OwnershipPredecessor `json:"former_owner"`
|
||||
}
|
||||
|
||||
func RoleRefOf(ref useCases.RoleRef) RoleRef {
|
||||
return RoleRef(ref)
|
||||
}
|
||||
|
||||
func RoleRefPtrOf(ref *useCases.RoleRef) *RoleRef {
|
||||
if ref == nil {
|
||||
return nil
|
||||
}
|
||||
converted := RoleRefOf(*ref)
|
||||
return &converted
|
||||
}
|
||||
|
||||
func RoleAssignerPtrOf(assigner *useCases.RoleAssigner) *RoleAssigner {
|
||||
if assigner == nil {
|
||||
return nil
|
||||
}
|
||||
converted := RoleAssigner(*assigner)
|
||||
return &converted
|
||||
}
|
||||
|
||||
func RoleViewOf(view useCases.RoleView) RoleView {
|
||||
converted := RoleView{Role: view.Role, Members: view.Members, UpdatedAt: view.UpdatedAt}
|
||||
if view.UpdatedBy != nil {
|
||||
editor := RoleEditor(*view.UpdatedBy)
|
||||
converted.UpdatedBy = &editor
|
||||
}
|
||||
return converted
|
||||
}
|
||||
|
||||
func RoleViewsOf(views []useCases.RoleView) []RoleView {
|
||||
converted := make([]RoleView, 0, len(views))
|
||||
for _, view := range views {
|
||||
converted = append(converted, RoleViewOf(view))
|
||||
}
|
||||
return converted
|
||||
}
|
||||
|
||||
func OwnershipTransferOf(transfer useCases.OwnershipTransfer) OwnershipTransfer {
|
||||
return OwnershipTransfer{
|
||||
Owner: OwnershipSuccessor(transfer.Owner),
|
||||
FormerOwner: OwnershipPredecessor{ID: transfer.FormerOwner.ID, Name: transfer.FormerOwner.Name, Role: RoleRefOf(transfer.FormerOwner.Role)},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user