From c2a75b3762fbaf949cd8f12a6aa7c0989d274e24 Mon Sep 17 00:00:00 2001 From: Remy Boulanouar Date: Fri, 19 May 2017 16:57:27 +0200 Subject: [PATCH 01/33] Add UI visibility in organization settings --- models/user.go | 19 +++++++++++++++++-- modules/auth/org.go | 1 + options/locale/locale_en-US.ini | 7 ++++++- routers/org/setting.go | 2 ++ templates/org/settings/options.tmpl | 23 +++++++++++++++++++++++ 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/models/user.go b/models/user.go index 7e6bbd5dc..8c136e25f 100644 --- a/models/user.go +++ b/models/user.go @@ -72,6 +72,20 @@ var ( ErrUnsupportedLoginType = errors.New("Login source is unknown") ) +// VisibleType define the visibility (Organization only) +type VisibleType int + +const ( + // VisibleType Visible for everyone + VisibleTypePublic VisibleType = iota + 1 + + // 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"` @@ -129,8 +143,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"` // Preferences DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"` diff --git a/modules/auth/org.go b/modules/auth/org.go index d6c26b633..f1f5e17a0 100644 --- a/modules/auth/org.go +++ b/modules/auth/org.go @@ -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 } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 75f02a626..b5688e1c5 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -992,6 +992,11 @@ settings.options = Options settings.full_name = Full Name settings.website = Website settings.location = Location +settings.visibility = Visibility +settings.visibility.public = Public +settings.visibility.limited = Limited (Visible to connected user 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 = This change will change the links to the organization. @@ -1424,4 +1429,4 @@ error.failed_retrieval_gpg_keys = "Failed to retrieve any key attached to the co [units] error.no_unit_allowed_repo = Cannot find any unit allowed on this repository -error.unit_not_allowed = You have not allowed to visit this repository unit \ No newline at end of file +error.unit_not_allowed = You have not allowed to visit this repository unit diff --git a/routers/org/setting.go b/routers/org/setting.go index 4faed77d0..47235fcaf 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -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) } @@ -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.Handle(500, "UpdateUser", err) return diff --git a/templates/org/settings/options.tmpl b/templates/org/settings/options.tmpl index 804136543..07941988d 100644 --- a/templates/org/settings/options.tmpl +++ b/templates/org/settings/options.tmpl @@ -33,6 +33,29 @@ +
+
+ +
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ {{if .SignedUser.IsAdmin}}
From 4df763c3b11c77a1c5ed034e321d8d3ef358762f Mon Sep 17 00:00:00 2001 From: Remy Boulanouar Date: Fri, 19 May 2017 17:02:29 +0200 Subject: [PATCH 02/33] Set Visibility Public by default when creating new organization --- models/org.go | 1 + 1 file changed, 1 insertion(+) diff --git a/models/org.go b/models/org.go index fb07c4aaf..dfe11c6e4 100644 --- a/models/org.go +++ b/models/org.go @@ -125,6 +125,7 @@ func CreateOrganization(org, owner *User) (err error) { org.NumTeams = 1 org.NumMembers = 1 org.Type = UserTypeOrganization + org.Visibility = VisibleTypePublic sess := x.NewSession() defer sessionRelease(sess) From 9d73ff4b3e8c71e040adf1ca27703230d529bff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Boulanouar?= Date: Sun, 21 May 2017 21:32:38 +0200 Subject: [PATCH 03/33] Implement visibility in explore/organizations --- models/user.go | 7 ++++++- modules/context/context.go | 2 +- templates/explore/organizations.tmpl | 9 ++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/models/user.go b/models/user.go index 8c136e25f..4203b54b7 100644 --- a/models/user.go +++ b/models/user.go @@ -76,7 +76,7 @@ var ( type VisibleType int const ( - // VisibleType Visible for everyone + // VisibleTypePublic Visible for everyone VisibleTypePublic VisibleType = iota + 1 // VisibleTypeLimited Visible for every connected user @@ -521,6 +521,11 @@ func (u *User) IsUserOrgOwner(orgID int64) bool { return IsOrganizationOwner(orgID, u.ID) } +// IsUserOrgPartOf returns true if user is part of the organization +func (u *User) IsUserOrgPartOf(userID int64) bool { + return IsOrganizationMember(u.ID, userID) +} + // IsPublicMember returns true if user public his/her membership in given organization. func (u *User) IsPublicMember(orgID int64) bool { return IsPublicMembership(orgID, u.ID) diff --git a/modules/context/context.go b/modules/context/context.go index e96bf5bd3..f0d2c473b 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -175,7 +175,7 @@ func Contexter() macaron.Handler { ctx.Data["SignedUserName"] = ctx.User.Name ctx.Data["IsAdmin"] = ctx.User.IsAdmin } else { - ctx.Data["SignedUserID"] = 0 + ctx.Data["SignedUserID"] = int64(0) ctx.Data["SignedUserName"] = "" } diff --git a/templates/explore/organizations.tmpl b/templates/explore/organizations.tmpl index 4b1ab1834..d753a1ba6 100644 --- a/templates/explore/organizations.tmpl +++ b/templates/explore/organizations.tmpl @@ -6,10 +6,16 @@
{{range .Users}} + {{if (or (eq .Visibility 1) (and ($.SignedUser) (or (eq .Visibility 2) (and (.IsUserOrgPartOf $.SignedUserID) (eq .Visibility 3)) ($.IsAdmin))))}}
- {{.Name}} {{.FullName}} + + {{.Name}} {{.FullName}} + {{if eq .Visibility 3}} + + {{end}} +
{{if .Location}} {{.Location}} @@ -22,6 +28,7 @@
+ {{end}} {{else}}
{{$.i18n.Tr "explore.org_no_results"}}
{{end}} From 7bdc6e8bbc2825b8cd9acc25b2dfa0d19853656a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Boulanouar?= Date: Sun, 21 May 2017 22:38:18 +0200 Subject: [PATCH 04/33] Implement visibility in explore/repos --- templates/explore/repo_list.tmpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index 76ed6491f..ed3a907f7 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -1,5 +1,6 @@
{{range .Repos}} + {{if (or (eq .Owner.Visibility 1) (and ($.SignedUser) (or (eq .Owner.Visibility 2) (and (.Owner.IsUserOrgPartOf $.SignedUserID) (eq .Owner.Visibility 3)) ($.IsAdmin))))}}
{{if or $.PageIsExplore $.PageIsProfileStarList }}{{.Owner.Name}} / {{end}}{{.Name}} @@ -19,6 +20,7 @@ {{if .DescriptionHTML}}

{{.DescriptionHTML}}

{{end}}

{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}

+ {{end}} {{else}}
{{$.i18n.Tr "explore.repo_no_results"}} From fb0c45abb13dd6e225a60ca4666dea618a391a62 Mon Sep 17 00:00:00 2001 From: Remy Boulanouar Date: Mon, 22 May 2017 12:00:08 +0200 Subject: [PATCH 05/33] Implement global configuration for new organizations --- conf/app.ini | 5 +++++ models/org.go | 4 +++- modules/setting/setting.go | 10 ++++++++++ options/locale/locale_en-US.ini | 1 + templates/admin/config.tmpl | 3 +++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/conf/app.ini b/conf/app.ini index 106e0ea2c..a458a316d 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -245,6 +245,11 @@ DEFAULT_KEEP_EMAIL_PRIVATE = false ; Default value for AllowCreateOrganization ; 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 ; Default value for the domain part of the user's email address in the git log ; if he has set KeepEmailPrivate true. The user's email replaced with a ; concatenation of the user name in lower case, "@" and NO_REPLY_ADDRESS. diff --git a/models/org.go b/models/org.go index dfe11c6e4..243a4aa02 100644 --- a/models/org.go +++ b/models/org.go @@ -10,6 +10,8 @@ import ( "os" "strings" + "code.gitea.io/gitea/modules/setting" + "github.com/Unknwon/com" "github.com/go-xorm/builder" "github.com/go-xorm/xorm" @@ -125,7 +127,7 @@ func CreateOrganization(org, owner *User) (err error) { org.NumTeams = 1 org.NumMembers = 1 org.Type = UserTypeOrganization - org.Visibility = VisibleTypePublic + org.Visibility = VisibleType(setting.Service.DefaultVisibilityMode) sess := x.NewSession() defer sessionRelease(sess) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 4acad4239..7fd9cdb55 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -991,6 +991,8 @@ var Service struct { DefaultKeepEmailPrivate bool DefaultAllowCreateOrganization bool NoReplyAddress string + DefaultVisibility string + DefaultVisibilityMode int // OpenID settings EnableOpenIDSignIn bool @@ -999,6 +1001,12 @@ var Service struct { OpenIDBlacklist []*regexp.Regexp } +var visibilityModes = map[string]int{ + "public": 1, + "limited": 2, + "private": 3, +} + func newService() { sec := Cfg.Section("service") Service.ActiveCodeLives = sec.Key("ACTIVE_CODE_LIVE_MINUTES").MustInt(180) @@ -1012,6 +1020,8 @@ func newService() { Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool() Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").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"}) + Service.DefaultVisibilityMode = visibilityModes[Service.DefaultVisibility] sec = Cfg.Section("openid") Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(false) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index b5688e1c5..3831e5c2c 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1286,6 +1286,7 @@ config.active_code_lives = Active Code Lives config.reset_password_code_lives = Reset Password Code Expiry Time config.default_keep_email_private = Default Value for Keep Email Private config.default_allow_create_organization = Default permission to create Organizations +config.default_visibility_organization = Default visibility for new Organizations config.no_reply_address = No-reply Address config.webhook_config = Webhook Configuration diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl index 0fbd0befc..8f81865bb 100644 --- a/templates/admin/config.tmpl +++ b/templates/admin/config.tmpl @@ -130,6 +130,9 @@
{{.i18n.Tr "admin.config.default_allow_create_organization"}}
+
{{.i18n.Tr "admin.config.default_visibility_organization"}}
+
{{.Service.DefaultVisibility}}
+
{{.i18n.Tr "admin.config.no_reply_address"}}
{{if .Service.NoReplyAddress}}{{.Service.NoReplyAddress}}{{else}}-{{end}}
From 90ec0302a3aae204c5d65cba9005ba5ac759f312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Boulanouar?= Date: Mon, 22 May 2017 19:42:21 +0200 Subject: [PATCH 06/33] Add in admin/repos and admin/org gold lock icons for private organization --- templates/admin/org/list.tmpl | 7 ++++++- templates/admin/repo/list.tmpl | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl index 362352b69..aa9cd79e8 100644 --- a/templates/admin/org/list.tmpl +++ b/templates/admin/org/list.tmpl @@ -29,7 +29,12 @@ {{range .Users}} {{.ID}} - {{.Name}} + + {{.Name}} + {{if eq .Visibility 3}} + + {{end}} + {{.NumTeams}} {{.NumMembers}} {{.NumRepos}} diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index aeaecf8df..21a0afed6 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -29,7 +29,12 @@ {{range .Repos}} {{.ID}} - {{.Owner.Name}} + + {{.Owner.Name}} + {{if eq .Owner.Visibility 3}} + + {{end}} + {{.Name}} {{.NumWatches}} From 8eaddfc86b349fda1f379d1acd551b7f9fa2f3a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Boulanouar?= Date: Mon, 22 May 2017 19:43:06 +0200 Subject: [PATCH 07/33] Handle display of repositories from explore/repo and when viewing an organization --- templates/explore/repo_list.tmpl | 80 +++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 17 deletions(-) diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index ed3a907f7..3c8753c36 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -1,25 +1,71 @@
{{range .Repos}} - {{if (or (eq .Owner.Visibility 1) (and ($.SignedUser) (or (eq .Owner.Visibility 2) (and (.Owner.IsUserOrgPartOf $.SignedUserID) (eq .Owner.Visibility 3)) ($.IsAdmin))))}} -
-
- {{if or $.PageIsExplore $.PageIsProfileStarList }}{{.Owner.Name}} / {{end}}{{.Name}} - {{if .IsPrivate}} - - {{else if .IsFork}} - - {{else if .IsMirror}} - - {{end}} + {{if .Owner}} + {{if (or (eq .Owner.Visibility 1) (and ($.SignedUser) (or (eq .Owner.Visibility 2) (and (.Owner.IsUserOrgPartOf $.SignedUserID) (eq .Owner.Visibility 3)) ($.IsAdmin))))}} +
+
+ {{if or $.PageIsExplore $.PageIsProfileStarList }}{{.Owner.Name}} / {{end}}{{.Name}} + {{if .IsPrivate}} + + {{else if .IsFork}} + + {{else if .IsMirror}} + + {{end}} -
- {{.NumStars}} - {{.NumForks}} +
+ {{.NumStars}} + {{.NumForks}} +
+ {{if .DescriptionHTML}}

{{.DescriptionHTML}}

{{end}} +

{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}

- {{if .DescriptionHTML}}

{{.DescriptionHTML}}

{{end}} -

{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}

-
+ {{end}} + {{else if $.Org}} + {{if (or (eq $.Org.Visibility 1) (and ($.SignedUser) (or (eq $.Org.Visibility 2) (and ($.Org.IsUserOrgPartOf $.SignedUserID) (eq $.Org.Visibility 3)) ($.IsAdmin))))}} +
+
+ {{if or $.PageIsExplore $.PageIsProfileStarList }}{{.Owner.Name}} / {{end}}{{.Name}} + {{if .IsPrivate}} + + {{else if .IsFork}} + + {{else if .IsMirror}} + + {{end}} + +
+ {{.NumStars}} + {{.NumForks}} +
+
+ {{if .DescriptionHTML}}

{{.DescriptionHTML}}

{{end}} +

{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}

+
+ {{end}} + {{else}} + {{if (or (eq $.Owner.Visibility 1) (and ($.SignedUser) (or (eq $.Owner.Visibility 2) (and ($.Owner.IsUserOrgPartOf $.SignedUserID) (eq $.Owner.Visibility 3)) ($.IsAdmin))))}} +
+
+ {{if or $.PageIsExplore $.PageIsProfileStarList }}{{.Owner.Name}} / {{end}}{{.Name}} + {{if .IsPrivate}} + + {{else if .IsFork}} + + {{else if .IsMirror}} + + {{end}} + +
+ {{.NumStars}} + {{.NumForks}} +
+
+ {{if .DescriptionHTML}}

{{.DescriptionHTML}}

{{end}} +

{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}

+
+ {{end}} {{end}} {{else}}
From 20e63bb47952c3d0ed56c9ccd60360621f2438ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Boulanouar?= Date: Tue, 23 May 2017 20:36:44 +0200 Subject: [PATCH 08/33] Add lock icon for private org on explore/repo --- templates/explore/repo_list.tmpl | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index 3c8753c36..b399732bb 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -4,7 +4,15 @@ {{if (or (eq .Owner.Visibility 1) (and ($.SignedUser) (or (eq .Owner.Visibility 2) (and (.Owner.IsUserOrgPartOf $.SignedUserID) (eq .Owner.Visibility 3)) ($.IsAdmin))))}}
- {{if or $.PageIsExplore $.PageIsProfileStarList }}{{.Owner.Name}} / {{end}}{{.Name}} + + {{if or $.PageIsExplore $.PageIsProfileStarList }} + {{.Owner.Name}} + {{if eq .Owner.Visibility 3}} + + {{end}} / + {{end}} + {{.Name}} + {{if .IsPrivate}} {{else if .IsFork}} @@ -26,7 +34,14 @@ {{if (or (eq $.Org.Visibility 1) (and ($.SignedUser) (or (eq $.Org.Visibility 2) (and ($.Org.IsUserOrgPartOf $.SignedUserID) (eq $.Org.Visibility 3)) ($.IsAdmin))))}}
- {{if or $.PageIsExplore $.PageIsProfileStarList }}{{.Owner.Name}} / {{end}}{{.Name}} + + {{if or $.PageIsExplore $.PageIsProfileStarList }} + {{.Owner.Name}} + {{if eq $.Org.Visibility 3}} + + {{end}} / + {{end}} + {{.Name}} {{if .IsPrivate}} {{else if .IsFork}} @@ -48,7 +63,15 @@ {{if (or (eq $.Owner.Visibility 1) (and ($.SignedUser) (or (eq $.Owner.Visibility 2) (and ($.Owner.IsUserOrgPartOf $.SignedUserID) (eq $.Owner.Visibility 3)) ($.IsAdmin))))}}
- {{if or $.PageIsExplore $.PageIsProfileStarList }}{{.Owner.Name}} / {{end}}{{.Name}} + + {{if or $.PageIsExplore $.PageIsProfileStarList }} + {{.Owner.Name}} + {{if eq $.Owner.Visibility 3}} + + {{end}} / + {{end}} + {{.Name}} + {{if .IsPrivate}} {{else if .IsFork}} From 15d9e00533adc6a6e4a052a0eed7b78ec40d3f31 Mon Sep 17 00:00:00 2001 From: Remy Boulanouar Date: Wed, 24 May 2017 16:18:09 +0200 Subject: [PATCH 09/33] User profile display organization based on Membership Visibility and Organization Visibility --- models/org.go | 37 +++++++++++++++++++++++++++++++++++++ routers/user/profile.go | 2 ++ templates/user/profile.tmpl | 6 ++++-- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/models/org.go b/models/org.go index 243a4aa02..968b6aff0 100644 --- a/models/org.go +++ b/models/org.go @@ -1,4 +1,5 @@ // Copyright 2014 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. @@ -368,6 +369,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 +func HasOrgVisible(orgs []*User, user *User) bool { + if len(orgs) == 0 { + return false + } + + // Not SignedUser + if user == nil { + for _, org := range orgs { + if org.Visibility == 1 { + 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: + } + } + + return false +} + // GetOwnedOrgsByUserID returns a list of organizations are owned by given user ID. func GetOwnedOrgsByUserID(userID int64) ([]*User, error) { sess := x.NewSession() diff --git a/routers/user/profile.go b/routers/user/profile.go index eb862d654..c4e03db4b 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -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. @@ -95,6 +96,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 diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index a055a99a8..3658a72ee 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -61,10 +61,12 @@ */}} - {{if .Orgs}} + {{if and .Orgs .HasOrgsVisible}}
  • {{range .Orgs}} - + {{if (or (eq .Visibility 1) (and ($.SignedUser) (or (eq .Visibility 2) (and (.IsUserOrgPartOf $.SignedUserID) (eq .Visibility 3)) ($.IsAdmin))))}} + + {{end}} {{end}}
  • {{end}} From 49e4008a40d3a8fa830489e6dfac86203ac8b43f Mon Sep 17 00:00:00 2001 From: Remy Boulanouar Date: Wed, 24 May 2017 16:26:42 +0200 Subject: [PATCH 10/33] Resolve Conflict for merging --- options/locale/locale_en-US.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 3831e5c2c..0fae6d3c7 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1429,5 +1429,5 @@ error.not_signed_commit = "Not a signed commit" error.failed_retrieval_gpg_keys = "Failed to retrieve any key attached to the committer account" [units] -error.no_unit_allowed_repo = Cannot find any unit allowed on this repository -error.unit_not_allowed = You have not allowed to visit this repository unit +error.no_unit_allowed_repo = Cannot find any unit on this repository which you are allowed to access +error.unit_not_allowed = You are not allowed to visit this repository unit From 86d1e787464d93d3982a36d9919511529cf411cd Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Fri, 8 Jun 2018 17:07:43 -0400 Subject: [PATCH 11/33] Fix build errors --- models/user.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/models/user.go b/models/user.go index 4d17a5040..7ee3fdd09 100644 --- a/models/user.go +++ b/models/user.go @@ -536,7 +536,12 @@ func (u *User) IsUserOrgOwner(orgID int64) bool { // IsUserOrgPartOf returns true if user is part of the organization func (u *User) IsUserOrgPartOf(userID int64) bool { - return IsOrganizationMember(u.ID, userID) + 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. From 1d74ce335ea7c38246d93d8f48994e5a2281b532 Mon Sep 17 00:00:00 2001 From: Gitea Date: Fri, 8 Jun 2018 17:10:27 -0400 Subject: [PATCH 12/33] make fmt --- modules/setting/setting.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 152f3a22a..714e659e1 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -1150,8 +1150,8 @@ func NewContext() { // Service settings var Service struct { - DefaultVisibility string - DefaultVisibilityMode int + DefaultVisibility string + DefaultVisibilityMode int ActiveCodeLives int ResetPwdCodeLives int RegisterEmailConfirm bool From 79131fce64b6221ba25862577ddb5c7dd047ff58 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Fri, 8 Jun 2018 17:16:59 -0400 Subject: [PATCH 13/33] Update string per @BKC's suggestion --- options/locale/locale_en-US.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index a529f5556..69526bbff 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1199,7 +1199,7 @@ settings.website = Website settings.location = Location settings.visibility = Visibility settings.visibility.public = Public -settings.visibility.limited = Limited (Visible to connected user only) +settings.visibility.limited = Limited (Visible to logged in users only) settings.visibility.private = Private (Visible only to organization members) settings.update_settings = Update Settings From 6d874777803a9ba72e1fb3f1d2de25986babae52 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Fri, 8 Jun 2018 17:37:06 -0400 Subject: [PATCH 14/33] Use UpdatedUnix instead of just Updated --- templates/explore/repo_list.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index 298e69be7..b9550c6ac 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -19,7 +19,7 @@
    {{if .DescriptionHTML}}

    {{.DescriptionHTML}}

    {{end}} -

    {{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}

    +

    {{$.i18n.Tr "org.repo_updated"}} {{TimeSince .UpdatedUnix $.i18n.Lang}}

    {{if .DescriptionHTML}}

    {{.DescriptionHTML}}

    {{end}} {{if .Topics }} From 9c797bad5bcd29b2f03ec90a5f8f0d7bdc6d0aa7 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Fri, 8 Jun 2018 17:55:43 -0400 Subject: [PATCH 15/33] use TimeSinceUnix instead of TimeSince --- templates/explore/repo_list.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index b9550c6ac..40f23e5b5 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -19,7 +19,7 @@
    {{if .DescriptionHTML}}

    {{.DescriptionHTML}}

    {{end}} -

    {{$.i18n.Tr "org.repo_updated"}} {{TimeSince .UpdatedUnix $.i18n.Lang}}

    +

    {{$.i18n.Tr "org.repo_updated"}} {{TimeSinceUnix .UpdatedUnix $.i18n.Lang}}

    {{if .DescriptionHTML}}

    {{.DescriptionHTML}}

    {{end}} {{if .Topics }} From 79401e39bda3de5a9372a21dfce8d03428190dad Mon Sep 17 00:00:00 2001 From: Gitea Date: Fri, 8 Jun 2018 19:07:54 -0400 Subject: [PATCH 16/33] add migration --- models/migrations/migrations.go | 2 ++ models/migrations/v67.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 models/migrations/v67.go diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 1300065ab..336260ed9 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -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 diff --git a/models/migrations/v67.go b/models/migrations/v67.go new file mode 100644 index 000000000..baca529c5 --- /dev/null +++ b/models/migrations/v67.go @@ -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(PublicKey)); err != nil { + return fmt.Errorf("Sync2: %v", err) + } + return nil +} From b1a19ef549246d01fa50ca972bb8c51c6ebb0f32 Mon Sep 17 00:00:00 2001 From: Gitea Date: Fri, 8 Jun 2018 19:20:20 -0400 Subject: [PATCH 17/33] fix migration --- models/migrations/v67.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/migrations/v67.go b/models/migrations/v67.go index baca529c5..48261b399 100644 --- a/models/migrations/v67.go +++ b/models/migrations/v67.go @@ -15,7 +15,7 @@ func addVisibilityForUserAndOrg(x *xorm.Engine) error { Visibility int `xorm:"NOT NULL DEFAULT 1"` } - if err := x.Sync2(new(PublicKey)); err != nil { + if err := x.Sync2(new(User)); err != nil { return fmt.Errorf("Sync2: %v", err) } return nil From 059dba5f9007da233bea47fc65820c40beffd204 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Fri, 8 Jun 2018 23:59:42 -0400 Subject: [PATCH 18/33] update date --- models/org.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/org.go b/models/org.go index bf926532d..d7ce32973 100644 --- a/models/org.go +++ b/models/org.go @@ -1,5 +1,5 @@ // Copyright 2014 The Gogs Authors. All rights reserved. -// Copyright 2017 The Gitea 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. From 8a36cf29e924c79a3956d9c57a30f24f406db6b7 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 11 Jun 2018 14:56:35 -0400 Subject: [PATCH 19/33] update with suggested code --- templates/explore/repo_list.tmpl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index 40f23e5b5..c04d8dfee 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -9,8 +9,10 @@ {{else if .IsMirror}} - {{else if eq .Owner.Visibility 3}} - + {{else if .Owner}} + {{if eq .Owner.Visibility 3}} + + {{end}} {{end}}
    From 819085a4d741ee65b95cf9742c089d2f082fe26a Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 29 Jun 2018 15:46:54 -0400 Subject: [PATCH 20/33] prepare for conflict resolution --- models/migrations/{v67.go => v72.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename models/migrations/{v67.go => v72.go} (100%) diff --git a/models/migrations/v67.go b/models/migrations/v72.go similarity index 100% rename from models/migrations/v67.go rename to models/migrations/v72.go From 0b0b603a4b39a6641b5e742c14574c353aab3472 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 29 Jun 2018 17:34:10 -0400 Subject: [PATCH 21/33] hide org profile page if needed when directly accessed --- routers/user/home.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/routers/user/home.go b/routers/user/home.go index 0c84b2498..a065dc794 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -362,6 +362,13 @@ func showOrgProfile(ctx *context.Context) { } org := ctx.Org.Organization + + canSeeOrg := models.HasOrgVisible([]*models.User{org}, ctx.User) + if !canSeeOrg { + ctx.NotFound("HasOrgVisible", nil) + return + } + ctx.Data["Title"] = org.DisplayName() page := ctx.QueryInt("page") From 6db8162c04e8400e0d72130d6aa031ccd6cd0488 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 29 Jun 2018 17:59:51 -0400 Subject: [PATCH 22/33] hide repo if hidden --- routers/repo/view.go | 6 ++++++ routers/user/home.go | 1 + 2 files changed, 7 insertions(+) diff --git a/routers/repo/view.go b/routers/repo/view.go index 4f1deeae4..d6e276b15 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -276,6 +276,12 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st // Home render repository home page func Home(ctx *context.Context) { + + canSeeOrg := models.HasOrgVisible([]*models.User{ctx.Repo.Repository.Owner}, ctx.User) + if !canSeeOrg { + ctx.NotFound("HasOrgVisible", nil) + return + } if len(ctx.Repo.Repository.Units) > 0 { var firstUnit *models.Unit for _, repoUnit := range ctx.Repo.Repository.Units { diff --git a/routers/user/home.go b/routers/user/home.go index a065dc794..a0142c2bb 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -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. From d4c63672a763f4bfb7f009587177770f64604aa7 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 29 Jun 2018 19:16:34 -0400 Subject: [PATCH 23/33] Chose visibility when creating org --- models/org.go | 1 - routers/org/org.go | 2 ++ templates/org/create.tmpl | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/models/org.go b/models/org.go index 30009d432..e75b5f0e2 100644 --- a/models/org.go +++ b/models/org.go @@ -127,7 +127,6 @@ func CreateOrganization(org, owner *User) (err error) { org.NumTeams = 1 org.NumMembers = 1 org.Type = UserTypeOrganization - org.Visibility = VisibleType(setting.Service.DefaultVisibilityMode) sess := x.NewSession() defer sess.Close() diff --git a/routers/org/org.go b/routers/org/org.go index bb7540277..f1b54d50d 100644 --- a/routers/org/org.go +++ b/routers/org/org.go @@ -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. @@ -23,6 +24,7 @@ const ( // Create render the page for create organization func Create(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("new_org") + ctx.Data["DefaultVisibilityMode"] = Setting.Service.DefaultVisibilityMode if !ctx.User.CanCreateOrganization() { ctx.ServerError("Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed"))) return diff --git a/templates/org/create.tmpl b/templates/org/create.tmpl index 765ef240e..39412b16a 100644 --- a/templates/org/create.tmpl +++ b/templates/org/create.tmpl @@ -15,6 +15,28 @@ {{.i18n.Tr "org.org_name_helper"}}
    +
    + +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +