feat(admin): transfer user accounts and show local cover coverage
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 1m17s
ci / ts / ts (packages + web) (push) Successful in 3m13s
ci / api / api (push) Successful in 59s
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 1m31s
ci / db / db (push) Successful in 2m50s
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 1m17s
ci / ts / ts (packages + web) (push) Successful in 3m13s
ci / api / api (push) Successful in 59s
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 1m31s
ci / db / db (push) Successful in 2m50s
This commit is contained in:
1 parent
0a4cd4bff1
commit
f1528de948
22 files changed
+1661
-313
No files matched your search
@@ -0,0 +1,61 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"pipu/api/internal/api/gen"
|
||||
)
|
||||
|
||||
func (h *Handler) ExportUsers(ctx context.Context, _ gen.ExportUsersRequestObject) (gen.ExportUsersResponseObject, error) {
|
||||
p, err := principal(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
users, err := h.svc.ExportUsers(ctx, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
archive := gen.UserArchive{Version: 1, Users: make([]gen.UserArchiveEntry, 0, len(users))}
|
||||
for _, u := range users {
|
||||
archive.Users = append(archive.Users, gen.UserArchiveEntry{
|
||||
Username: u.Username, DisplayName: u.DisplayName, PasswordHash: u.PasswordHash, Role: gen.Role(u.Role),
|
||||
IsBlocked: u.IsBlocked, MustChangePassword: u.MustChangePassword, MustChangeCredentials: u.MustChangeCredentials,
|
||||
ReviewsUploads: u.ReviewsUploads, ManagesUpdates: u.ManagesUpdates,
|
||||
})
|
||||
}
|
||||
return archiveResponse{archive}, nil
|
||||
}
|
||||
|
||||
type archiveResponse struct{ gen.UserArchive }
|
||||
|
||||
func (r archiveResponse) VisitExportUsersResponse(w http.ResponseWriter) error {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Header().Set("Content-Disposition", `attachment; filename="pipu-users.json"`)
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
return json.NewEncoder(w).Encode(r.UserArchive)
|
||||
}
|
||||
|
||||
func (h *Handler) ImportUsers(ctx context.Context, req gen.ImportUsersRequestObject) (gen.ImportUsersResponseObject, error) {
|
||||
p, err := principal(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if req.Body == nil {
|
||||
return nil, archiveInvalid()
|
||||
}
|
||||
entries := make([]ArchivedUser, 0, len(req.Body.Users))
|
||||
for _, u := range req.Body.Users {
|
||||
entries = append(entries, ArchivedUser{
|
||||
Username: u.Username, DisplayName: u.DisplayName, PasswordHash: u.PasswordHash, Role: Role(u.Role),
|
||||
IsBlocked: u.IsBlocked, MustChangePassword: u.MustChangePassword, MustChangeCredentials: u.MustChangeCredentials,
|
||||
ReviewsUploads: u.ReviewsUploads, ManagesUpdates: u.ManagesUpdates,
|
||||
})
|
||||
}
|
||||
created, skipped, err := h.svc.ImportUsers(ctx, p, int(req.Body.Version), entries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return gen.ImportUsers200JSONResponse{Created: created, Skipped: skipped}, nil
|
||||
}
|
||||
Reference in new issue
Block a user