Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding new user changes to server #1021

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/user/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func UpdateUser(c *gin.Context) {
u.SetFavorites(input.GetFavorites())
}

if input.Dashboards != nil {
// update dashboards if set
u.SetDashboards(input.GetDashboards())
}

// send API call to update the user
u, err = database.FromContext(c).UpdateUser(ctx, u)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions api/user/update_current.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ func UpdateCurrentUser(c *gin.Context) {
u.SetFavorites(input.GetFavorites())
}

// update user fields if provided
if input.Dashboards != nil {
// update dashboards if set
u.SetDashboards(input.GetDashboards())
}

// send API call to update the user
u, err = database.FromContext(c).UpdateUser(ctx, u)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions database/user/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func TestUser_Engine_CreateUser(t *testing.T) {

// ensure the mock expects the query
_mock.ExpectQuery(`INSERT INTO "users"
("name","refresh_token","token","hash","favorites","active","admin","id")
("name","refresh_token","token","hash","favorites","active","admin","dashboards","id")
VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING "id"`).
WithArgs("foo", AnyArgument{}, AnyArgument{}, AnyArgument{}, nil, false, false, 1).
WithArgs("foo", AnyArgument{}, AnyArgument{}, AnyArgument{}, nil, false, false, nil, 1).
WillReturnRows(_rows)

_sqlite := testSqlite(t)
Expand Down
4 changes: 2 additions & 2 deletions database/user/get_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestUser_Engine_GetUserForName(t *testing.T) {

// create expected result in mock
_rows := sqlmock.NewRows(
[]string{"id", "name", "refresh_token", "token", "hash", "favorites", "active", "admin"}).
AddRow(1, "foo", "", "bar", "baz", "{}", false, false)
[]string{"id", "name", "refresh_token", "token", "hash", "favorites", "active", "admin", "dashboards"}).
AddRow(1, "foo", "", "bar", "baz", "{}", false, false, nil)

// ensure the mock expects the query
_mock.ExpectQuery(`SELECT * FROM "users" WHERE name = $1 LIMIT 1`).WithArgs("foo").WillReturnRows(_rows)
Expand Down
4 changes: 2 additions & 2 deletions database/user/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestUser_Engine_GetUser(t *testing.T) {

// create expected result in mock
_rows := sqlmock.NewRows(
[]string{"id", "name", "refresh_token", "token", "hash", "favorites", "active", "admin"}).
AddRow(1, "foo", "", "bar", "baz", "{}", false, false)
[]string{"id", "name", "refresh_token", "token", "hash", "favorites", "active", "admin", "dashboards"}).
AddRow(1, "foo", "", "bar", "baz", "{}", false, false, nil)

// ensure the mock expects the query
_mock.ExpectQuery(`SELECT * FROM "users" WHERE id = $1 LIMIT 1`).WithArgs(1).WillReturnRows(_rows)
Expand Down
6 changes: 3 additions & 3 deletions database/user/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func TestUser_Engine_ListUsers(t *testing.T) {

// create expected result in mock
_rows = sqlmock.NewRows(
[]string{"id", "name", "refresh_token", "token", "hash", "favorites", "active", "admin"}).
AddRow(1, "foo", "", "bar", "baz", "{}", false, false).
AddRow(2, "baz", "", "bar", "foo", "{}", false, false)
[]string{"id", "name", "refresh_token", "token", "hash", "favorites", "active", "admin", "dashboards"}).
AddRow(1, "foo", "", "bar", "baz", "{}", false, false, nil).
AddRow(2, "baz", "", "bar", "foo", "{}", false, false, nil)

// ensure the mock expects the query
_mock.ExpectQuery(`SELECT * FROM "users"`).WillReturnRows(_rows)
Expand Down
2 changes: 2 additions & 0 deletions database/user/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ users (
favorites VARCHAR(5000),
active BOOLEAN,
admin BOOLEAN,
dashboards VARCHAR(5000),
UNIQUE(name)
);
`
Expand All @@ -39,6 +40,7 @@ users (
favorites TEXT,
active BOOLEAN,
admin BOOLEAN,
dashboards TEXT,
UNIQUE(name)
);
`
Expand Down
6 changes: 3 additions & 3 deletions database/user/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func TestUser_Engine_UpdateUser(t *testing.T) {

// ensure the mock expects the query
_mock.ExpectExec(`UPDATE "users"
SET "name"=$1,"refresh_token"=$2,"token"=$3,"hash"=$4,"favorites"=$5,"active"=$6,"admin"=$7
WHERE "id" = $8`).
WithArgs("foo", AnyArgument{}, AnyArgument{}, AnyArgument{}, nil, false, false, 1).
SET "name"=$1,"refresh_token"=$2,"token"=$3,"hash"=$4,"favorites"=$5,"active"=$6,"admin"=$7,"dashboards"=$8
WHERE "id" = $9`).
WithArgs("foo", AnyArgument{}, AnyArgument{}, AnyArgument{}, nil, false, false, nil, 1).
WillReturnResult(sqlmock.NewResult(1, 1))

_sqlite := testSqlite(t)
Expand Down
9 changes: 6 additions & 3 deletions mock/server/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const (
"token": null,
"favorites": ["github/octocat"],
"active": true,
"admin": false
"admin": false,
"dashboards": []
}`

// UsersResp represents a JSON return for one to many users.
Expand All @@ -33,15 +34,17 @@ const (
"token": null,
"favorites": ["github/octocat"],
"active": true,
"admin": false
"admin": false,
"dashboards": []
},
{
"id": 1,
"name": "OctoKitty",
"token": null,
"favorites": ["github/octocat"],
"active": true,
"admin": false
"admin": false,
"dashboards": []
}
]`
)
Expand Down
Loading