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

users: add user favorite support #1864

Merged
merged 38 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
253b09b
applied changes from former branch
pnengchu Jul 15, 2021
e765ffc
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Jul 15, 2021
1e0485f
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Jul 16, 2021
0f30997
wip cypress tests
pnengchu Jul 16, 2021
b1047c5
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Jul 20, 2021
ab06a2a
wip cypress tests
pnengchu Jul 20, 2021
70f93ae
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Jul 21, 2021
9394ce1
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Jul 28, 2021
5635e3c
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Jul 29, 2021
f392be0
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Aug 2, 2021
d5d82b6
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Aug 4, 2021
3c1154b
WIP cypress test: setFavorite mutation
pnengchu Aug 4, 2021
def8d0d
wip cypress tests
pnengchu Aug 6, 2021
20c3ec9
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Aug 9, 2021
0452d6f
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Aug 9, 2021
388a90e
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Aug 11, 2021
8620481
wip cypress test
pnengchu Aug 11, 2021
2080147
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Aug 12, 2021
55ea92e
use direct selector for fav. testing
mastercactapus Aug 16, 2021
ab28501
Merge branch 'favorite-users' of https://github.com/target/goalert in…
pnengchu Aug 16, 2021
b0f889a
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Aug 17, 2021
c72db16
fixes for migration and checks
pnengchu Aug 17, 2021
3e40f80
pr fixes
pnengchu Aug 19, 2021
8ea38ba
pr fixes and rebase from master branch
pnengchu Aug 20, 2021
0cbdde1
fix merge conflicts revert to earlier commit
pnengchu Aug 23, 2021
0c5e3e8
fix merge conflicts
pnengchu Aug 23, 2021
a81ad68
pr fix spelling
pnengchu Aug 24, 2021
ba5c450
pr fixes
pnengchu Aug 25, 2021
db732af
pr bug fix
pnengchu Sep 2, 2021
5e7ab05
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Sep 2, 2021
b219d96
logic cleanup and comment updates
mastercactapus Oct 6, 2021
de9d545
remove unused field from value
mastercactapus Oct 6, 2021
ced0829
Merge branch 'master' into favorite-users
mastercactapus Oct 6, 2021
140b4b7
use null uuid if no userID available
mastercactapus Oct 6, 2021
415d48a
fix forUpdate lock
mastercactapus Oct 6, 2021
b4c12ce
Merge branch 'master' of https://github.com/target/goalert into favor…
pnengchu Oct 7, 2021
24bf30c
cypress build fix
pnengchu Oct 7, 2021
adcfee4
deleted comment
pnengchu Oct 7, 2021
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
4 changes: 3 additions & 1 deletion devtools/resetdb/datagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (d *datagen) NewAlert(status alert.Status) {
// NewFavorite will generate a new favorite for the provided user ID.
func (d *datagen) NewFavorite(userID string) {
var tgt assignment.Target
switch rand.Intn(4) {
switch rand.Intn(5) {
case 0:
tgt = assignment.ServiceTarget(d.ids.Gen(func() string { return d.Services[rand.Intn(len(d.Services))].ID }, "favSvc", userID))
case 1:
Expand All @@ -353,6 +353,8 @@ func (d *datagen) NewFavorite(userID string) {
tgt = assignment.ScheduleTarget(d.ids.Gen(func() string { return d.Schedules[rand.Intn(len(d.Schedules))].ID }, "favSched", userID))
case 3:
tgt = assignment.EscalationPolicyTarget(d.ids.Gen(func() string { return d.EscalationPolicies[rand.Intn(len(d.EscalationPolicies))].ID }, "favEP", userID))
case 4:
tgt = assignment.UserTarget(d.ids.Gen(func() string { return d.Users[rand.Intn(len(d.Users))].ID }, "favUsr", userID))
}

d.Favorites = append(d.Favorites, userFavorite{
Expand Down
91 changes: 91 additions & 0 deletions graphql2/generated.go

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

18 changes: 18 additions & 0 deletions graphql2/graphqlapp/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/target/goalert/validation/validate"

"github.com/pkg/errors"
"github.com/target/goalert/assignment"
"github.com/target/goalert/escalation"
"github.com/target/goalert/graphql2"
"github.com/target/goalert/permission"
Expand Down Expand Up @@ -95,6 +96,12 @@ func (a *Mutation) CreateUser(ctx context.Context, input graphql2.CreateUserInpu
if err != nil {
return err
}
if input.Favorite != nil && *input.Favorite {
err = a.FavoriteStore.SetTx(ctx, tx, permission.UserID(ctx), assignment.UserTarget(newUser.ID))
if err != nil {
return err
}
}
err = a.AuthBasicStore.CreateTx(ctx, tx, newUser.ID, input.Username, input.Password)
if err != nil {
return err
Expand Down Expand Up @@ -150,6 +157,7 @@ func (q *Query) Users(ctx context.Context, opts *graphql2.UserSearchOptions, fir
}

var searchOpts user.SearchOptions
searchOpts.FavoritesUserID = permission.UserID(ctx)
if opts.Search != nil {
searchOpts.Search = *opts.Search
}
Expand All @@ -172,6 +180,12 @@ func (q *Query) Users(ctx context.Context, opts *graphql2.UserSearchOptions, fir
if opts.CMType != nil {
searchOpts.CMType = *opts.CMType
}
if opts.FavoritesOnly != nil {
searchOpts.FavoritesOnly = *opts.FavoritesOnly
}
if opts.FavoritesFirst != nil {
searchOpts.FavoritesFirst = *opts.FavoritesFirst
}

searchOpts.Limit++
users, err := q.UserStore.Search(ctx, &searchOpts)
Expand Down Expand Up @@ -208,3 +222,7 @@ func (a *Query) User(ctx context.Context, id *string) (*user.User, error) {
}
return (*App)(a).FindOneUser(ctx, userID)
}

func (a *User) IsFavorite(ctx context.Context, raw *user.User) (bool, error) {
return raw.IsUserFavorite(), nil
}
15 changes: 9 additions & 6 deletions graphql2/models_gen.go

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

9 changes: 9 additions & 0 deletions graphql2/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ input CreateUserInput {
name: String
email: String
role: UserRole
favorite: Boolean
}

input CreateUserCalendarSubscriptionInput {
Expand Down Expand Up @@ -806,6 +807,12 @@ input UserSearchOptions {
omit: [ID!]
CMValue: String = ""
CMType: ContactMethodType

# Include only favorited services in the results.
favoritesOnly: Boolean = false

# Sort favorite services first.
favoritesFirst: Boolean = false
}

input AlertSearchOptions {
Expand Down Expand Up @@ -1083,6 +1090,8 @@ type User {
sessions: [UserSession!]!

onCallSteps: [EscalationPolicyStep!]!

isFavorite: Boolean!
}

type UserSession {
Expand Down
9 changes: 9 additions & 0 deletions migrate/migrations/20210817132557-add-user-favorite.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- +migrate Up
ALTER TABLE user_favorites
ADD COLUMN tgt_user_id UUID REFERENCES users(id) ON DELETE CASCADE,
ADD CONSTRAINT user_favorites_user_id_tgt_user_id_key UNIQUE(user_id, tgt_user_id);

-- +migrate Down
ALTER TABLE user_favorites
DROP CONSTRAINT user_favorites_user_id_tgt_user_id_key,
DROP COLUMN tgt_user_id;
Loading