summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLanre Adelowo <adelowomailbox@gmail.com>2019-03-03 23:57:24 +0100
committertechknowlogick <matti@mdranta.net>2019-03-03 17:57:24 -0500
commit141c58f5a6353a3e9173ababd1532819ba2ee284 (patch)
treed888756084d086e455830f3d28526ced69de85d5 /models
parent8e202e28ad80452ced90ede3540e1662fa6d7da7 (diff)
downloadgitea-141c58f5a6353a3e9173ababd1532819ba2ee284.tar.gz
gitea-141c58f5a6353a3e9173ababd1532819ba2ee284.zip
add isAdmin to user model (#6231)
update vendor and add tests fix swagger
Diffstat (limited to 'models')
-rw-r--r--models/user.go1
-rw-r--r--models/user_test.go17
2 files changed, 18 insertions, 0 deletions
diff --git a/models/user.go b/models/user.go
index f6c2d6e25b..b64454d213 100644
--- a/models/user.go
+++ b/models/user.go
@@ -211,6 +211,7 @@ func (u *User) APIFormat() *api.User {
Email: u.getEmail(),
AvatarURL: u.AvatarLink(),
Language: u.Language,
+ IsAdmin: u.IsAdmin,
}
}
diff --git a/models/user_test.go b/models/user_test.go
index 35efc3959a..f0a8dbdd47 100644
--- a/models/user_test.go
+++ b/models/user_test.go
@@ -23,6 +23,23 @@ func TestGetUserEmailsByNames(t *testing.T) {
assert.Equal(t, []string{"user8@example.com", "user5@example.com"}, GetUserEmailsByNames([]string{"user8", "user5"}))
}
+func TestUser_APIFormat(t *testing.T) {
+
+ user, err := GetUserByID(1)
+ assert.NoError(t, err)
+ assert.True(t, user.IsAdmin)
+
+ apiUser := user.APIFormat()
+ assert.True(t, apiUser.IsAdmin)
+
+ user, err = GetUserByID(2)
+ assert.NoError(t, err)
+ assert.False(t, user.IsAdmin)
+
+ apiUser = user.APIFormat()
+ assert.False(t, apiUser.IsAdmin)
+}
+
func TestCanCreateOrganization(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())