Skip to content

Commit

Permalink
Remove user details from mediator database (#1304)
Browse files Browse the repository at this point in the history
Fix #1279
  • Loading branch information
eleftherias authored Oct 27, 2023
1 parent 283441a commit 11a5a93
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 246 deletions.
25 changes: 0 additions & 25 deletions cmd/cli/app/auth/auth_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,6 @@ func renderNewUser(cmd *cobra.Command, newUser *pb.CreateUserResponse) {
{"Project Name", newUser.ProjectName},
}

if newUser.Email != nil {
rows = append(rows, table.Row{"Email", *newUser.Email})
}

if newUser.FirstName != nil {
rows = append(rows, table.Row{"First Name", *newUser.FirstName})
}

if newUser.LastName != nil {
rows = append(rows, table.Row{"Last Name", *newUser.LastName})
}

renderUserToTable(cmd, rows)
}

Expand All @@ -236,19 +224,6 @@ func renderUserInfo(cmd *cobra.Command, user *pb.GetUserResponse) {
{projectKey, strings.Join(projects, ", ")},
}

userInfo := user.GetUser()
if userInfo.Email != nil {
rows = append(rows, table.Row{"Email", *userInfo.Email})
}

if userInfo.FirstName != nil {
rows = append(rows, table.Row{"First Name", *userInfo.FirstName})
}

if userInfo.LastName != nil {
rows = append(rows, table.Row{"Last Name", *userInfo.LastName})
}

renderUserToTable(cmd, rows)
}

Expand Down
19 changes: 19 additions & 0 deletions database/migrations/000004_remove_personal_info.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- Copyright 2023 Stacklok, Inc
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

-- Add personal user details to users table
ALTER TABLE users
ADD COLUMN email TEXT,
ADD COLUMN first_name TEXT,
ADD COLUMN last_name TEXT;
19 changes: 19 additions & 0 deletions database/migrations/000004_remove_personal_info.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- Copyright 2023 Stacklok, Inc
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

-- Remove personal user details from users table
ALTER TABLE users
DROP COLUMN IF EXISTS email,
DROP COLUMN IF EXISTS first_name,
DROP COLUMN IF EXISTS last_name;
2 changes: 1 addition & 1 deletion database/query/users.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- name: CreateUser :one
INSERT INTO users (organization_id, email, identity_subject, first_name, last_name) VALUES ($1, $2, $3, $4, $5) RETURNING *;
INSERT INTO users (organization_id, identity_subject) VALUES ($1, $2) RETURNING *;

-- name: GetUserByID :one
SELECT * FROM users WHERE id = $1;
Expand Down
6 changes: 0 additions & 6 deletions docs/docs/protodocs/proto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions internal/controlplane/handlers_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ import (
pb "github.com/stacklok/mediator/pkg/api/protobuf/go/mediator/v1"
)

func stringToNullString(s string) *sql.NullString {
if s == "" {
return &sql.NullString{Valid: false}
}
return &sql.NullString{String: s, Valid: true}
}

// CreateUser is a service for user self registration
//
//gocyclo:ignore
Expand Down Expand Up @@ -102,9 +95,6 @@ func (s *Server) CreateUser(ctx context.Context,
userOrg = organization.ID
userProject = uuid.MustParse(orgProject.ProjectId)
user, err := qtx.CreateUser(ctx, db.CreateUserParams{OrganizationID: userOrg,
Email: *stringToNullString(token.Email()),
FirstName: *stringToNullString(token.GivenName()),
LastName: *stringToNullString(token.FamilyName()),
IdentitySubject: subject})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to create user: %s", err)
Expand Down Expand Up @@ -132,10 +122,7 @@ func (s *Server) CreateUser(ctx context.Context,
OrganizatioName: organization.Name,
ProjectId: userProject.String(),
ProjectName: orgProject.Name,
Email: &user.Email.String,
IdentitySubject: user.IdentitySubject,
FirstName: &user.FirstName.String,
LastName: &user.LastName.String,
CreatedAt: timestamppb.New(user.CreatedAt),
}, nil
}
Expand Down Expand Up @@ -250,10 +237,7 @@ func (s *Server) GetUser(ctx context.Context, _ *pb.GetUserRequest) (*pb.GetUser
resp.User = &pb.UserRecord{
Id: user.ID,
OrganizationId: user.OrganizationID.String(),
Email: &user.Email.String,
IdentitySubject: user.IdentitySubject,
FirstName: &user.FirstName.String,
LastName: &user.LastName.String,
CreatedAt: timestamppb.New(user.CreatedAt),
UpdatedAt: timestamppb.New(user.UpdatedAt),
}
Expand Down
11 changes: 1 addition & 10 deletions internal/controlplane/handlers_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ func TestCreateUserDBMock(t *testing.T) {
ID: 1,
OrganizationID: orgID,
IdentitySubject: "subject1",
Email: sql.NullString{String: "[email protected]", Valid: true},
FirstName: sql.NullString{String: "Foo", Valid: true},
LastName: sql.NullString{String: "Bar", Valid: true},
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
Expand All @@ -98,10 +95,7 @@ func TestCreateUserDBMock(t *testing.T) {
store.EXPECT().CreateProvider(gomock.Any(), gomock.Any())
store.EXPECT().
CreateUser(gomock.Any(), db.CreateUserParams{OrganizationID: orgID,
IdentitySubject: "subject1",
Email: sql.NullString{String: "[email protected]", Valid: true},
FirstName: sql.NullString{String: "Foo", Valid: true},
LastName: sql.NullString{String: "Bar", Valid: true}}).
IdentitySubject: "subject1"}).
Return(returnedUser, nil)
store.EXPECT().AddUserProject(gomock.Any(), db.AddUserProjectParams{UserID: 1, ProjectID: projectID})
store.EXPECT().AddUserRole(gomock.Any(), db.AddUserRoleParams{UserID: 1, RoleID: 2})
Expand All @@ -117,10 +111,7 @@ func TestCreateUserDBMock(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, res)
assert.Equal(t, int32(1), res.Id)
assert.Equal(t, "[email protected]", *res.Email)
assert.Equal(t, orgID.String(), res.OrganizationId)
assert.Equal(t, "Foo", *res.FirstName)
assert.Equal(t, "Bar", *res.LastName)
},
},
}
Expand Down
13 changes: 5 additions & 8 deletions internal/db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 9 additions & 37 deletions internal/db/users.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 11a5a93

Please sign in to comment.