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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user