Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set organization visibility (public, internal, private) #1763

Merged
merged 167 commits into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
167 commits
Select commit Hold shift + click to select a range
c2a75b3
Add UI visibility in organization settings
DblK May 19, 2017
4df763c
Set Visibility Public by default when creating new organization
DblK May 19, 2017
9d73ff4
Implement visibility in explore/organizations
DblK May 21, 2017
7bdc6e8
Implement visibility in explore/repos
DblK May 21, 2017
fb0c45a
Implement global configuration for new organizations
DblK May 22, 2017
90ec030
Add in admin/repos and admin/org gold lock icons for private organiza…
DblK May 22, 2017
8eaddfc
Handle display of repositories from explore/repo and when viewing an …
DblK May 22, 2017
20e63bb
Add lock icon for private org on explore/repo
DblK May 23, 2017
15d9e00
User profile display organization based on Membership Visibility and …
DblK May 24, 2017
49e4008
Resolve Conflict for merging
DblK May 24, 2017
fcf8516
Merge remote-tracking branch 'upstream/master' into feature_AllowPriv…
techknowlogick Jun 8, 2018
86d1e78
Fix build errors
techknowlogick Jun 8, 2018
1d74ce3
make fmt
techknowlogick Jun 8, 2018
79131fc
Update string per @BKC's suggestion
techknowlogick Jun 8, 2018
6d87477
Use UpdatedUnix instead of just Updated
techknowlogick Jun 8, 2018
9c797ba
use TimeSinceUnix instead of TimeSince
techknowlogick Jun 8, 2018
79401e3
add migration
techknowlogick Jun 8, 2018
df88dbf
Merge branch 'feature_AllowPrivateOrganization' of github.com:DblK/gi…
techknowlogick Jun 8, 2018
b1a19ef
fix migration
techknowlogick Jun 8, 2018
af87b29
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Jun 8, 2018
c850416
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Jun 9, 2018
059dba5
update date
techknowlogick Jun 9, 2018
8a36cf2
update with suggested code
techknowlogick Jun 11, 2018
c0fa0de
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Jun 11, 2018
819085a
prepare for conflict resolution
techknowlogick Jun 29, 2018
917cf76
Merge remote-tracking branch 'upstream/master' into feature_AllowPriv…
techknowlogick Jun 29, 2018
0b0b603
hide org profile page if needed when directly accessed
techknowlogick Jun 29, 2018
6db8162
hide repo if hidden
techknowlogick Jun 29, 2018
d4c6367
Chose visibility when creating org
techknowlogick Jun 29, 2018
7ee585f
fix build error
techknowlogick Jun 29, 2018
87f16f9
add copyright
techknowlogick Jun 29, 2018
f884657
add copyright
techknowlogick Jun 29, 2018
38556b9
update copyright
techknowlogick Jun 29, 2018
e46bd24
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Jul 13, 2018
0e546f1
Merge remote-tracking branch 'upstream/master' into feature_AllowPriv…
techknowlogick Jul 14, 2018
250f858
add checks to api & some tests
techknowlogick Jul 14, 2018
a60f4be
make fmt
techknowlogick Jul 14, 2018
502fed5
add copyright
techknowlogick Jul 14, 2018
4a1e0bd
add copyright
techknowlogick Jul 14, 2018
28fc8f0
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Jul 14, 2018
36d9124
rename migration
techknowlogick Jul 21, 2018
5a69b47
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Jul 21, 2018
5df42b4
make fmt
techknowlogick Jul 21, 2018
285b47b
Rename v71.go to v77.go
techknowlogick Jan 4, 2019
e3a4a08
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Jan 4, 2019
d434cec
make fmt fix
techknowlogick Jan 4, 2019
06a7d56
Update user.go
techknowlogick Jan 4, 2019
8f4f59d
resolve @bkcsoft feedback
techknowlogick Jan 4, 2019
24d2e48
Update org.go
techknowlogick Jan 4, 2019
0ed54b6
step before merge master
techknowlogick Jan 22, 2019
f8977ad
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Jan 22, 2019
20d33dd
make fmt
techknowlogick Jan 22, 2019
e9a1664
add sql queries
techknowlogick Jan 22, 2019
25dcc39
Merge branch 'feature_AllowPrivateOrganization' of github.com:DblK/gi…
techknowlogick Jan 22, 2019
c424cc3
remove TODO
techknowlogick Jan 22, 2019
1538c29
Fix Tests
techknowlogick Jan 22, 2019
878b887
accept post field on create
techknowlogick Jan 22, 2019
b5faeaf
add func per BKC feedback
techknowlogick Jan 22, 2019
cda121f
add comment to func
techknowlogick Jan 22, 2019
1e237d4
update per BKC feedback
techknowlogick Jan 22, 2019
15f4c95
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Jan 23, 2019
6f4da0b
update year
techknowlogick Jan 23, 2019
bc208a7
update year
techknowlogick Jan 23, 2019
9df3bf0
update year
techknowlogick Jan 23, 2019
16f4012
update year
techknowlogick Jan 23, 2019
b7f88b2
add copyright
techknowlogick Jan 23, 2019
51a10cd
update year
techknowlogick Jan 23, 2019
7c04589
update year
techknowlogick Jan 23, 2019
99bad71
Update year
techknowlogick Jan 23, 2019
a085b47
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Jan 28, 2019
fd24c9f
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Jan 28, 2019
f9122f3
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Jan 30, 2019
829e9f2
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Jan 31, 2019
70471ab
Update app.ini.sample
techknowlogick Jan 31, 2019
f32baca
Update setting.go
techknowlogick Jan 31, 2019
d6241c8
Add docs
techknowlogick Jan 31, 2019
b66b8f0
Update org.go
techknowlogick Jan 31, 2019
1d48754
Update user.go
techknowlogick Jan 31, 2019
8be87bc
Update modules/setting/setting.go
techknowlogick Jan 31, 2019
a100940
Update to use constants
techknowlogick Jan 31, 2019
8ea71f6
remove redundant conditional
techknowlogick Jan 31, 2019
a68ecf9
split up func for has visibility
techknowlogick Feb 1, 2019
17e3a38
combine conditional
techknowlogick Feb 1, 2019
cf3b71b
refactor structs into new package
techknowlogick Feb 1, 2019
fd51d42
fix syntax
techknowlogick Feb 1, 2019
eed990a
export struct
techknowlogick Feb 1, 2019
8826686
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 1, 2019
3a3a1cb
fix query & template - still more todo
techknowlogick Feb 1, 2019
0d1cd97
Merge branch 'feature_AllowPrivateOrganization' of github.com:DblK/gi…
techknowlogick Feb 1, 2019
4ed648e
reset before sql changes
techknowlogick Feb 1, 2019
0483344
try to fix mssql
techknowlogick Feb 1, 2019
e67cbd0
repo SQL
techknowlogick Feb 2, 2019
9cd145c
remove TODO comment
techknowlogick Feb 2, 2019
0159beb
make fmt
techknowlogick Feb 2, 2019
8d26cb6
fix spacing
techknowlogick Feb 2, 2019
45b706c
more spacing
techknowlogick Feb 2, 2019
14e6d04
try different sql join
techknowlogick Feb 2, 2019
5e02b7b
make fmt
techknowlogick Feb 2, 2019
30bdaa0
correct capitalization
techknowlogick Feb 2, 2019
2ffc296
resolve postgresql errors
techknowlogick Feb 2, 2019
7f63414
more psql fixes
techknowlogick Feb 2, 2019
78ed0a7
SQL
techknowlogick Feb 2, 2019
97802f2
psql
techknowlogick Feb 2, 2019
ac9aad0
fix mysql
techknowlogick Feb 2, 2019
373e1f5
work for all DB types
techknowlogick Feb 2, 2019
da64f72
work on all DBs hopefully
techknowlogick Feb 2, 2019
64af3a6
mssql
techknowlogick Feb 2, 2019
d22dff8
mssql
techknowlogick Feb 2, 2019
55cba7c
Update config-cheat-sheet.en-us.md
techknowlogick Feb 2, 2019
655c772
Update user.go
techknowlogick Feb 2, 2019
3a5d9ad
Update structs.go
techknowlogick Feb 2, 2019
3e236c5
Delete v79.go
techknowlogick Feb 2, 2019
148039e
Update migrations.go
techknowlogick Feb 2, 2019
996ee26
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 2, 2019
fc19628
Update user.go
techknowlogick Feb 2, 2019
35c4175
Update user.go
techknowlogick Feb 2, 2019
907a5ba
update per feedback
techknowlogick Feb 2, 2019
583a400
fix comment
techknowlogick Feb 2, 2019
c8cbf1f
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 3, 2019
b4b6871
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 4, 2019
a10dfae
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 4, 2019
4fce179
Update org.go
techknowlogick Feb 4, 2019
c8b844f
Update repo.go
techknowlogick Feb 4, 2019
7f05374
Update view.go
techknowlogick Feb 4, 2019
f94e040
Update home.go
techknowlogick Feb 4, 2019
7082b4a
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 4, 2019
b1f7a5d
Update list.tmpl
techknowlogick Feb 4, 2019
ec4b110
Update profile.tmpl
techknowlogick Feb 4, 2019
54ddf81
Update options.tmpl
techknowlogick Feb 4, 2019
caf2acf
Update create.tmpl
techknowlogick Feb 4, 2019
881db82
Update repo_list.tmpl
techknowlogick Feb 4, 2019
87d8463
Update create.tmpl
techknowlogick Feb 4, 2019
f33a083
Update organizations.tmpl
techknowlogick Feb 4, 2019
5b18778
Update list.tmpl
techknowlogick Feb 4, 2019
be4f405
Update options.tmpl
techknowlogick Feb 4, 2019
39e8464
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 5, 2019
9462c2d
Update structs.go
techknowlogick Feb 6, 2019
46c75f3
move structs to structs package
techknowlogick Feb 6, 2019
3fcebe6
Update repo_list.go
techknowlogick Feb 6, 2019
88d250a
Update org.go
techknowlogick Feb 6, 2019
1afc055
update per @lunny feedback
techknowlogick Feb 6, 2019
dfc6679
split up lines
techknowlogick Feb 6, 2019
ec77786
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 6, 2019
0f99946
fix build
techknowlogick Feb 6, 2019
f6a85ea
Merge branch 'feature_AllowPrivateOrganization' of github.com:DblK/gi…
techknowlogick Feb 6, 2019
c8e22a8
fix build issues
techknowlogick Feb 6, 2019
3423b2e
Update create.tmpl
techknowlogick Feb 6, 2019
3994a5a
Update repo_list.tmpl
techknowlogick Feb 6, 2019
bd0add3
update templates
techknowlogick Feb 6, 2019
955ff90
update templates
techknowlogick Feb 6, 2019
eb4e19d
rename DefaultVisibility to DefaultOrgVisibility
techknowlogick Feb 6, 2019
2c19f68
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 6, 2019
7a03024
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 7, 2019
91db977
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 7, 2019
3ff683e
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 9, 2019
69e9bad
Merge remote-tracking branch 'upstream/master' into feature_AllowPriv…
techknowlogick Feb 10, 2019
fae9107
fix build
techknowlogick Feb 10, 2019
58e5585
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 10, 2019
bda7c8d
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 11, 2019
7cae78f
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 11, 2019
c9595fc
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 13, 2019
9db666c
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 13, 2019
c165437
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 14, 2019
dee33fc
Merge branch 'master' into feature_AllowPrivateOrganization
techknowlogick Feb 14, 2019
958530a
Merge branch 'master' into feature_AllowPrivateOrganization
lunny Feb 17, 2019
b7c26e1
Merge branch 'master' into feature_AllowPrivateOrganization
lunny Feb 18, 2019
e6891d9
Merge branch 'master' into feature_AllowPrivateOrganization
lafriks Feb 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions custom/conf/app.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ DEFAULT_KEEP_EMAIL_PRIVATE = false
; Default value for AllowCreateOrganization
; Every new user will have rights set to create organizations depending on this setting
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
; Either "public", "limited" or "private", default is "public"
; Limited is for signed user only
; Private is only for member of the organization
; Public is for everyone
DEFAULT_VISIBILITY = public
; Enable Timetracking
ENABLE_TIMETRACKING = true
; Default value for EnableTimetracking
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ var migrations = []Migration{
NewMigration("add u2f", addU2FReg),
// v66 -> v67
NewMigration("add login source id column for public_key table", addLoginSourceIDToPublicKeyTable),
// v67 -> v68
NewMigration("add visibility for user and org", addVisibilityForUserAndOrg),
}

