types: rename user UserName field to Name
This commit is contained in:
parent
1e1152cb1a
commit
1820e7c477
|
@ -275,7 +275,7 @@ func (s *CommandHandler) CreateUser(ctx context.Context, req *CreateUserRequest)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if u != nil {
|
if u != nil {
|
||||||
return util.NewErrBadRequest(errors.Errorf("user with name %q already exists", u.UserName))
|
return util.NewErrBadRequest(errors.Errorf("user with name %q already exists", u.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.CreateUserLARequest != nil {
|
if req.CreateUserLARequest != nil {
|
||||||
|
@ -302,7 +302,7 @@ func (s *CommandHandler) CreateUser(ctx context.Context, req *CreateUserRequest)
|
||||||
|
|
||||||
user := &types.User{
|
user := &types.User{
|
||||||
ID: uuid.NewV4().String(),
|
ID: uuid.NewV4().String(),
|
||||||
UserName: req.UserName,
|
Name: req.UserName,
|
||||||
}
|
}
|
||||||
if req.CreateUserLARequest != nil {
|
if req.CreateUserLARequest != nil {
|
||||||
if user.LinkedAccounts == nil {
|
if user.LinkedAccounts == nil {
|
||||||
|
@ -599,7 +599,7 @@ func (s *CommandHandler) UpdateUserLA(ctx context.Context, req *UpdateUserLARequ
|
||||||
|
|
||||||
la, ok := user.LinkedAccounts[req.LinkedAccountID]
|
la, ok := user.LinkedAccounts[req.LinkedAccountID]
|
||||||
if !ok {
|
if !ok {
|
||||||
return util.NewErrBadRequest(errors.Errorf("linked account id %q for user %q doesn't exist", req.LinkedAccountID, user.UserName))
|
return util.NewErrBadRequest(errors.Errorf("linked account id %q for user %q doesn't exist", req.LinkedAccountID, user.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
rs, err = s.readDB.GetRemoteSource(tx, la.RemoteSourceID)
|
rs, err = s.readDB.GetRemoteSource(tx, la.RemoteSourceID)
|
||||||
|
|
|
@ -394,7 +394,7 @@ func TestProjectGroupsAndProjects(t *testing.T) {
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
|
|
||||||
t.Run("create a project in user root project group", func(t *testing.T) {
|
t.Run("create a project in user root project group", func(t *testing.T) {
|
||||||
_, err := cs.ch.CreateProject(ctx, &types.Project{Name: "project01", Parent: types.Parent{Type: types.ConfigTypeProjectGroup, ID: path.Join("user", user.UserName)}})
|
_, err := cs.ch.CreateProject(ctx, &types.Project{Name: "project01", Parent: types.Parent{Type: types.ConfigTypeProjectGroup, ID: path.Join("user", user.Name)}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected err: %v", err)
|
t.Fatalf("unexpected err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -406,7 +406,7 @@ func TestProjectGroupsAndProjects(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.Run("create a projectgroup in user root project group", func(t *testing.T) {
|
t.Run("create a projectgroup in user root project group", func(t *testing.T) {
|
||||||
_, err := cs.ch.CreateProjectGroup(ctx, &types.ProjectGroup{Name: "projectgroup01", Parent: types.Parent{Type: types.ConfigTypeProjectGroup, ID: path.Join("user", user.UserName)}})
|
_, err := cs.ch.CreateProjectGroup(ctx, &types.ProjectGroup{Name: "projectgroup01", Parent: types.Parent{Type: types.ConfigTypeProjectGroup, ID: path.Join("user", user.Name)}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected err: %v", err)
|
t.Fatalf("unexpected err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -418,7 +418,7 @@ func TestProjectGroupsAndProjects(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.Run("create a project in user non root project group with same name as a root project", func(t *testing.T) {
|
t.Run("create a project in user non root project group with same name as a root project", func(t *testing.T) {
|
||||||
_, err := cs.ch.CreateProject(ctx, &types.Project{Name: "project01", Parent: types.Parent{Type: types.ConfigTypeProjectGroup, ID: path.Join("user", user.UserName, "projectgroup01")}})
|
_, err := cs.ch.CreateProject(ctx, &types.Project{Name: "project01", Parent: types.Parent{Type: types.ConfigTypeProjectGroup, ID: path.Join("user", user.Name, "projectgroup01")}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected err: %+#v", err)
|
t.Fatalf("unexpected err: %+#v", err)
|
||||||
}
|
}
|
||||||
|
@ -432,8 +432,8 @@ func TestProjectGroupsAndProjects(t *testing.T) {
|
||||||
|
|
||||||
t.Run("create duplicated project in user root project group", func(t *testing.T) {
|
t.Run("create duplicated project in user root project group", func(t *testing.T) {
|
||||||
projectName := "project01"
|
projectName := "project01"
|
||||||
expectedErr := fmt.Sprintf("project with name %q, path %q already exists", projectName, path.Join("user", user.UserName, projectName))
|
expectedErr := fmt.Sprintf("project with name %q, path %q already exists", projectName, path.Join("user", user.Name, projectName))
|
||||||
_, err := cs.ch.CreateProject(ctx, &types.Project{Name: projectName, Parent: types.Parent{Type: types.ConfigTypeProjectGroup, ID: path.Join("user", user.UserName)}})
|
_, err := cs.ch.CreateProject(ctx, &types.Project{Name: projectName, Parent: types.Parent{Type: types.ConfigTypeProjectGroup, ID: path.Join("user", user.Name)}})
|
||||||
if err.Error() != expectedErr {
|
if err.Error() != expectedErr {
|
||||||
t.Fatalf("expected err %v, got err: %v", expectedErr, err)
|
t.Fatalf("expected err %v, got err: %v", expectedErr, err)
|
||||||
}
|
}
|
||||||
|
@ -449,8 +449,8 @@ func TestProjectGroupsAndProjects(t *testing.T) {
|
||||||
|
|
||||||
t.Run("create duplicated project in user non root project group", func(t *testing.T) {
|
t.Run("create duplicated project in user non root project group", func(t *testing.T) {
|
||||||
projectName := "project01"
|
projectName := "project01"
|
||||||
expectedErr := fmt.Sprintf("project with name %q, path %q already exists", projectName, path.Join("user", user.UserName, "projectgroup01", projectName))
|
expectedErr := fmt.Sprintf("project with name %q, path %q already exists", projectName, path.Join("user", user.Name, "projectgroup01", projectName))
|
||||||
_, err := cs.ch.CreateProject(ctx, &types.Project{Name: projectName, Parent: types.Parent{Type: types.ConfigTypeProjectGroup, ID: path.Join("user", user.UserName, "projectgroup01")}})
|
_, err := cs.ch.CreateProject(ctx, &types.Project{Name: projectName, Parent: types.Parent{Type: types.ConfigTypeProjectGroup, ID: path.Join("user", user.Name, "projectgroup01")}})
|
||||||
if err.Error() != expectedErr {
|
if err.Error() != expectedErr {
|
||||||
t.Fatalf("expected err %v, got err: %v", expectedErr, err)
|
t.Fatalf("expected err %v, got err: %v", expectedErr, err)
|
||||||
}
|
}
|
||||||
|
@ -488,7 +488,7 @@ func TestProjectGroupsAndProjects(t *testing.T) {
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go cs.ch.CreateProject(ctx, &types.Project{Name: "project02", Parent: types.Parent{Type: types.ConfigTypeProjectGroup, ID: path.Join("user", user.UserName)}})
|
go cs.ch.CreateProject(ctx, &types.Project{Name: "project02", Parent: types.Parent{Type: types.ConfigTypeProjectGroup, ID: path.Join("user", user.Name)}})
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
|
@ -132,7 +132,7 @@ func (r *ReadDB) GetProjectGroupPath(tx *db.Tx, group *types.ProjectGroup) (stri
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return "", errors.Errorf("cannot find user with id %q", rootGroupID)
|
return "", errors.Errorf("cannot find user with id %q", rootGroupID)
|
||||||
}
|
}
|
||||||
p = path.Join("user", user.UserName)
|
p = path.Join("user", user.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, group := range groups {
|
for _, group := range groups {
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (r *ReadDB) insertUser(tx *db.Tx, data []byte) error {
|
||||||
if err := r.deleteUser(tx, user.ID); err != nil {
|
if err := r.deleteUser(tx, user.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
q, args, err := userInsert.Values(user.ID, user.UserName, data).ToSql()
|
q, args, err := userInsert.Values(user.ID, user.Name, data).ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to build query")
|
return errors.Wrap(err, "failed to build query")
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ type UserResponse struct {
|
||||||
func createUserResponse(u *types.User) *UserResponse {
|
func createUserResponse(u *types.User) *UserResponse {
|
||||||
user := &UserResponse{
|
user := &UserResponse{
|
||||||
ID: u.ID,
|
ID: u.ID,
|
||||||
UserName: u.UserName,
|
UserName: u.Name,
|
||||||
Tokens: make([]string, 0, len(u.Tokens)),
|
Tokens: make([]string, 0, len(u.Tokens)),
|
||||||
}
|
}
|
||||||
for tokenName := range u.Tokens {
|
for tokenName := range u.Tokens {
|
||||||
|
|
|
@ -63,7 +63,7 @@ func (c *CommandHandler) CreateProject(ctx context.Context, req *CreateProjectRe
|
||||||
return nil, errors.Errorf("user doesn't have a linked account for remote source %q", rs.Name)
|
return nil, errors.Errorf("user doesn't have a linked account for remote source %q", rs.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
gitsource, err := c.GetGitSource(ctx, rs, user.UserName, la)
|
gitsource, err := c.GetGitSource(ctx, rs, user.Name, la)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to create gitsource client")
|
return nil, errors.Wrapf(err, "failed to create gitsource client")
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func (c *CommandHandler) CreateProject(ctx context.Context, req *CreateProjectRe
|
||||||
parentID := req.ParentID
|
parentID := req.ParentID
|
||||||
if parentID == "" {
|
if parentID == "" {
|
||||||
// create project in current user namespace
|
// create project in current user namespace
|
||||||
parentID = path.Join("user", user.UserName)
|
parentID = path.Join("user", user.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
p := &types.Project{
|
p := &types.Project{
|
||||||
|
@ -109,7 +109,7 @@ func (c *CommandHandler) CreateProject(ctx context.Context, req *CreateProjectRe
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CommandHandler) SetupProject(ctx context.Context, rs *types.RemoteSource, user *types.User, la *types.LinkedAccount, project *types.Project) error {
|
func (c *CommandHandler) SetupProject(ctx context.Context, rs *types.RemoteSource, user *types.User, la *types.LinkedAccount, project *types.Project) error {
|
||||||
gitsource, err := c.GetGitSource(ctx, rs, user.UserName, la)
|
gitsource, err := c.GetGitSource(ctx, rs, user.Name, la)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to create gitsource client")
|
return errors.Wrapf(err, "failed to create gitsource client")
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ func (c *CommandHandler) ReconfigProject(ctx context.Context, projectRef string)
|
||||||
la := user.LinkedAccounts[p.LinkedAccountID]
|
la := user.LinkedAccounts[p.LinkedAccountID]
|
||||||
c.log.Infof("la: %s", util.Dump(la))
|
c.log.Infof("la: %s", util.Dump(la))
|
||||||
if la == nil {
|
if la == nil {
|
||||||
return errors.Errorf("linked account %q in user %q doesn't exist", p.LinkedAccountID, user.UserName)
|
return errors.Errorf("linked account %q in user %q doesn't exist", p.LinkedAccountID, user.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
rs, resp, err := c.configstoreClient.GetRemoteSource(ctx, la.RemoteSourceID)
|
rs, resp, err := c.configstoreClient.GetRemoteSource(ctx, la.RemoteSourceID)
|
||||||
|
|
|
@ -43,7 +43,7 @@ func (c *CommandHandler) CreateProjectGroup(ctx context.Context, req *CreateProj
|
||||||
parentID := req.ParentID
|
parentID := req.ParentID
|
||||||
if parentID == "" {
|
if parentID == "" {
|
||||||
// create projectGroup in current user namespace
|
// create projectGroup in current user namespace
|
||||||
parentID = path.Join("user", user.UserName)
|
parentID = path.Join("user", user.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
p := &types.ProjectGroup{
|
p := &types.ProjectGroup{
|
||||||
|
|
|
@ -61,7 +61,7 @@ func (c *CommandHandler) CreateUser(ctx context.Context, req *CreateUserRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to create user"))
|
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to create user"))
|
||||||
}
|
}
|
||||||
c.log.Infof("user %s created, ID: %s", u.UserName, u.ID)
|
c.log.Infof("user %s created, ID: %s", u.Name, u.ID)
|
||||||
|
|
||||||
return u, nil
|
return u, nil
|
||||||
}
|
}
|
||||||
|
@ -369,7 +369,7 @@ func (c *CommandHandler) LoginUser(ctx context.Context, req *LoginUserRequest) (
|
||||||
}
|
}
|
||||||
c.log.Infof("la: %s", util.Dump(la))
|
c.log.Infof("la: %s", util.Dump(la))
|
||||||
if la == nil {
|
if la == nil {
|
||||||
return nil, errors.Errorf("linked account for user %q for remote source %q doesn't exist", user.UserName, rs.Name)
|
return nil, errors.Errorf("linked account for user %q for remote source %q doesn't exist", user.Name, rs.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update oauth tokens if they have changed since the getuserinfo request may have updated them
|
// Update oauth tokens if they have changed since the getuserinfo request may have updated them
|
||||||
|
@ -390,12 +390,12 @@ func (c *CommandHandler) LoginUser(ctx context.Context, req *LoginUserRequest) (
|
||||||
Oauth2AccessTokenExpiresAt: la.Oauth2AccessTokenExpiresAt,
|
Oauth2AccessTokenExpiresAt: la.Oauth2AccessTokenExpiresAt,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.log.Infof("updating user %q linked account", user.UserName)
|
c.log.Infof("updating user %q linked account", user.Name)
|
||||||
la, resp, err = c.configstoreClient.UpdateUserLA(ctx, user.UserName, la.ID, creq)
|
la, resp, err = c.configstoreClient.UpdateUserLA(ctx, user.Name, la.ID, creq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to update user"))
|
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to update user"))
|
||||||
}
|
}
|
||||||
c.log.Infof("linked account %q for user %q updated", la.ID, user.UserName)
|
c.log.Infof("linked account %q for user %q updated", la.ID, user.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate jwt token
|
// generate jwt token
|
||||||
|
|
|
@ -75,7 +75,7 @@ func (h *AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// pass userid to handlers via context
|
// pass userid to handlers via context
|
||||||
ctx = context.WithValue(ctx, "userid", user.ID)
|
ctx = context.WithValue(ctx, "userid", user.ID)
|
||||||
ctx = context.WithValue(ctx, "username", user.UserName)
|
ctx = context.WithValue(ctx, "username", user.Name)
|
||||||
h.next.ServeHTTP(w, r.WithContext(ctx))
|
h.next.ServeHTTP(w, r.WithContext(ctx))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ func (h *AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// pass userid to handlers via context
|
// pass userid to handlers via context
|
||||||
ctx = context.WithValue(ctx, "userid", user.ID)
|
ctx = context.WithValue(ctx, "userid", user.ID)
|
||||||
ctx = context.WithValue(ctx, "username", user.UserName)
|
ctx = context.WithValue(ctx, "username", user.Name)
|
||||||
h.next.ServeHTTP(w, r.WithContext(ctx))
|
h.next.ServeHTTP(w, r.WithContext(ctx))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,14 +160,14 @@ func (h *webhooksHandler) handleWebhook(r *http.Request) (int, string, error) {
|
||||||
la := user.LinkedAccounts[project.LinkedAccountID]
|
la := user.LinkedAccounts[project.LinkedAccountID]
|
||||||
h.log.Infof("la: %s", util.Dump(la))
|
h.log.Infof("la: %s", util.Dump(la))
|
||||||
if la == nil {
|
if la == nil {
|
||||||
return http.StatusInternalServerError, "", errors.Errorf("linked account %q in user %q doesn't exist", project.LinkedAccountID, user.UserName)
|
return http.StatusInternalServerError, "", errors.Errorf("linked account %q in user %q doesn't exist", project.LinkedAccountID, user.Name)
|
||||||
}
|
}
|
||||||
rs, _, err := h.configstoreClient.GetRemoteSource(ctx, la.RemoteSourceID)
|
rs, _, err := h.configstoreClient.GetRemoteSource(ctx, la.RemoteSourceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, "", errors.Wrapf(err, "failed to get remote source %q", la.RemoteSourceID)
|
return http.StatusInternalServerError, "", errors.Wrapf(err, "failed to get remote source %q", la.RemoteSourceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
gitSource, err = h.ch.GetGitSource(ctx, rs, user.UserName, la)
|
gitSource, err = h.ch.GetGitSource(ctx, rs, user.Name, la)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, "", errors.Wrapf(err, "failed to create gitea client")
|
return http.StatusInternalServerError, "", errors.Wrapf(err, "failed to create gitea client")
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ type User struct {
|
||||||
|
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
|
|
||||||
UserName string `json:"user_name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
|
|
||||||
LinkedAccounts map[string]*LinkedAccount `json:"linked_accounts,omitempty"`
|
LinkedAccounts map[string]*LinkedAccount `json:"linked_accounts,omitempty"`
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue