mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Service Accounts: Add enabled/disabled status to list (#46259)
* ServiceAccounts: improve where condition * ServiceAccounts: Add Enabled/Disabled status to list
This commit is contained in:
parent
1f3f4ebe21
commit
874ac9180b
@ -299,8 +299,6 @@ func (s *ServiceAccountsStoreImpl) UpdateServiceAccount(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServiceAccountsStoreImpl) SearchOrgServiceAccounts(ctx context.Context, query *models.SearchOrgUsersQuery) ([]*serviceaccounts.ServiceAccountDTO, error) {
|
func (s *ServiceAccountsStoreImpl) SearchOrgServiceAccounts(ctx context.Context, query *models.SearchOrgUsersQuery) ([]*serviceaccounts.ServiceAccountDTO, error) {
|
||||||
query.IsServiceAccount = true
|
|
||||||
|
|
||||||
serviceAccounts := make([]*serviceaccounts.ServiceAccountDTO, 0)
|
serviceAccounts := make([]*serviceaccounts.ServiceAccountDTO, 0)
|
||||||
|
|
||||||
err := s.sqlStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
|
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 = ?")
|
whereConditions = append(whereConditions, "org_user.org_id = ?")
|
||||||
whereParams = append(whereParams, query.OrgID)
|
whereParams = append(whereParams, query.OrgID)
|
||||||
|
|
||||||
// TODO: add to chore, for cleaning up after we have created
|
whereConditions = append(whereConditions,
|
||||||
// service accounts table in the modelling
|
fmt.Sprintf("%s.is_service_account = %s",
|
||||||
whereConditions = append(whereConditions, fmt.Sprintf("%s.is_service_account = %t", s.sqlStore.Dialect.Quote("user"), query.IsServiceAccount))
|
s.sqlStore.Dialect.Quote("user"),
|
||||||
|
s.sqlStore.Dialect.BooleanStr(true)))
|
||||||
|
|
||||||
if s.sqlStore.Cfg.IsFeatureToggleEnabled(featuremgmt.FlagAccesscontrol) {
|
if s.sqlStore.Cfg.IsFeatureToggleEnabled(featuremgmt.FlagAccesscontrol) {
|
||||||
acFilter, err := accesscontrol.Filter(ctx, "org_user.user_id", "serviceaccounts", "serviceaccounts:read", query.User)
|
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.name",
|
||||||
"user.login",
|
"user.login",
|
||||||
"user.last_seen_at",
|
"user.last_seen_at",
|
||||||
|
"user.is_disabled",
|
||||||
)
|
)
|
||||||
sess.Asc("user.email", "user.login")
|
sess.Asc("user.email", "user.login")
|
||||||
if err := sess.Find(&serviceAccounts); err != nil {
|
if err := sess.Find(&serviceAccounts); err != nil {
|
||||||
|
@ -34,6 +34,7 @@ type ServiceAccountDTO struct {
|
|||||||
Name string `json:"name" xorm:"name"`
|
Name string `json:"name" xorm:"name"`
|
||||||
Login string `json:"login" xorm:"login"`
|
Login string `json:"login" xorm:"login"`
|
||||||
OrgId int64 `json:"orgId" xorm:"org_id"`
|
OrgId int64 `json:"orgId" xorm:"org_id"`
|
||||||
|
IsDisabled bool `json:"isDisabled" xorm:"is_disabled"`
|
||||||
Role string `json:"role" xorm:"role"`
|
Role string `json:"role" xorm:"role"`
|
||||||
Tokens int64 `json:"tokens"`
|
Tokens int64 `json:"tokens"`
|
||||||
AvatarUrl string `json:"avatarUrl"`
|
AvatarUrl string `json:"avatarUrl"`
|
||||||
|
@ -113,6 +113,7 @@ const ServiceAccountsListPage = ({
|
|||||||
<th>Display name</th>
|
<th>Display name</th>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th>Roles</th>
|
<th>Roles</th>
|
||||||
|
<th>Status</th>
|
||||||
<th>Tokens</th>
|
<th>Tokens</th>
|
||||||
<th style={{ width: '34px' }} />
|
<th style={{ width: '34px' }} />
|
||||||
</tr>
|
</tr>
|
||||||
@ -174,6 +175,9 @@ type ServiceAccountListItemProps = {
|
|||||||
const getServiceAccountsAriaLabel = (name: string) => {
|
const getServiceAccountsAriaLabel = (name: string) => {
|
||||||
return `Edit service account's ${name} details`;
|
return `Edit service account's ${name} details`;
|
||||||
};
|
};
|
||||||
|
const getServiceAccountsEnabledStatus = (disabled: boolean) => {
|
||||||
|
return disabled ? 'Disabled' : 'Enabled';
|
||||||
|
};
|
||||||
|
|
||||||
const ServiceAccountListItem = memo(
|
const ServiceAccountListItem = memo(
|
||||||
({ serviceAccount, onRoleChange, roleOptions, builtInRoles, onSetToRemove }: ServiceAccountListItemProps) => {
|
({ serviceAccount, onRoleChange, roleOptions, builtInRoles, onSetToRemove }: ServiceAccountListItemProps) => {
|
||||||
@ -237,7 +241,17 @@ const ServiceAccountListItem = memo(
|
|||||||
<a
|
<a
|
||||||
className="ellipsis"
|
className="ellipsis"
|
||||||
href={editUrl}
|
href={editUrl}
|
||||||
title="tokens"
|
title={getServiceAccountsEnabledStatus(serviceAccount.isDisabled)}
|
||||||
|
aria-label={getServiceAccountsAriaLabel(serviceAccount.name)}
|
||||||
|
>
|
||||||
|
{getServiceAccountsEnabledStatus(serviceAccount.isDisabled)}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td className="link-td max-width-10">
|
||||||
|
<a
|
||||||
|
className="ellipsis"
|
||||||
|
href={editUrl}
|
||||||
|
title="Tokens"
|
||||||
aria-label={getServiceAccountsAriaLabel(serviceAccount.name)}
|
aria-label={getServiceAccountsAriaLabel(serviceAccount.name)}
|
||||||
>
|
>
|
||||||
<span>
|
<span>
|
||||||
|
Loading…
Reference in New Issue
Block a user