mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
UsersTable: Display Disabled flag in Organizations' Users table (#53656)
* Add disabled column to Org's Users table * fix typo * Change column order * Add test for testing whether GetOrgUsers populates the DTO correctly * Remove type assertion
This commit is contained in:
parent
4069fe1c39
commit
1c0ab501aa
@ -100,4 +100,5 @@ type OrgUserDTO struct {
|
||||
Created time.Time `json:"-"`
|
||||
LastSeenAtAge string `json:"lastSeenAtAge"`
|
||||
AccessControl map[string]bool `json:"accessControl,omitempty"`
|
||||
IsDisabled bool `json:"isDisabled"`
|
||||
}
|
||||
|
@ -152,6 +152,7 @@ func (ss *SQLStore) GetOrgUsers(ctx context.Context, query *models.GetOrgUsersQu
|
||||
"user.last_seen_at",
|
||||
"user.created",
|
||||
"user.updated",
|
||||
"user.is_disabled",
|
||||
)
|
||||
sess.Asc("user.email", "user.login")
|
||||
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -83,6 +84,60 @@ func TestSQLStore_GetOrgUsers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLStore_GetOrgUsers_PopulatesCorrectly(t *testing.T) {
|
||||
// The millisecond part is not stored in the DB
|
||||
constNow := time.Now().UTC().Truncate(time.Second)
|
||||
defer mockTimeNow(constNow)()
|
||||
|
||||
store := InitTestDB(t, InitTestDBOpt{})
|
||||
_, err := store.CreateUser(context.Background(), user.CreateUserCommand{
|
||||
Login: "Admin",
|
||||
Email: "admin@localhost",
|
||||
OrgID: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
newUser, err := store.CreateUser(context.Background(), user.CreateUserCommand{
|
||||
Login: "Viewer",
|
||||
Email: "viewer@localhost",
|
||||
OrgID: 1,
|
||||
IsDisabled: true,
|
||||
Name: "Viewer Localhost",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
err = store.AddOrgUser(context.Background(), &models.AddOrgUserCommand{
|
||||
Role: "Viewer",
|
||||
OrgId: 1,
|
||||
UserId: newUser.ID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
query := &models.GetOrgUsersQuery{
|
||||
OrgId: 1,
|
||||
UserID: newUser.ID,
|
||||
User: &user.SignedInUser{
|
||||
OrgID: 1,
|
||||
Permissions: map[int64]map[string][]string{1: {ac.ActionOrgUsersRead: {ac.ScopeUsersAll}}},
|
||||
},
|
||||
}
|
||||
err = store.GetOrgUsers(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, query.Result, 1)
|
||||
|
||||
actual := query.Result[0]
|
||||
assert.Equal(t, int64(1), actual.OrgId)
|
||||
assert.Equal(t, newUser.ID, actual.UserId)
|
||||
assert.Equal(t, "viewer@localhost", actual.Email)
|
||||
assert.Equal(t, "Viewer Localhost", actual.Name)
|
||||
assert.Equal(t, "Viewer", actual.Login)
|
||||
assert.Equal(t, "Viewer", actual.Role)
|
||||
assert.Equal(t, constNow.AddDate(-10, 0, 0), actual.LastSeenAt)
|
||||
assert.Equal(t, constNow, actual.Created)
|
||||
assert.Equal(t, constNow, actual.Updated)
|
||||
assert.Equal(t, true, actual.IsDisabled)
|
||||
}
|
||||
|
||||
type searchOrgUsersTestCase struct {
|
||||
desc string
|
||||
query *models.SearchOrgUsersQuery
|
||||
@ -279,3 +334,14 @@ func hasWildcardScope(user *user.SignedInUser, action string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func mockTimeNow(constTime time.Time) func() {
|
||||
timeNow = func() time.Time {
|
||||
return constTime.Truncate(time.Second)
|
||||
}
|
||||
return resetTimeNow
|
||||
}
|
||||
|
||||
func resetTimeNow() {
|
||||
timeNow = time.Now
|
||||
}
|
||||
|
@ -40,6 +40,14 @@ describe('Render', () => {
|
||||
expect(screen.getByText(user.name)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('should render disabled flag when any of the Users are disabled', () => {
|
||||
const usersData = getMockUsers(5);
|
||||
usersData[0].isDisabled = true;
|
||||
setup({ users: usersData });
|
||||
|
||||
expect(screen.getByText('Disabled')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Remove modal', () => {
|
||||
|
@ -58,6 +58,7 @@ const UsersTable: FC<Props> = (props) => {
|
||||
<th>Seen</th>
|
||||
<th>Role</th>
|
||||
<th style={{ width: '34px' }} />
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -108,8 +109,12 @@ const UsersTable: FC<Props> = (props) => {
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td className="width-1 text-center">
|
||||
{user.isDisabled && <span className="label label-tag label-tag--gray">Disabled</span>}
|
||||
</td>
|
||||
|
||||
{contextSrv.hasPermissionInMetadata(AccessControlAction.OrgUsersRemove, user) && (
|
||||
<td>
|
||||
<td className="text-right">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
|
@ -14,6 +14,7 @@ export const getMockUsers = (amount: number) => {
|
||||
orgId: 1,
|
||||
role: 'Admin',
|
||||
userId: i,
|
||||
isDisabled: false,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ export interface OrgUser extends WithAccessControlMetadata {
|
||||
orgId: number;
|
||||
role: OrgRole;
|
||||
userId: number;
|
||||
isDisabled: boolean;
|
||||
}
|
||||
|
||||
export interface User {
|
||||
|
Loading…
Reference in New Issue
Block a user