// Migrate database to current version
Expand Down
22 changes: 22 additions & 0 deletions models/migrations/v67.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package migrations

import (
"fmt"

"github.com/go-xorm/xorm"
)

func addVisibilityForUserAndOrg(x *xorm.Engine) error {
type User struct {
Visibility int `xorm:"NOT NULL DEFAULT 1"`
}

if err := x.Sync2(new(User)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}
return nil
}
39 changes: 39 additions & 0 deletions models/org.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
// Copyright 2018 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

Expand All @@ -11,6 +12,7 @@ import (
"strings"

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"

"github.com/Unknwon/com"
"github.com/go-xorm/builder"
Expand Down Expand Up @@ -125,6 +127,7 @@ func CreateOrganization(org, owner *User) (err error) {
org.NumTeams = 1
org.NumMembers = 1
org.Type = UserTypeOrganization
org.Visibility = VisibleType(setting.Service.DefaultVisibilityMode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One is not able to set it when it's being created? What if the default is "public" and you want it "private"? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can still change it after anyway. I do not remember this code. Need deeper look

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkcsoft fixed. User can now chose visibility when creating org.


sess := x.NewSession()
defer sess.Close()
Expand Down Expand Up @@ -351,6 +354,42 @@ func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {
Find(&orgs)
}

// HasOrgVisible tell if the given user can see one of the given orgs
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
func HasOrgVisible(orgs []*User, user *User) bool {
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
if len(orgs) == 0 {
return false
}

// Not SignedUser
if user == nil {
for _, org := range orgs {
if org.Visibility == 1 {
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
return true
}
}
return false
}

if user.IsAdmin {
return true
}
for _, org := range orgs {
switch org.Visibility {
case VisibleTypePublic:
return true
case VisibleTypeLimited:
return true
case VisibleTypePrivate:
if org.IsUserOrgPartOf(user.ID) {
return true
}
default:
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
}
}

return false
}

// GetOwnedOrgsByUserID returns a list of organizations are owned by given user ID.
func GetOwnedOrgsByUserID(userID int64) ([]*User, error) {
sess := x.NewSession()
Expand Down
29 changes: 27 additions & 2 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ var (
ErrUnsupportedLoginType = errors.New("Login source is unknown")
)

// VisibleType define the visibility (Organization only)
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
type VisibleType int

const (
// VisibleTypePublic Visible for everyone
VisibleTypePublic VisibleType = iota + 1
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved

// VisibleTypeLimited Visible for every connected user
VisibleTypeLimited

// VisibleTypePrivate Visible only for organization's members
VisibleTypePrivate
)

// User represents the object of individual and member of organization.
type User struct {
ID int64 `xorm:"pk autoincr"`
Expand Down Expand Up @@ -128,8 +142,9 @@ type User struct {
Description string
NumTeams int
NumMembers int
Teams []*Team `xorm:"-"`
Members []*User `xorm:"-"`
Teams []*Team `xorm:"-"`
Members []*User `xorm:"-"`
Visibility VisibleType `xorm:"DEFAULT 1"`
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved

// Preferences
DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
Expand Down Expand Up @@ -519,6 +534,16 @@ func (u *User) IsUserOrgOwner(orgID int64) bool {
return isOwner
}

// IsUserOrgPartOf returns true if user is part of the organization
func (u *User) IsUserOrgPartOf(userID int64) bool {
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
isMember, err := IsOrganizationMember(u.ID, userID)
if err != nil {
log.Error(4, "IsOrganizationMember: %v", err)
return false
}
return isMember
}

// IsPublicMember returns true if user public his/her membership in given organization.
func (u *User) IsPublicMember(orgID int64) bool {
isMember, err := IsPublicMembership(orgID, u.ID)
Expand Down
1 change: 1 addition & 0 deletions modules/auth/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type UpdateOrgSettingForm struct {
Description string `binding:"MaxSize(255)"`
Website string `binding:"ValidUrl;MaxSize(255)"`
Location string `binding:"MaxSize(50)"`
Visibility models.VisibleType
MaxRepoCreation int
}

Expand Down
10 changes: 10 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,8 @@ func NewContext() {

// Service settings
var Service struct {
DefaultVisibility string
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
DefaultVisibilityMode int
ActiveCodeLives int
ResetPwdCodeLives int
RegisterEmailConfirm bool
Expand All @@ -1175,6 +1177,12 @@ var Service struct {
OpenIDBlacklist []*regexp.Regexp
}

var visibilityModes = map[string]int{
"public": 1,
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
"limited": 2,
"private": 3,
}

func newService() {
sec := Cfg.Section("service")
Service.ActiveCodeLives = sec.Key("ACTIVE_CODE_LIVE_MINUTES").MustInt(180)
Expand All @@ -1194,6 +1202,8 @@ func newService() {
}
Service.DefaultAllowOnlyContributorsToTrackTime = sec.Key("DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME").MustBool(true)
Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org")
Service.DefaultVisibility = sec.Key("DEFAULT_VISIBILITY").In("public", []string{"public", "limited", "private"})
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
Service.DefaultVisibilityMode = visibilityModes[Service.DefaultVisibility]

sec = Cfg.Section("openid")
Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock)
Expand Down
6 changes: 6 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,11 @@ settings.options = Organization
settings.full_name = Full Name
settings.website = Website
settings.location = Location
settings.visibility = Visibility
settings.visibility.public = Public
settings.visibility.limited = Limited (Visible to logged in users only)
settings.visibility.private = Private (Visible only to organization members)

settings.update_settings = Update Settings
settings.update_setting_success = Organization settings have been updated.
settings.change_orgname_prompt = Note: changing the organization name also changes the organization's URL.
Expand Down Expand Up @@ -1496,6 +1501,7 @@ config.enable_timetracking = Enable Time Tracking
config.default_enable_timetracking = Enable Time Tracking by Default
config.default_allow_only_contributors_to_track_time = Let Only Contributors Track Time
config.no_reply_address = Hidden Email Domain
config.default_visibility_organization = Default visibility for new Organizations

config.webhook_config = Webhook Configuration
config.queue_length = Queue Length
Expand Down
2 changes: 2 additions & 0 deletions routers/org/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
func Settings(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("org.settings")
ctx.Data["PageIsSettingsOptions"] = true
ctx.Data["CurrentVisibility"] = models.VisibleType(ctx.Org.Organization.Visibility)
ctx.HTML(200, tplSettingsOptions)
}

Expand Down Expand Up @@ -79,6 +80,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
org.Description = form.Description
org.Website = form.Website
org.Location = form.Location
org.Visibility = form.Visibility
if err := models.UpdateUser(org); err != nil {
ctx.ServerError("UpdateUser", err)
return
Expand Down
2 changes: 2 additions & 0 deletions routers/user/profile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2015 The Gogs Authors. All rights reserved.
// Copyright 2017 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -96,6 +97,7 @@ func Profile(ctx *context.Context) {
}

ctx.Data["Orgs"] = orgs
ctx.Data["HasOrgsVisible"] = models.HasOrgVisible(orgs, ctx.User)

tab := ctx.Query("tab")
ctx.Data["TabName"] = tab
Expand Down
3 changes: 3 additions & 0 deletions templates/admin/config.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
<dt>{{.i18n.Tr "admin.config.default_allow_only_contributors_to_track_time"}}</dt>
<dd><i class="fa fa{{if .Service.DefaultAllowOnlyContributorsToTrackTime}}-check{{end}}-square-o"></i></dd>
{{end}}
<dt>{{.i18n.Tr "admin.config.default_visibility_organization"}}</dt>
<dd>{{.Service.DefaultVisibility}}</dd>

<dt>{{.i18n.Tr "admin.config.no_reply_address"}}</dt>
<dd>{{if .Service.NoReplyAddress}}{{.Service.NoReplyAddress}}{{else}}-{{end}}</dd>
<div class="ui divider"></div>
Expand Down
7 changes: 6 additions & 1 deletion templates/admin/org/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
{{range .Users}}
<tr>
<td>{{.ID}}</td>
<td><a href="{{.HomeLink}}">{{.Name}}</a></td>
<td>
<a href="{{.HomeLink}}">{{.Name}}</a>
{{if eq .Visibility 3}}
<span class="text gold"><i class="octicon octicon-lock"></i></span>
{{end}}
</td>
<td>{{.NumTeams}}</td>
<td>{{.NumMembers}}</td>
<td>{{.NumRepos}}</td>
Expand Down
7 changes: 6 additions & 1 deletion templates/admin/repo/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
{{range .Repos}}
<tr>
<td>{{.ID}}</td>
<td><a href="{{AppSubUrl}}/{{.Owner.Name}}">{{.Owner.Name}}</a></td>
<td>
<a href="{{AppSubUrl}}/{{.Owner.Name}}">{{.Owner.Name}}</a>
{{if eq .Owner.Visibility 3}}
<span class="text gold"><i class="octicon octicon-lock"></i></span>
{{end}}
</td>
<td><a href="{{AppSubUrl}}/{{.Owner.Name}}/{{.Name}}">{{.Name}}</a></td>
<td><i class="fa fa{{if .IsPrivate}}-check{{end}}-square-o"></i></td>
<td>{{.NumWatches}}</td>
Expand Down
9 changes: 8 additions & 1 deletion templates/explore/organizations.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@

<div class="ui user list">
{{range .Users}}
{{if (or (eq .Visibility 1) (and ($.SignedUser) (or (eq .Visibility 2) (and (.IsUserOrgPartOf $.SignedUserID) (eq .Visibility 3)) ($.IsAdmin))))}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break paging as if most organizations are private can be that you will get empty pages or pages with very few orgs in it. These conditions should be already part of database query

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, when I did that I did not have that many user so did not see the pages. Everything was one page. Agree with your solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DblK I've just resolved the latest conflicts. I'm going on vacation until mid-august, do you want to take over this PR again, and add in the SQL conditions?

<div class="item">
<img class="ui avatar image" src="{{.RelAvatarLink}}">
<div class="content">
<span class="header"><a href="{{.HomeLink}}">{{.Name}}</a> {{.FullName}}</span>
<span class="header">
<a href="{{.HomeLink}}">{{.Name}}</a> {{.FullName}}
{{if eq .Visibility 3}}
<span class="text gold"><i class="octicon octicon-lock"></i></span>
{{end}}
</span>
<div class="description">
{{if .Location}}
<i class="octicon octicon-location"></i> {{.Location}}
Expand All @@ -22,6 +28,7 @@
</div>
</div>
</div>
{{end}}
{{else}}
<div>{{$.i18n.Tr "explore.org_no_results"}}</div>
{{end}}
Expand Down
11 changes: 8 additions & 3 deletions templates/explore/repo_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
<span><i class="octicon octicon-repo-forked"></i></span>
{{else if .IsMirror}}
<span><i class="octicon octicon-repo-clone"></i></span>
{{else if eq .Owner.Visibility 3}}
Copy link
Contributor

@scr34m scr34m Jun 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra test required because .Owner is not defined then an error occur <.Owner.Visibility>: can't evaluate field Visibility in type *models.User

Possible solution:

{{else if .Owner}}
    {{if eq .Owner.Visibility 3}}
        <span class="text gold"><i class="octicon octicon-lock"></i></span>
    {{end}}
{{end}}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @scr34m I've just updated the template

<span class="text gold"><i class="octicon octicon-lock"></i></span>
{{end}}

<div class="ui right metas">
<span class="text grey"><i class="octicon octicon-star"></i> {{.NumStars}}</span>
<span class="text grey"><i class="octicon octicon-git-branch"></i> {{.NumForks}}</span>
<div class="ui right metas">
<span class="text grey"><i class="octicon octicon-star"></i> {{.NumStars}}</span>
<span class="text grey"><i class="octicon octicon-git-branch"></i> {{.NumForks}}</span>
</div>
</div>
{{if .DescriptionHTML}}<p class="has-emoji">{{.DescriptionHTML}}</p>{{end}}
<p class="time">{{$.i18n.Tr "org.repo_updated"}} {{TimeSinceUnix .UpdatedUnix $.i18n.Lang}}</p>
</div>
{{if .DescriptionHTML}}<p class="has-emoji">{{.DescriptionHTML}}</p>{{end}}
{{if .Topics }}
Expand Down
23 changes: 23 additions & 0 deletions templates/org/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@
<input id="location" name="location" value="{{.Org.Location}}">
</div>

<div class="ui divider"></div>
<div class="field" id="visibility_box">
<label for="visibility">{{.i18n.Tr "org.settings.visibility"}}</label>
<div class="field">
<div class="ui radio checkbox">
<input class="hidden enable-system-radio" tabindex="0" name="visibility" type="radio" value="1" {{if eq .CurrentVisibility 1}}checked{{end}}/>
<label>{{.i18n.Tr "org.settings.visibility.public"}}</label>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
<input class="hidden enable-system-radio" tabindex="0" name="visibility" type="radio" value="2" {{if eq .CurrentVisibility 2}}checked{{end}}/>
<label>{{.i18n.Tr "org.settings.visibility.limited"}}</label>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
<input class="hidden enable-system-radio" tabindex="0" name="visibility" type="radio" value="3" {{if eq .CurrentVisibility 3}}checked{{end}}/>
<label>{{.i18n.Tr "org.settings.visibility.private"}}</label>
</div>
</div>
</div>

{{if .SignedUser.IsAdmin}}
<div class="ui divider"></div>

Expand Down
6 changes: 4 additions & 2 deletions templates/user/profile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@
</a>
</li>
*/}}
{{if .Orgs}}
{{if and .Orgs .HasOrgsVisible}}
<li>
{{range .Orgs}}
<a href="{{.HomeLink}}"><img class="ui mini image poping up" src="{{.RelAvatarLink}}" data-content="{{.Name}}" data-position="top center" data-variation="tiny inverted"></a>
{{if (or (eq .Visibility 1) (and ($.SignedUser) (or (eq .Visibility 2) (and (.IsUserOrgPartOf $.SignedUserID) (eq .Visibility 3)) ($.IsAdmin))))}}
<a href="{{.HomeLink}}"><img class="ui mini image poping up" src="{{.RelAvatarLink}}" data-content="{{.Name}}" data-position="top center" data-variation="tiny inverted"></a>
{{end}}
{{end}}
</li>
{{end}}
Expand Down