mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: prevent archive/delete current user
This commit is contained in:
@@ -312,6 +312,9 @@ func (s *APIV1Service) DeleteUser(c echo.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)
|
||||||
}
|
}
|
||||||
|
if currentUserID == userID {
|
||||||
|
return echo.NewHTTPError(http.StatusBadRequest, "Cannot delete current user")
|
||||||
|
}
|
||||||
|
|
||||||
if err := s.Store.DeleteUser(ctx, &store.DeleteUser{
|
if err := s.Store.DeleteUser(ctx, &store.DeleteUser{
|
||||||
ID: userID,
|
ID: userID,
|
||||||
@@ -371,6 +374,9 @@ func (s *APIV1Service) UpdateUser(c echo.Context) error {
|
|||||||
if request.RowStatus != nil {
|
if request.RowStatus != nil {
|
||||||
rowStatus := store.RowStatus(request.RowStatus.String())
|
rowStatus := store.RowStatus(request.RowStatus.String())
|
||||||
userUpdate.RowStatus = &rowStatus
|
userUpdate.RowStatus = &rowStatus
|
||||||
|
if rowStatus == store.Archived && currentUserID == userID {
|
||||||
|
return echo.NewHTTPError(http.StatusBadRequest, "Cannot archive current user")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if request.Username != nil {
|
if request.Username != nil {
|
||||||
if !usernameMatcher.MatchString(strings.ToLower(*request.Username)) {
|
if !usernameMatcher.MatchString(strings.ToLower(*request.Username)) {
|
||||||
|
Reference in New Issue
Block a user