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

PMM-12910 snooze updates #3018

Merged
merged 9 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 15 additions & 0 deletions api/swagger/swagger-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -31406,6 +31406,11 @@
"type": "boolean",
"title": "Alerting Tour",
"x-order": 2
},
"snoozed_pmm_version": {
"type": "string",
"title": "Snoozed PMM version update",
"x-order": 3
}
}
}
Expand Down Expand Up @@ -31467,6 +31472,11 @@
"type": "boolean",
"title": "Alerting Tour",
"x-order": 1
},
"snoozed_pmm_version": {
"type": "string",
"title": "Snooze update alert for a PMM version",
"x-order": 2
}
}
}
Expand All @@ -31493,6 +31503,11 @@
"type": "boolean",
"title": "Alerting Tour",
"x-order": 2
},
"snoozed_pmm_version": {
"type": "string",
"title": "Snoozed PMM version update",
"x-order": 3
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -25873,6 +25873,11 @@
"type": "boolean",
"title": "Alerting Tour",
"x-order": 2
},
"snoozed_pmm_version": {
"type": "string",
"title": "Snoozed PMM version update",
"x-order": 3
}
}
}
Expand Down Expand Up @@ -25934,6 +25939,11 @@
"type": "boolean",
"title": "Alerting Tour",
"x-order": 1
},
"snoozed_pmm_version": {
"type": "string",
"title": "Snooze update alert for a PMM version",
"x-order": 2
}
}
}
Expand All @@ -25960,6 +25970,11 @@
"type": "boolean",
"title": "Alerting Tour",
"x-order": 2
},
"snoozed_pmm_version": {
"type": "string",
"title": "Snoozed PMM version update",
"x-order": 3
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions api/userpb/json/client/user/get_user_responses.go

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

6 changes: 6 additions & 0 deletions api/userpb/json/client/user/update_user_responses.go

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

15 changes: 15 additions & 0 deletions api/userpb/json/userpb.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"title": "Product Tour",
"x-order": 1
},
"snoozed_pmm_version": {
"type": "string",
"title": "Snoozed PMM version update",
"x-order": 3
},
"user_id": {
"type": "integer",
"format": "int64",
Expand Down Expand Up @@ -105,6 +110,11 @@
"type": "boolean",
"title": "Product Tour",
"x-order": 0
},
"snoozed_pmm_version": {
"type": "string",
"title": "Snooze update alert for a PMM version",
"x-order": 2
}
}
}
Expand All @@ -126,6 +136,11 @@
"title": "Product Tour",
"x-order": 1
},
"snoozed_pmm_version": {
"type": "string",
"title": "Snoozed PMM version update",
"x-order": 3
},
"user_id": {
"type": "integer",
"format": "int64",
Expand Down
154 changes: 91 additions & 63 deletions api/userpb/user.pb.go

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions api/userpb/user.pb.validate.go

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

4 changes: 4 additions & 0 deletions api/userpb/user.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ message UserDetailsResponse {
bool product_tour_completed = 2;
// Alerting Tour
bool alerting_tour_completed = 3;
// Snoozed PMM version update
string snoozed_pmm_version = 4;
}

message UserUpdateRequest {
// Product Tour
bool product_tour_completed = 2;
// Alerting Tour
bool alerting_tour_completed = 3;
// Snooze update alert for a PMM version
google.protobuf.StringValue snoozed_pmm_version = 4;
idoqo marked this conversation as resolved.
Show resolved Hide resolved
}

message ListUsersRequest {}
Expand Down
4 changes: 4 additions & 0 deletions managed/models/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,10 @@ var databaseSchema = [][]string{
102: {
`UPDATE settings SET settings = settings - 'alert_manager_url'`,
},
103: {
`ALTER TABLE user_flags
ADD COLUMN snoozed_pmm_version VARCHAR NOT NULL DEFAULT ''`,
},
}

// ^^^ Avoid default values in schema definition. ^^^
Expand Down
10 changes: 7 additions & 3 deletions managed/models/user_flags_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ type CreateUserParams struct {

// UpdateUserParams has parameters to update existing user.
type UpdateUserParams struct {
UserID int
Tour bool
AlertingTour bool
UserID int
Tour bool
AlertingTour bool
SnoozedPMMVersion string
idoqo marked this conversation as resolved.
Show resolved Hide resolved
}

// GetOrCreateUser returns user and optionally creates it, if not in database yet.
Expand Down Expand Up @@ -103,6 +104,9 @@ func UpdateUser(q *reform.Querier, params *UpdateUserParams) (*UserDetails, erro

row.Tour = params.Tour
row.AlertingTour = params.AlertingTour
if params.SnoozedPMMVersion != "" {
idoqo marked this conversation as resolved.
Show resolved Hide resolved
row.SnoozedPMMVersion = params.SnoozedPMMVersion
}

if err = q.Update(row); err != nil {
return nil, errors.Wrap(err, "failed to update user")
Expand Down
7 changes: 4 additions & 3 deletions managed/models/user_flags_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import (
//
//reform:user_flags
type UserDetails struct {
ID int `reform:"id,pk"`
Tour bool `reform:"tour_done"`
AlertingTour bool `reform:"alerting_tour_done"`
ID int `reform:"id,pk"`
Tour bool `reform:"tour_done"`
AlertingTour bool `reform:"alerting_tour_done"`
SnoozedPMMVersion string `reform:"snoozed_pmm_version"`

CreatedAt time.Time `reform:"created_at"`
UpdatedAt time.Time `reform:"updated_at"`
Expand Down
11 changes: 8 additions & 3 deletions managed/models/user_flags_model_reform.go

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

7 changes: 6 additions & 1 deletion managed/services/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ func (s *Service) GetUser(ctx context.Context, _ *userpb.UserDetailsRequest) (*u
UserId: uint32(userInfo.ID),
ProductTourCompleted: userInfo.Tour,
AlertingTourCompleted: userInfo.AlertingTour,
SnoozedPmmVersion: userInfo.SnoozedPMMVersion,
}
return resp, nil
}

// UpdateUser updates data for given user.
// UpdateUser updates data and flags for the given user.
func (s *Service) UpdateUser(ctx context.Context, req *userpb.UserUpdateRequest) (*userpb.UserDetailsResponse, error) {
userID, err := s.c.GetUserID(ctx)
if err != nil {
Expand Down Expand Up @@ -106,6 +107,9 @@ func (s *Service) UpdateUser(ctx context.Context, req *userpb.UserUpdateRequest)
if req.AlertingTourCompleted {
params.AlertingTour = req.AlertingTourCompleted
}
if req.SnoozedPmmVersion != nil {
idoqo marked this conversation as resolved.
Show resolved Hide resolved
params.SnoozedPMMVersion = req.SnoozedPmmVersion.Value
idoqo marked this conversation as resolved.
Show resolved Hide resolved
}

userInfo, err = models.UpdateUser(tx.Querier, params)
if err != nil {
Expand All @@ -122,6 +126,7 @@ func (s *Service) UpdateUser(ctx context.Context, req *userpb.UserUpdateRequest)
UserId: uint32(userInfo.ID),
ProductTourCompleted: userInfo.Tour,
AlertingTourCompleted: userInfo.AlertingTour,
SnoozedPmmVersion: userInfo.SnoozedPMMVersion,
}
return resp, nil
}
Expand Down
Loading