Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Remember user's SMS template preference #1379

Merged
merged 16 commits into from
Dec 17, 2020

Conversation

whaught
Copy link
Contributor

@whaught whaught commented Dec 16, 2020

Issue #1320

Proposed Changes

  • Remember the issuing user's last used SMS template.

Release Note

 Remember the issuing user's last used SMS template.

@googlebot googlebot added the cla: yes Auto: added by CLA bot when all committers have signed a CLA. label Dec 16, 2020
@whaught whaught changed the title Remember user Remember user's SMS template preference Dec 16, 2020
cmd/server/assets/codes/bulk-issue.html Outdated Show resolved Hide resolved
cmd/server/assets/codes/issue.html Outdated Show resolved Hide resolved
pkg/controller/issueapi/logic.go Outdated Show resolved Hide resolved
pkg/database/migrations.go Outdated Show resolved Hide resolved
`UPDATE users SET remember_last_used_sms_template = TRUE WHERE remember_last_used_sms_template IS NULL`,
`ALTER TABLE users ALTER COLUMN remember_last_used_sms_template SET DEFAULT TRUE`,
`ALTER TABLE users ALTER COLUMN remember_last_used_sms_template SET NOT NULL`,
`ALTER TABLE users ADD COLUMN IF NOT EXISTS default_sms_template_label VARCHAR(255)`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add some validation or a database constraint here. Either:

  • Changing an SMS label should fail if a user is depending on it
  • Changing an SMS label clears the default for any users

pkg/database/user.go Outdated Show resolved Hide resolved
@@ -43,6 +43,9 @@ type User struct {
Name string `gorm:"type:varchar(100)"`
SystemAdmin bool `gorm:"column:system_admin; default:false;"`

RememberLastUsedSMSTemplate bool `gorm:"type:boolean; not null; default:true;"`
DefaultSMSTemplateLabel string `gorm:"type:varchar(255);"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things here:

  • A user can be a member of multiple realms (with different templates), so this might be better as a property on the Membership instead of the user
  • There needs to be some validation that the template is one of the keys in the hstore for the realm
  • There needs to be some validation/changes when the hstore column is updated to cascade here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to keep the membership preferred template in sync with the existing ones. When the page loads and the template doesn't exist, that selectedIf doesn't match anything and the user goes back to the default template in the selector.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this work for users that in in more than 1 realm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses Seth's suggestion now - it's attached to Membership

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I have to join a club?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Club Realm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

™️

@whaught
Copy link
Contributor Author

whaught commented Dec 16, 2020

/hold

this needs some tests too

@whaught
Copy link
Contributor Author

whaught commented Dec 16, 2020

/unhold

var audits []*AuditEntry

var existing Membership
if err := tx.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we be reading this for update?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do that to diff existing and add audits. This is the pattern we're using in SaveRealm, SaveUser, etc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's all in a tx, so we don't need to read for update as that's implied.

pkg/database/membership.go Show resolved Hide resolved
var audits []*AuditEntry

var existing Membership
if err := tx.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's all in a tx, so we don't need to read for update as that's implied.

pkg/database/membership.go Outdated Show resolved Hide resolved
pkg/database/membership.go Outdated Show resolved Hide resolved
Copy link
Member

@sethvargo sethvargo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sethvargo, whaught

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-robot google-oss-robot merged commit 2ab46b1 into google:main Dec 17, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 19, 2020
@whaught whaught deleted the remember-template-pref branch December 22, 2020 01:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Auto: added by CLA bot when all committers have signed a CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants