Skip to content

Commit

Permalink
Backend PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Jul 12, 2024
1 parent 71a438a commit 524ff9a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion admin/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ type DB interface {
DeleteOrganizationMemberUser(ctx context.Context, orgID, userID string) error
UpdateOrganizationMemberUserRole(ctx context.Context, orgID, userID, roleID string) error
CountSingleuserOrganizationsForMemberUser(ctx context.Context, userID string) (int, error)
FindOrganizationMemberWithManageUsersRole(ctx context.Context, orgID string) ([]*MemberUser, error)
FindOrganizationMembersWithManageUsersRole(ctx context.Context, orgID string) ([]*MemberUser, error)

FindProjectMemberUsers(ctx context.Context, projectID, afterEmail string, limit int) ([]*MemberUser, error)
InsertProjectMemberUser(ctx context.Context, projectID, userID, roleID string) error
Expand Down
20 changes: 15 additions & 5 deletions admin/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ func (c *connection) CountSingleuserOrganizationsForMemberUser(ctx context.Conte
return count, nil
}

func (c *connection) FindOrganizationMemberWithManageUsersRole(ctx context.Context, orgID string) ([]*database.MemberUser, error) {
func (c *connection) FindOrganizationMembersWithManageUsersRole(ctx context.Context, orgID string) ([]*database.MemberUser, error) {
var res []*database.MemberUser
err := c.getDB(ctx).SelectContext(ctx, &res, `
SELECT u.id, u.email, u.display_name, u.created_on, u.updated_on, r.name FROM users u
Expand Down Expand Up @@ -1599,12 +1599,22 @@ func (c *connection) UpdateProjectInviteRole(ctx context.Context, id, roleID str

func (c *connection) FindProjectAccessRequests(ctx context.Context, projectID, afterID string, limit int) ([]*database.ProjectAccessRequest, error) {
var res []*database.ProjectAccessRequest
err := c.getDB(ctx).SelectContext(ctx, &res, `
var err error
if afterID != "" {
err = c.getDB(ctx).SelectContext(ctx, &res, `
SELECT par.user_id
FROM project_access_requests par
WHERE par.project_id = $1 AND par.user_id > $2
ORDER BY par.user_id LIMIT $3
`, projectID, afterID, limit)
} else {
err = c.getDB(ctx).SelectContext(ctx, &res, `
SELECT par.user_id
FROM project_access_requests par
WHERE par.project_id = $1 AND par.user_id > lower($2)
ORDER BY lower(par.email) LIMIT $3
`, projectID, afterID, limit)
WHERE par.project_id = $1
ORDER BY par.user_id LIMIT $2
`, projectID, limit)
}
if err != nil {
return nil, parseErr("project access request", err)
}
Expand Down
18 changes: 3 additions & 15 deletions admin/server/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,6 @@ func (s *Server) RequestProjectAccess(ctx context.Context, req *adminv1.RequestP
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
// TODO: quotas

existing, err := s.admin.DB.FindProjectAccessRequest(ctx, proj.ID, user.ID)
if err != nil && !errors.Is(err, database.ErrNotFound) {
Expand All @@ -1022,17 +1021,7 @@ func (s *Server) RequestProjectAccess(ctx context.Context, req *adminv1.RequestP
return nil, status.Error(codes.Internal, err.Error())
}

admins, err := s.admin.DB.FindOrganizationMemberWithManageUsersRole(ctx, proj.OrganizationID)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

approveLink, err := url.JoinPath(s.opts.FrontendURL, org.Name, proj.Name, "-", "request-access", accessReq.ID, "approve")
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

denyLink, err := url.JoinPath(s.opts.FrontendURL, org.Name, proj.Name, "-", "request-access", accessReq.ID, "deny")
admins, err := s.admin.DB.FindOrganizationMembersWithManageUsersRole(ctx, proj.OrganizationID)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand All @@ -1044,8 +1033,8 @@ func (s *Server) RequestProjectAccess(ctx context.Context, req *adminv1.RequestP
Email: user.Email,
OrgName: org.Name,
ProjectName: proj.Name,
ApproveLink: approveLink,
DenyLink: denyLink,
ApproveLink: s.urls.approveProjectAccess(org.Name, proj.Name, accessReq.ID),
DenyLink: s.urls.denyProjectAccess(org.Name, proj.Name, accessReq.ID),
})
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
Expand Down Expand Up @@ -1113,7 +1102,6 @@ func (s *Server) ApproveProjectAccess(ctx context.Context, req *adminv1.ApproveP
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
// TODO: quotas

role, err := s.admin.DB.FindProjectRole(ctx, req.Role)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions admin/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,11 @@ func (u *externalURLs) alertEdit(org, project, alert string) string {
func (u *externalURLs) magicAuthTokenOpen(org, project, token string) string {
return urlutil.MustJoinURL(u.frontend, org, project, "-", "share", token)
}

func (u *externalURLs) approveProjectAccess(org, project, id string) string {
return urlutil.MustJoinURL(u.frontend, org, project, "-", "request-access", id, "approve")
}

func (u *externalURLs) denyProjectAccess(org, project, id string) string {
return urlutil.MustJoinURL(u.frontend, org, project, "-", "request-access", id, "deny")
}

0 comments on commit 524ff9a

Please sign in to comment.