From 874ac9180bf36694bb18d61e806d56020733dba7 Mon Sep 17 00:00:00 2001 From: J Guerreiro Date: Tue, 8 Mar 2022 13:10:16 +0000 Subject: [PATCH] Service Accounts: Add enabled/disabled status to list (#46259) * ServiceAccounts: improve where condition * ServiceAccounts: Add Enabled/Disabled status to list --- .../serviceaccounts/database/database.go | 10 +++++----- pkg/services/serviceaccounts/models.go | 1 + .../serviceaccounts/ServiceAccountsListPage.tsx | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/pkg/services/serviceaccounts/database/database.go b/pkg/services/serviceaccounts/database/database.go index 2245a000458..623157b3b06 100644 --- a/pkg/services/serviceaccounts/database/database.go +++ b/pkg/services/serviceaccounts/database/database.go @@ -299,8 +299,6 @@ func (s *ServiceAccountsStoreImpl) UpdateServiceAccount(ctx context.Context, } func (s *ServiceAccountsStoreImpl) SearchOrgServiceAccounts(ctx context.Context, query *models.SearchOrgUsersQuery) ([]*serviceaccounts.ServiceAccountDTO, error) { - query.IsServiceAccount = true - serviceAccounts := make([]*serviceaccounts.ServiceAccountDTO, 0) err := s.sqlStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error { @@ -313,9 +311,10 @@ func (s *ServiceAccountsStoreImpl) SearchOrgServiceAccounts(ctx context.Context, whereConditions = append(whereConditions, "org_user.org_id = ?") whereParams = append(whereParams, query.OrgID) - // TODO: add to chore, for cleaning up after we have created - // service accounts table in the modelling - whereConditions = append(whereConditions, fmt.Sprintf("%s.is_service_account = %t", s.sqlStore.Dialect.Quote("user"), query.IsServiceAccount)) + whereConditions = append(whereConditions, + fmt.Sprintf("%s.is_service_account = %s", + s.sqlStore.Dialect.Quote("user"), + s.sqlStore.Dialect.BooleanStr(true))) if s.sqlStore.Cfg.IsFeatureToggleEnabled(featuremgmt.FlagAccesscontrol) { acFilter, err := accesscontrol.Filter(ctx, "org_user.user_id", "serviceaccounts", "serviceaccounts:read", query.User) @@ -348,6 +347,7 @@ func (s *ServiceAccountsStoreImpl) SearchOrgServiceAccounts(ctx context.Context, "user.name", "user.login", "user.last_seen_at", + "user.is_disabled", ) sess.Asc("user.email", "user.login") if err := sess.Find(&serviceAccounts); err != nil { diff --git a/pkg/services/serviceaccounts/models.go b/pkg/services/serviceaccounts/models.go index 2f6a34099dd..dc4d33db3ac 100644 --- a/pkg/services/serviceaccounts/models.go +++ b/pkg/services/serviceaccounts/models.go @@ -34,6 +34,7 @@ type ServiceAccountDTO struct { Name string `json:"name" xorm:"name"` Login string `json:"login" xorm:"login"` OrgId int64 `json:"orgId" xorm:"org_id"` + IsDisabled bool `json:"isDisabled" xorm:"is_disabled"` Role string `json:"role" xorm:"role"` Tokens int64 `json:"tokens"` AvatarUrl string `json:"avatarUrl"` diff --git a/public/app/features/serviceaccounts/ServiceAccountsListPage.tsx b/public/app/features/serviceaccounts/ServiceAccountsListPage.tsx index 75b8bc9894b..62e18ceaa91 100644 --- a/public/app/features/serviceaccounts/ServiceAccountsListPage.tsx +++ b/public/app/features/serviceaccounts/ServiceAccountsListPage.tsx @@ -113,6 +113,7 @@ const ServiceAccountsListPage = ({ Display name ID Roles + Status Tokens @@ -174,6 +175,9 @@ type ServiceAccountListItemProps = { const getServiceAccountsAriaLabel = (name: string) => { return `Edit service account's ${name} details`; }; +const getServiceAccountsEnabledStatus = (disabled: boolean) => { + return disabled ? 'Disabled' : 'Enabled'; +}; const ServiceAccountListItem = memo( ({ serviceAccount, onRoleChange, roleOptions, builtInRoles, onSetToRemove }: ServiceAccountListItemProps) => { @@ -237,7 +241,17 @@ const ServiceAccountListItem = memo( + {getServiceAccountsEnabledStatus(serviceAccount.isDisabled)} + + + +