mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: add github.com user id association (#14045)
* chore: add github.com user id association This will eventually be used to show an indicator in the UI to star the repository if you've been using Coder for a while and have not starred the repo. If you have, we'll never show a thing! * gen * Fix model query * Fix linting * Ignore auditing github.com user id * Add test * Fix gh url var name * Update migration * Update coderd/database/dbauthz/dbauthz.go Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com> * Fix updating to when the token changes * Fix migration --------- Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>
This commit is contained in:
co-authored by
Steven Masley
parent
4d4d27c509
commit
6e36082b0f
@@ -3260,6 +3260,23 @@ func (q *querier) UpdateUserDeletedByID(ctx context.Context, id uuid.UUID) error
|
||||
return deleteQ(q.log, q.auth, q.db.GetUserByID, q.db.UpdateUserDeletedByID)(ctx, id)
|
||||
}
|
||||
|
||||
func (q *querier) UpdateUserGithubComUserID(ctx context.Context, arg database.UpdateUserGithubComUserIDParams) error {
|
||||
user, err := q.db.GetUserByID(ctx, arg.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = q.authorizeContext(ctx, policy.ActionUpdatePersonal, user)
|
||||
if err != nil {
|
||||
// System user can also update
|
||||
err = q.authorizeContext(ctx, policy.ActionUpdate, user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return q.db.UpdateUserGithubComUserID(ctx, arg)
|
||||
}
|
||||
|
||||
func (q *querier) UpdateUserHashedPassword(ctx context.Context, arg database.UpdateUserHashedPasswordParams) error {
|
||||
user, err := q.db.GetUserByID(ctx, arg.ID)
|
||||
if err != nil {
|
||||
|
||||
@@ -1105,6 +1105,12 @@ func (s *MethodTestSuite) TestUser() {
|
||||
u := dbgen.User(s.T(), db, database.User{})
|
||||
check.Args(u.ID).Asserts(u, policy.ActionDelete).Returns()
|
||||
}))
|
||||
s.Run("UpdateUserGithubComUserID", s.Subtest(func(db database.Store, check *expects) {
|
||||
u := dbgen.User(s.T(), db, database.User{})
|
||||
check.Args(database.UpdateUserGithubComUserIDParams{
|
||||
ID: u.ID,
|
||||
}).Asserts(u, policy.ActionUpdatePersonal)
|
||||
}))
|
||||
s.Run("UpdateUserHashedPassword", s.Subtest(func(db database.Store, check *expects) {
|
||||
u := dbgen.User(s.T(), db, database.User{})
|
||||
check.Args(database.UpdateUserHashedPasswordParams{
|
||||
|
||||
Reference in New Issue
Block a user