diff options
Diffstat (limited to 'internal/db/users.go')
-rw-r--r-- | internal/db/users.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/internal/db/users.go b/internal/db/users.go index 468bb3ac..7e986a47 100644 --- a/internal/db/users.go +++ b/internal/db/users.go @@ -73,6 +73,10 @@ type UsersStore interface { // GetByKeyID returns the owner of given public key ID. It returns // ErrUserNotExist when not found. GetByKeyID(ctx context.Context, keyID int64) (*User, error) + // GetMailableEmailsByUsernames returns a list of verified primary email + // addresses (where email notifications are sent to) of users with given list of + // usernames. Non-existing usernames are ignored. + GetMailableEmailsByUsernames(ctx context.Context, usernames []string) ([]string, error) // HasForkedRepository returns true if the user has forked given repository. HasForkedRepository(ctx context.Context, userID, repoID int64) bool // IsUsernameUsed returns true if the given username has been used other than @@ -509,6 +513,15 @@ func (db *users) GetByKeyID(ctx context.Context, keyID int64) (*User, error) { return user, nil } +func (db *users) GetMailableEmailsByUsernames(ctx context.Context, usernames []string) ([]string, error) { + emails := make([]string, 0, len(usernames)) + return emails, db.WithContext(ctx). + Model(&User{}). + Select("email"). + Where("lower_name IN (?) AND is_active = ?", usernames, true). + Find(&emails).Error +} + func (db *users) HasForkedRepository(ctx context.Context, userID, repoID int64) bool { var count int64 db.WithContext(ctx).Model(new(Repository)).Where("owner_id = ? AND fork_id = ?", userID, repoID).Count(&count) @@ -816,11 +829,6 @@ func (u *User) IsOrganization() bool { return u.Type == UserTypeOrganization } -// IsMailable returns true if the user is eligible to receive emails. -func (u *User) IsMailable() bool { - return u.IsActive -} - // APIFormat returns the API format of a user. func (u *User) APIFormat() *api.User { return &api.User{ |