feat(dataservices): unify access methods and abstract away redundant code [EE-5628] (#9115)
This commit is contained in:
@@ -79,7 +79,7 @@ func (handler *Handler) userCreateAccessToken(w http.ResponseWriter, r *http.Req
|
||||
return httperror.Forbidden("Permission denied to create user access token", httperrors.ErrUnauthorized)
|
||||
}
|
||||
|
||||
user, err := handler.DataStore.User().User(portainer.UserID(userID))
|
||||
user, err := handler.DataStore.User().Read(portainer.UserID(userID))
|
||||
if err != nil {
|
||||
return httperror.BadRequest("Unable to find a user", err)
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func (handler *Handler) userDelete(w http.ResponseWriter, r *http.Request) *http
|
||||
return httperror.Forbidden("Cannot remove your own user account. Contact another administrator", errAdminCannotRemoveSelf)
|
||||
}
|
||||
|
||||
user, err := handler.DataStore.User().User(portainer.UserID(userID))
|
||||
user, err := handler.DataStore.User().Read(portainer.UserID(userID))
|
||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
||||
return httperror.NotFound("Unable to find a user with the specified identifier inside the database", err)
|
||||
} else if err != nil {
|
||||
@@ -64,7 +64,7 @@ func (handler *Handler) deleteAdminUser(w http.ResponseWriter, user *portainer.U
|
||||
return handler.deleteUser(w, user)
|
||||
}
|
||||
|
||||
users, err := handler.DataStore.User().Users()
|
||||
users, err := handler.DataStore.User().ReadAll()
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to retrieve users from the database", err)
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func (handler *Handler) deleteAdminUser(w http.ResponseWriter, user *portainer.U
|
||||
}
|
||||
|
||||
func (handler *Handler) deleteUser(w http.ResponseWriter, user *portainer.User) *httperror.HandlerError {
|
||||
err := handler.DataStore.User().DeleteUser(user.ID)
|
||||
err := handler.DataStore.User().Delete(user.ID)
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to remove user from the database", err)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func (handler *Handler) userGetAccessTokens(w http.ResponseWriter, r *http.Reque
|
||||
return httperror.Forbidden("Permission denied to get user access tokens", httperrors.ErrUnauthorized)
|
||||
}
|
||||
|
||||
_, err = handler.DataStore.User().User(portainer.UserID(userID))
|
||||
_, err = handler.DataStore.User().Read(portainer.UserID(userID))
|
||||
if err != nil {
|
||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
||||
return httperror.NotFound("Unable to find a user with the specified identifier inside the database", err)
|
||||
|
||||
@@ -42,7 +42,7 @@ func (handler *Handler) userInspect(w http.ResponseWriter, r *http.Request) *htt
|
||||
return httperror.Forbidden("Permission denied inspect user", errors.ErrResourceAccessDenied)
|
||||
}
|
||||
|
||||
user, err := handler.DataStore.User().User(portainer.UserID(userID))
|
||||
user, err := handler.DataStore.User().Read(portainer.UserID(userID))
|
||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
||||
return httperror.NotFound("Unable to find a user with the specified identifier inside the database", err)
|
||||
} else if err != nil {
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
// @failure 500 "Server error"
|
||||
// @router /users [get]
|
||||
func (handler *Handler) userList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
||||
users, err := handler.DataStore.User().Users()
|
||||
users, err := handler.DataStore.User().ReadAll()
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to retrieve users from the database", err)
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func (handler *Handler) userList(w http.ResponseWriter, r *http.Request) *httper
|
||||
return httperror.InternalServerError("Unable to retrieve endpoint from the database", err)
|
||||
}
|
||||
|
||||
endpointGroup, err := handler.DataStore.EndpointGroup().EndpointGroup(endpoint.GroupID)
|
||||
endpointGroup, err := handler.DataStore.EndpointGroup().Read(endpoint.GroupID)
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to retrieve environment groups from the database", err)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func (handler *Handler) userRemoveAccessToken(w http.ResponseWriter, r *http.Req
|
||||
return httperror.Forbidden("Permission denied to get user access tokens", httperrors.ErrUnauthorized)
|
||||
}
|
||||
|
||||
_, err = handler.DataStore.User().User(portainer.UserID(userID))
|
||||
_, err = handler.DataStore.User().Read(portainer.UserID(userID))
|
||||
if err != nil {
|
||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
||||
return httperror.NotFound("Unable to find a user with the specified identifier inside the database", err)
|
||||
|
||||
@@ -87,7 +87,7 @@ func (handler *Handler) userUpdate(w http.ResponseWriter, r *http.Request) *http
|
||||
return httperror.Forbidden("Permission denied to update user to administrator role", httperrors.ErrResourceAccessDenied)
|
||||
}
|
||||
|
||||
user, err := handler.DataStore.User().User(portainer.UserID(userID))
|
||||
user, err := handler.DataStore.User().Read(portainer.UserID(userID))
|
||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
||||
return httperror.NotFound("Unable to find a user with the specified identifier inside the database", err)
|
||||
} else if err != nil {
|
||||
@@ -125,7 +125,7 @@ func (handler *Handler) userUpdate(w http.ResponseWriter, r *http.Request) *http
|
||||
user.TokenIssueAt = time.Now().Unix()
|
||||
}
|
||||
|
||||
err = handler.DataStore.User().UpdateUser(user.ID, user)
|
||||
err = handler.DataStore.User().Update(user.ID, user)
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to persist user changes inside the database", err)
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func (handler *Handler) userUpdatePassword(w http.ResponseWriter, r *http.Reques
|
||||
return httperror.BadRequest("Invalid request payload", err)
|
||||
}
|
||||
|
||||
user, err := handler.DataStore.User().User(portainer.UserID(userID))
|
||||
user, err := handler.DataStore.User().Read(portainer.UserID(userID))
|
||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
||||
return httperror.NotFound("Unable to find a user with the specified identifier inside the database", err)
|
||||
} else if err != nil {
|
||||
@@ -97,7 +97,7 @@ func (handler *Handler) userUpdatePassword(w http.ResponseWriter, r *http.Reques
|
||||
|
||||
user.TokenIssueAt = time.Now().Unix()
|
||||
|
||||
err = handler.DataStore.User().UpdateUser(user.ID, user)
|
||||
err = handler.DataStore.User().Update(user.ID, user)
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to persist user changes inside the database", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user