Service accounts: RBAC the service account UI (#47788)

* WIP

* fix: bug for saving name did not remove edit

* refactor: better error msg

* Display the column Roles even when user can't see the role picker

* Remove spaces when building the search query request

* Disable Edit button and fix token addition and deletion

* Fix the error message text

Co-authored-by: Vardan Torosyan <vardants@gmail.com>
This commit is contained in:
Eric Leijonmarck
2022-04-14 23:06:08 +01:00
committed by GitHub
parent 2a178bd73c
commit b43e9b50b4
7 changed files with 48 additions and 22 deletions

View File

@@ -93,7 +93,7 @@ func (api *ServiceAccountsAPI) CreateServiceAccount(c *models.ReqContext) respon
serviceAccount, err := api.store.CreateServiceAccount(c.Req.Context(), c.OrgId, cmd.Name)
switch {
case errors.Is(err, &database.ErrSAInvalidName{}):
return response.Error(http.StatusBadRequest, "Invalid service account name", err)
return response.Error(http.StatusBadRequest, "Failed due to %s", err)
case err != nil:
return response.Error(http.StatusInternalServerError, "Failed to create service account", err)
}

View File

@@ -17,14 +17,14 @@ func (e *ErrSAInvalidName) Unwrap() error {
return models.ErrUserAlreadyExists
}
type ErrMisingSAToken struct {
type ErrMissingSAToken struct {
}
func (e *ErrMisingSAToken) Error() string {
func (e *ErrMissingSAToken) Error() string {
return "service account token not found"
}
func (e *ErrMisingSAToken) Unwrap() error {
func (e *ErrMissingSAToken) Unwrap() error {
return models.ErrApiKeyNotFound
}
@@ -44,7 +44,7 @@ type ErrDuplicateSAToken struct {
}
func (e *ErrDuplicateSAToken) Error() string {
return fmt.Sprintf("service account token %s already exists", e.name)
return fmt.Sprintf("service account token %s already exists in the organization", e.name)
}
func (e *ErrDuplicateSAToken) Unwrap() error {

View File

@@ -57,7 +57,7 @@ func (s *ServiceAccountsStoreImpl) DeleteServiceAccountToken(ctx context.Context
if err != nil {
return err
} else if n == 0 {
return &ErrMisingSAToken{}
return &ErrMissingSAToken{}
}
return nil
})