summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorSergey Dryabzhinsky <sergey@rusoft.ru>2021-06-26 22:53:14 +0300
committerGitHub <noreply@github.com>2021-06-26 20:53:14 +0100
commit22a0636544237bcffb46b36b593a501e77ae02cc (patch)
tree009c2bcf2b478f45356b8aae59f29091ffc5809f /modules
parent19ac575d572af655ab691f829d0b4de38a1f10be (diff)
downloadgitea-22a0636544237bcffb46b36b593a501e77ae02cc.tar.gz
gitea-22a0636544237bcffb46b36b593a501e77ae02cc.zip
Add Visible modes function from Organisation to Users too (#16069)
You can limit or hide organisations. This pull make it also posible for users - new strings to translte - add checkbox to user profile form - add checkbox to admin user.edit form - filter explore page user search - filter api admin and public user searches - allow admins view "hidden" users - add app option DEFAULT_USER_VISIBILITY - rewrite many files to use Visibility field - check for teams intersection - fix context output - right fake 404 if not visible Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules')
-rw-r--r--modules/convert/user.go4
-rw-r--r--modules/convert/user_test.go8
-rw-r--r--modules/setting/service.go4
-rw-r--r--modules/structs/admin_user.go2
-rw-r--r--modules/structs/user.go2
5 files changed, 20 insertions, 0 deletions
diff --git a/modules/convert/user.go b/modules/convert/user.go
index 894be3bd44..164ffb71fd 100644
--- a/modules/convert/user.go
+++ b/modules/convert/user.go
@@ -62,10 +62,14 @@ func toUser(user *models.User, signed, authed bool) *api.User {
Following: user.NumFollowing,
StarredRepos: user.NumStars,
}
+
+ result.Visibility = user.Visibility.String()
+
// hide primary email if API caller is anonymous or user keep email private
if signed && (!user.KeepEmailPrivate || authed) {
result.Email = user.Email
}
+
// only site admin will get these information and possibly user himself
if authed {
result.IsAdmin = user.IsAdmin
diff --git a/modules/convert/user_test.go b/modules/convert/user_test.go
index 7837910ffe..679c4f9894 100644
--- a/modules/convert/user_test.go
+++ b/modules/convert/user_test.go
@@ -8,6 +8,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
)
@@ -27,4 +28,11 @@ func TestUser_ToUser(t *testing.T) {
apiUser = toUser(user1, false, false)
assert.False(t, apiUser.IsAdmin)
+ assert.EqualValues(t, api.VisibleTypePublic.String(), apiUser.Visibility)
+
+ user31 := models.AssertExistsAndLoadBean(t, &models.User{ID: 31, IsAdmin: false, Visibility: api.VisibleTypePrivate}).(*models.User)
+
+ apiUser = toUser(user31, true, true)
+ assert.False(t, apiUser.IsAdmin)
+ assert.EqualValues(t, api.VisibleTypePrivate.String(), apiUser.Visibility)
}
diff --git a/modules/setting/service.go b/modules/setting/service.go
index bd70c7e6eb..3f689212f3 100644
--- a/modules/setting/service.go
+++ b/modules/setting/service.go
@@ -15,6 +15,8 @@ import (
// Service settings
var Service struct {
+ DefaultUserVisibility string
+ DefaultUserVisibilityMode structs.VisibleType
DefaultOrgVisibility string
DefaultOrgVisibilityMode structs.VisibleType
ActiveCodeLives int
@@ -118,6 +120,8 @@ func newService() {
Service.EnableUserHeatmap = sec.Key("ENABLE_USER_HEATMAP").MustBool(true)
Service.AutoWatchNewRepos = sec.Key("AUTO_WATCH_NEW_REPOS").MustBool(true)
Service.AutoWatchOnChanges = sec.Key("AUTO_WATCH_ON_CHANGES").MustBool(false)
+ Service.DefaultUserVisibility = sec.Key("DEFAULT_USER_VISIBILITY").In("public", structs.ExtractKeysFromMapString(structs.VisibilityModes))
+ Service.DefaultUserVisibilityMode = structs.VisibilityModes[Service.DefaultUserVisibility]
Service.DefaultOrgVisibility = sec.Key("DEFAULT_ORG_VISIBILITY").In("public", structs.ExtractKeysFromMapString(structs.VisibilityModes))
Service.DefaultOrgVisibilityMode = structs.VisibilityModes[Service.DefaultOrgVisibility]
Service.DefaultOrgMemberVisible = sec.Key("DEFAULT_ORG_MEMBER_VISIBLE").MustBool()
diff --git a/modules/structs/admin_user.go b/modules/structs/admin_user.go
index 5da4e9608b..facf16a395 100644
--- a/modules/structs/admin_user.go
+++ b/modules/structs/admin_user.go
@@ -19,6 +19,7 @@ type CreateUserOption struct {
Password string `json:"password" binding:"Required;MaxSize(255)"`
MustChangePassword *bool `json:"must_change_password"`
SendNotify bool `json:"send_notify"`
+ Visibility string `json:"visibility" binding:"In(,public,limited,private)"`
}
// EditUserOption edit user options
@@ -43,4 +44,5 @@ type EditUserOption struct {
ProhibitLogin *bool `json:"prohibit_login"`
AllowCreateOrganization *bool `json:"allow_create_organization"`
Restricted *bool `json:"restricted"`
+ Visibility string `json:"visibility" binding:"In(,public,limited,private)"`
}
diff --git a/modules/structs/user.go b/modules/structs/user.go
index 0d8b0300c3..a3c8f0c32a 100644
--- a/modules/structs/user.go
+++ b/modules/structs/user.go
@@ -43,6 +43,8 @@ type User struct {
Website string `json:"website"`
// the user's description
Description string `json:"description"`
+ // User visibility level option: public, limited, private
+ Visibility string `json:"visibility"`
// user counts
Followers int `json:"followers_count"`