aboutsummaryrefslogtreecommitdiff
path: root/internal/db/users.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/users.go')
-rw-r--r--internal/db/users.go25
1 files changed, 24 insertions, 1 deletions
diff --git a/internal/db/users.go b/internal/db/users.go
index ca755fc6..bdd6501b 100644
--- a/internal/db/users.go
+++ b/internal/db/users.go
@@ -511,11 +511,16 @@ func (u *User) AfterFind(_ *gorm.DB) error {
return nil
}
-// IsLocal returns true if user is created as local account.
+// IsLocal returns true if the user is created as local account.
func (u *User) IsLocal() bool {
return u.LoginSource <= 0
}
+// IsOrganization returns true if the user is an organization.
+func (u *User) IsOrganization() bool {
+ return u.Type == UserTypeOrganization
+}
+
// APIFormat returns the API format of a user.
func (u *User) APIFormat() *api.User {
return &api.User{
@@ -626,3 +631,21 @@ func (u *User) AvatarURL() string {
func (u *User) IsFollowing(followID int64) bool {
return Follows.IsFollowing(context.TODO(), u.ID, followID)
}
+
+// IsUserOrgOwner returns true if the user is in the owner team of the given
+// organization.
+//
+// TODO(unknwon): This is also used in templates, which should be fixed by
+// having a dedicated type `template.User`.
+func (u *User) IsUserOrgOwner(orgId int64) bool {
+ return IsOrganizationOwner(orgId, u.ID)
+}
+
+// IsPublicMember returns true if the user has public membership of the given
+// organization.
+//
+// TODO(unknwon): This is also used in templates, which should be fixed by
+// having a dedicated type `template.User`.
+func (u *User) IsPublicMember(orgId int64) bool {
+ return IsPublicMembership(orgId, u.ID)
+}