diff options
Diffstat (limited to 'internal/db/users.go')
-rw-r--r-- | internal/db/users.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/internal/db/users.go b/internal/db/users.go index 8cebd814..d52cfc4c 100644 --- a/internal/db/users.go +++ b/internal/db/users.go @@ -48,6 +48,8 @@ type UsersStore interface { // GetByUsername returns the user with given username. It returns // ErrUserNotExist when not found. GetByUsername(ctx context.Context, username string) (*User, error) + // HasForkedRepository returns true if the user has forked given repository. + HasForkedRepository(ctx context.Context, userID, repoID int64) bool } var Users UsersStore @@ -68,6 +70,11 @@ func (u *User) AfterFind(_ *gorm.DB) error { return nil } +// IsLocal returns true if user is created as local account. +func (u *User) IsLocal() bool { + return u.LoginSource <= 0 +} + var _ UsersStore = (*users)(nil) type users struct { @@ -344,3 +351,9 @@ func (db *users) GetByUsername(ctx context.Context, username string) (*User, err } return user, nil } + +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) + return count > 0 +} |