From c2a75b3762fbaf949cd8f12a6aa7c0989d274e24 Mon Sep 17 00:00:00 2001 From: Remy Boulanouar Date: Fri, 19 May 2017 16:57:27 +0200 Subject: [PATCH 001/124] 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 7e6bbd5dc3066..8c136e25fb7a7 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 d6c26b633638f..f1f5e17a091bc 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 75f02a6268aad..b5688e1c519f0 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 4faed77d0d5ee..47235fcafb239 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 804136543433d..07941988df982 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 002/124] 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 fb07c4aaf29d8..dfe11c6e4b7e8 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 003/124] 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 8c136e25fb7a7..4203b54b79b74 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 e96bf5bd3f52f..f0d2c473b582e 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 4b1ab18349cd2..d753a1ba69b26 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 004/124] 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 76ed6491f476d..ed3a907f7353d 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 005/124] 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 106e0ea2c2cbc..a458a316d1192 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 dfe11c6e4b7e8..243a4aa024d91 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 4acad4239335f..7fd9cdb551abb 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 b5688e1c519f0..3831e5c2cf1b5 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 0fbd0befcf6b3..8f81865bbfee5 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 006/124] 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 362352b69512f..aa9cd79e8ff29 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 aeaecf8dfbdb9..21a0afed67a9a 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 007/124] 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 ed3a907f7353d..3c8753c36d7db 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 008/124] 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 3c8753c36d7db..b399732bb8908 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 009/124] 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 243a4aa024d91..968b6aff043ef 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 eb862d6542f29..c4e03db4b0523 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 a055a99a85652..3658a72eea2c0 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 010/124] 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 3831e5c2cf1b5..0fae6d3c7fe59 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 011/124] 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 4d17a50400cd2..7ee3fdd093a7b 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 012/124] 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 152f3a22aa666..714e659e1d697 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 013/124] 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 a529f55569901..69526bbff312b 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 014/124] 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 298e69be79e44..b9550c6ac1068 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 015/124] 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 b9550c6ac1068..40f23e5b54652 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 016/124] 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 1300065ab4c75..336260ed92de2 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 0000000000000..baca529c5d054 --- /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 017/124] 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 baca529c5d054..48261b3995779 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 018/124] update date --- models/org.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/org.go b/models/org.go index bf926532d0ea6..d7ce329739879 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 019/124] 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 40f23e5b54652..c04d8dfeec4fa 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 020/124] 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 021/124] 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 0c84b2498e013..a065dc7944c20 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 022/124] 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 4f1deeae40cd8..d6e276b15c324 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 a065dc7944c20..a0142c2bbdc7b 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 023/124] 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 30009d4323f0f..e75b5f0e2b064 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 bb7540277c635..f1b54d50dafd5 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 765ef240e538e..39412b16a476e 100644 --- a/templates/org/create.tmpl +++ b/templates/org/create.tmpl @@ -15,6 +15,28 @@ {{.i18n.Tr "org.org_name_helper"}}
    +
    + +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    {{else}}
    From 4ed648ed67d03e1a25a9d20608c2a5561fe8f85f Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 18:14:09 -0500 Subject: [PATCH 070/124] reset before sql changes --- models/repo_list.go | 7 +++---- models/user.go | 12 ++++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 00aa5eaac2c17..049d1834f7cc0 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -189,17 +189,16 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err if !opts.Private { collaborateCond = collaborateCond.And(builder.Expr("owner_id NOT IN (SELECT org_id FROM org_user WHERE org_user.uid = ? AND org_user.is_public = ?)", opts.OwnerID, false)) } + + accessCond = accessCond.Or(collaborateCond) } if opts.AllPublic { - accessCond = accessCond.Or(builder.Eq{"is_private": false}).And(builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Or(builder.Eq{"visibility": VisibleTypePrivate}, builder.Eq{"visibility": VisibleTypeLimited})))) + accessCond = accessCond.Or(builder.Eq{"is_private": false}) } cond = cond.And(accessCond) } - // cond = cond.And() // TODO: NotIn list of orgs that user doesn't belong to - } else { - cond = cond.And(builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Or(builder.Eq{"visibility": VisibleTypePrivate}, builder.Eq{"visibility": VisibleTypeLimited})))) } if opts.Keyword != "" { diff --git a/models/user.go b/models/user.go index 257c7e882f03f..24b11f5ac2002 100644 --- a/models/user.go +++ b/models/user.go @@ -840,6 +840,7 @@ func CreateUser(u *User) (err error) { u.MaxRepoCreation = -1 u.Theme = setting.UI.DefaultTheme u.AllowCreateOrganization = !setting.Admin.DisableRegularOrgCreation + u.Visibility = VisibleTypePublic if _, err = sess.Insert(u); err != nil { return err @@ -1374,7 +1375,10 @@ type SearchUserOptions struct { } func (opts *SearchUserOptions) toConds() builder.Cond { - var cond builder.Cond = builder.Eq{"type": opts.Type} + + var cond = builder.NewCond() + cond = cond.And(builder.Eq{"type": opts.Type}) + if len(opts.Keyword) > 0 { lowerKeyword := strings.ToLower(opts.Keyword) keywordCond := builder.Or( @@ -1388,14 +1392,14 @@ func (opts *SearchUserOptions) toConds() builder.Cond { cond = cond.And(keywordCond) } - if !opts.Private && opts.Type == UserTypeOrganization { + if !opts.Private { // user not logged in and so they won't be allowed to see non-public orgs cond = cond.And(builder.In("visibility", VisibleTypePublic)) } - if opts.OwnerID > 0 && opts.Type == UserTypeOrganization { + if opts.OwnerID > 0 { var accessCond = builder.NewCond() - accessCond.Or( + accessCond = builder.Or( builder.In("id", builder.Select("org_id").From("org_user").Join("LEFT", "user", "`org_user`.org_id=`user`.id").Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("visibility", VisibleTypePublic, VisibleTypeLimited)) cond = cond.And(accessCond) From 048334454914443a76f5118a87f759b4c896cc39 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 18:40:43 -0500 Subject: [PATCH 071/124] try to fix mssql --- models/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/user.go b/models/user.go index 24b11f5ac2002..dea904302ee1f 100644 --- a/models/user.go +++ b/models/user.go @@ -1400,7 +1400,7 @@ func (opts *SearchUserOptions) toConds() builder.Cond { if opts.OwnerID > 0 { var accessCond = builder.NewCond() accessCond = builder.Or( - builder.In("id", builder.Select("org_id").From("org_user").Join("LEFT", "user", "`org_user`.org_id=`user`.id").Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("user", builder.Eq{"org_user.org_id": "user.id"}).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("visibility", VisibleTypePublic, VisibleTypeLimited)) cond = cond.And(accessCond) } From e67cbd089b897cba48d9e91fd3627395e16bf005 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 19:12:20 -0500 Subject: [PATCH 072/124] repo SQL --- models/repo_list.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/models/repo_list.go b/models/repo_list.go index 049d1834f7cc0..5fe550246014c 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -171,6 +171,11 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err if !opts.Private { cond = cond.And(builder.Eq{"is_private": false}) + var accessCond = builder.NewCond() + accessCond = builder.Or( + builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Or(builder.Eq{"visibility": VisibleTypeLimited}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Eq{"type": UserTypeOrganization}))) + cond = cond.And(accessCond) } if opts.OwnerID > 0 { @@ -193,6 +198,15 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err accessCond = accessCond.Or(collaborateCond) } + // TODO: filter down to only repos that belong to a user, or can be seen by the current user + var visibilityCond = builder.NewCond() + visibilityCond = builder.Or( + builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("user", builder.Eq{"org_user.org_id": "user.id"}).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("owner_id", builder.Select("id").From("user").Where(builder.Or(builder.Eq{"visibility": VisibleTypePublic}, builder.Eq{"visibility": VisibleTypeLimited}))), + builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Eq{"type": UserTypeOrganization})), + ) + cond = cond.And(visibilityCond) + if opts.AllPublic { accessCond = accessCond.Or(builder.Eq{"is_private": false}) } From 9cd145cdb7645a59ce41ff35194758babaaac49e Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 19:12:51 -0500 Subject: [PATCH 073/124] remove TODO comment --- models/repo_list.go | 1 - 1 file changed, 1 deletion(-) diff --git a/models/repo_list.go b/models/repo_list.go index 5fe550246014c..53e88d05f4cf4 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -198,7 +198,6 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err accessCond = accessCond.Or(collaborateCond) } - // TODO: filter down to only repos that belong to a user, or can be seen by the current user var visibilityCond = builder.NewCond() visibilityCond = builder.Or( builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("user", builder.Eq{"org_user.org_id": "user.id"}).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), From 0159beb56ab1793251645bbc297db5190248df00 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 19:16:11 -0500 Subject: [PATCH 074/124] make fmt --- models/repo_list.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 53e88d05f4cf4..52c4f4efb01c7 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -173,8 +173,8 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err cond = cond.And(builder.Eq{"is_private": false}) var accessCond = builder.NewCond() accessCond = builder.Or( - builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Or(builder.Eq{"visibility": VisibleTypeLimited}, builder.Eq{"visibility": VisibleTypePrivate}))), - builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Eq{"type": UserTypeOrganization}))) + builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Or(builder.Eq{"visibility": VisibleTypeLimited}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Eq{"type": UserTypeOrganization}))) cond = cond.And(accessCond) } @@ -203,7 +203,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("user", builder.Eq{"org_user.org_id": "user.id"}).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("owner_id", builder.Select("id").From("user").Where(builder.Or(builder.Eq{"visibility": VisibleTypePublic}, builder.Eq{"visibility": VisibleTypeLimited}))), builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Eq{"type": UserTypeOrganization})), - ) + ) cond = cond.And(visibilityCond) if opts.AllPublic { From 8d26cb604f7ca33682200b3bb2e0f7b9e0f3a91d Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 19:17:33 -0500 Subject: [PATCH 075/124] fix spacing --- templates/explore/repo_list.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index 50e76bb137ff7..497a8e1439570 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -23,7 +23,7 @@ {{.NumForks}}
    - {{if .DescriptionHTML}}

    {{.DescriptionHTML}}

    {{end}} + {{if .DescriptionHTML}}

    {{.DescriptionHTML}}

    {{end}} {{if .Topics }}
    {{range .Topics}} @@ -31,7 +31,7 @@ {{end}}
    {{end}} -

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

    +

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

    {{else}}
    From 45b706cf2587b4c1aac5eb584854751795a063b3 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 19:19:16 -0500 Subject: [PATCH 076/124] more spacing --- templates/explore/repo_list.tmpl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index 497a8e1439570..ad7e4ce49ab40 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -17,12 +17,11 @@ {{end}} {{end}} - -
    - {{.NumStars}} - {{.NumForks}} -
    +
    + {{.NumStars}} + {{.NumForks}}
    +
    {{if .DescriptionHTML}}

    {{.DescriptionHTML}}

    {{end}} {{if .Topics }}
    From 14e6d04351cedfd15b4bd9d9b77966f057698e78 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 20:22:14 -0500 Subject: [PATCH 077/124] try different sql join --- models/repo_list.go | 2 +- models/user.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 52c4f4efb01c7..98f64e4b780bb 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -200,7 +200,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err var visibilityCond = builder.NewCond() visibilityCond = builder.Or( - builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("user", builder.Eq{"org_user.org_id": "user.id"}).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("owner_id", builder.Select("org_id").From("org_user").JOIN("INNER", "user","org_user.org_id = user.id").Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("owner_id", builder.Select("id").From("user").Where(builder.Or(builder.Eq{"visibility": VisibleTypePublic}, builder.Eq{"visibility": VisibleTypeLimited}))), builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Eq{"type": UserTypeOrganization})), ) diff --git a/models/user.go b/models/user.go index dea904302ee1f..c251000d7ede0 100644 --- a/models/user.go +++ b/models/user.go @@ -1400,7 +1400,7 @@ func (opts *SearchUserOptions) toConds() builder.Cond { if opts.OwnerID > 0 { var accessCond = builder.NewCond() accessCond = builder.Or( - builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("user", builder.Eq{"org_user.org_id": "user.id"}).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("id", builder.Select("org_id").From("org_user").Join("INNER", "user", "org_user.org_id = user.id").Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("visibility", VisibleTypePublic, VisibleTypeLimited)) cond = cond.And(accessCond) } From 5e02b7b85285046fbc2172f26ffb3c2fc62d0e9f Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 20:22:38 -0500 Subject: [PATCH 078/124] make fmt --- models/repo_list.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/repo_list.go b/models/repo_list.go index 98f64e4b780bb..a8abbf92960ee 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -200,7 +200,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err var visibilityCond = builder.NewCond() visibilityCond = builder.Or( - builder.In("owner_id", builder.Select("org_id").From("org_user").JOIN("INNER", "user","org_user.org_id = user.id").Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("owner_id", builder.Select("org_id").From("org_user").JOIN("INNER", "user", "org_user.org_id = user.id").Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("owner_id", builder.Select("id").From("user").Where(builder.Or(builder.Eq{"visibility": VisibleTypePublic}, builder.Eq{"visibility": VisibleTypeLimited}))), builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Eq{"type": UserTypeOrganization})), ) From 30bdaa01a7bf1af35d11cc751b4f8ee713cec1dc Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 20:24:03 -0500 Subject: [PATCH 079/124] correct capitalization --- models/repo_list.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/repo_list.go b/models/repo_list.go index a8abbf92960ee..3a3f1f8513cec 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -200,7 +200,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err var visibilityCond = builder.NewCond() visibilityCond = builder.Or( - builder.In("owner_id", builder.Select("org_id").From("org_user").JOIN("INNER", "user", "org_user.org_id = user.id").Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("owner_id", builder.Select("org_id").From("org_user").Join("INNER", "user", "org_user.org_id = user.id").Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("owner_id", builder.Select("id").From("user").Where(builder.Or(builder.Eq{"visibility": VisibleTypePublic}, builder.Eq{"visibility": VisibleTypeLimited}))), builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Eq{"type": UserTypeOrganization})), ) From 2ffc2967f4dfe5a213d5150089dc560c7373f1a9 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 20:46:35 -0500 Subject: [PATCH 080/124] resolve postgresql errors --- models/repo_list.go | 10 +++++----- models/user.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 3a3f1f8513cec..6c9b970b37c40 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -173,8 +173,8 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err cond = cond.And(builder.Eq{"is_private": false}) var accessCond = builder.NewCond() accessCond = builder.Or( - builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Or(builder.Eq{"visibility": VisibleTypeLimited}, builder.Eq{"visibility": VisibleTypePrivate}))), - builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Eq{"type": UserTypeOrganization}))) + builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": VisibleTypeLimited}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization}))) cond = cond.And(accessCond) } @@ -200,9 +200,9 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err var visibilityCond = builder.NewCond() visibilityCond = builder.Or( - builder.In("owner_id", builder.Select("org_id").From("org_user").Join("INNER", "user", "org_user.org_id = user.id").Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), - builder.In("owner_id", builder.Select("id").From("user").Where(builder.Or(builder.Eq{"visibility": VisibleTypePublic}, builder.Eq{"visibility": VisibleTypeLimited}))), - builder.NotIn("owner_id", builder.Select("id").From("user").Where(builder.Eq{"type": UserTypeOrganization})), + builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Eq{"org_user.org_id": "user.id"}).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": VisibleTypePublic}, builder.Eq{"visibility": VisibleTypeLimited}))), + builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization})), ) cond = cond.And(visibilityCond) diff --git a/models/user.go b/models/user.go index c251000d7ede0..272319f94bae7 100644 --- a/models/user.go +++ b/models/user.go @@ -1400,7 +1400,7 @@ func (opts *SearchUserOptions) toConds() builder.Cond { if opts.OwnerID > 0 { var accessCond = builder.NewCond() accessCond = builder.Or( - builder.In("id", builder.Select("org_id").From("org_user").Join("INNER", "user", "org_user.org_id = user.id").Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Eq{"org_user.org_id": "user.id"}).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("visibility", VisibleTypePublic, VisibleTypeLimited)) cond = cond.And(accessCond) } From 7f634140c929987b3c4cc9a405feb6b018904b84 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 20:52:32 -0500 Subject: [PATCH 081/124] more psql fixes --- models/repo_list.go | 2 +- models/user.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 6c9b970b37c40..1ffde4300217e 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -200,7 +200,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err var visibilityCond = builder.NewCond() visibilityCond = builder.Or( - builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Eq{"org_user.org_id": "user.id"}).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Eq{"org_user.org_id": "`user`.id"}).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": VisibleTypePublic}, builder.Eq{"visibility": VisibleTypeLimited}))), builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization})), ) diff --git a/models/user.go b/models/user.go index 272319f94bae7..615b49ac7520a 100644 --- a/models/user.go +++ b/models/user.go @@ -1400,7 +1400,7 @@ func (opts *SearchUserOptions) toConds() builder.Cond { if opts.OwnerID > 0 { var accessCond = builder.NewCond() accessCond = builder.Or( - builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Eq{"org_user.org_id": "user.id"}).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Eq{"org_user.org_id": "`user`.id"}).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("visibility", VisibleTypePublic, VisibleTypeLimited)) cond = cond.And(accessCond) } From 78ed0a7dece601a5b4104761769db22a03540256 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 21:13:09 -0500 Subject: [PATCH 082/124] SQL --- models/repo_list.go | 2 +- models/user.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 1ffde4300217e..453666815718e 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -200,7 +200,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err var visibilityCond = builder.NewCond() visibilityCond = builder.Or( - builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Eq{"org_user.org_id": "`user`.id"}).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Expr("org_user.org_id = user.id")).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": VisibleTypePublic}, builder.Eq{"visibility": VisibleTypeLimited}))), builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization})), ) diff --git a/models/user.go b/models/user.go index 615b49ac7520a..c887257d7b11c 100644 --- a/models/user.go +++ b/models/user.go @@ -1400,7 +1400,7 @@ func (opts *SearchUserOptions) toConds() builder.Cond { if opts.OwnerID > 0 { var accessCond = builder.NewCond() accessCond = builder.Or( - builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Eq{"org_user.org_id": "`user`.id"}).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Expr("org_user.org_id = `user`.id")).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("visibility", VisibleTypePublic, VisibleTypeLimited)) cond = cond.And(accessCond) } From 97802f2e7f102684859a19276ee527248b4a0881 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 21:24:16 -0500 Subject: [PATCH 083/124] psql --- models/repo_list.go | 2 +- models/user.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 453666815718e..113be0effa085 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -200,7 +200,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err var visibilityCond = builder.NewCond() visibilityCond = builder.Or( - builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Expr("org_user.org_id = user.id")).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Expr("org_user.org_id = \"user\".id")).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": VisibleTypePublic}, builder.Eq{"visibility": VisibleTypeLimited}))), builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization})), ) diff --git a/models/user.go b/models/user.go index c887257d7b11c..da57ef5bcec3b 100644 --- a/models/user.go +++ b/models/user.go @@ -1400,7 +1400,7 @@ func (opts *SearchUserOptions) toConds() builder.Cond { if opts.OwnerID > 0 { var accessCond = builder.NewCond() accessCond = builder.Or( - builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Expr("org_user.org_id = `user`.id")).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Expr("org_user.org_id = \"user\".id")).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("visibility", VisibleTypePublic, VisibleTypeLimited)) cond = cond.And(accessCond) } From ac9aad0e490a1cd98b53904aedf9cf6276d33324 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 22:03:43 -0500 Subject: [PATCH 084/124] fix mysql --- models/repo_list.go | 2 +- models/user.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 113be0effa085..b9b4bff48322c 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -200,7 +200,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err var visibilityCond = builder.NewCond() visibilityCond = builder.Or( - builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Expr("org_user.org_id = \"user\".id")).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Expr("org_user.org_id = id")).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": VisibleTypePublic}, builder.Eq{"visibility": VisibleTypeLimited}))), builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization})), ) diff --git a/models/user.go b/models/user.go index da57ef5bcec3b..bcc4cf1c2ffa7 100644 --- a/models/user.go +++ b/models/user.go @@ -1400,7 +1400,7 @@ func (opts *SearchUserOptions) toConds() builder.Cond { if opts.OwnerID > 0 { var accessCond = builder.NewCond() accessCond = builder.Or( - builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Expr("org_user.org_id = \"user\".id")).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Expr("org_user.org_id = id")).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("visibility", VisibleTypePublic, VisibleTypeLimited)) cond = cond.And(accessCond) } From 373e1f58235fabb4a00951463e2060afcbed62c2 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 22:48:29 -0500 Subject: [PATCH 085/124] work for all DB types --- models/repo_list.go | 9 ++++++++- models/user.go | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index b9b4bff48322c..5de2d3ca24c0c 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/modules/util" "github.com/go-xorm/builder" + "github.com/go-xorm/core" ) // RepositoryListDefaultPageSize is the default number of repositories @@ -198,9 +199,15 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err accessCond = accessCond.Or(collaborateCond) } + var exprCond builder.Cond + if DbCfg.Type == core.MYSQL { + exprCond = builder.Expr("org_user.org_id = user.id") + } else { + builder.Expr("org_user.org_id = \"user\".id") + } var visibilityCond = builder.NewCond() visibilityCond = builder.Or( - builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Expr("org_user.org_id = id")).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": VisibleTypePublic}, builder.Eq{"visibility": VisibleTypeLimited}))), builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization})), ) diff --git a/models/user.go b/models/user.go index bcc4cf1c2ffa7..f42fc0db6c96a 100644 --- a/models/user.go +++ b/models/user.go @@ -27,6 +27,7 @@ import ( "github.com/Unknwon/com" "github.com/go-xorm/builder" + "github.com/go-xorm/core" "github.com/go-xorm/xorm" "github.com/nfnt/resize" "golang.org/x/crypto/pbkdf2" @@ -1398,9 +1399,15 @@ func (opts *SearchUserOptions) toConds() builder.Cond { } if opts.OwnerID > 0 { + var exprCond builder.Cond + if DbCfg.Type == core.MYSQL { + exprCond = builder.Expr("org_user.org_id = user.id") + } else { + exprCond = builder.Expr("org_user.org_id = \"user\".id") + } var accessCond = builder.NewCond() accessCond = builder.Or( - builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", builder.Expr("org_user.org_id = id")).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("visibility", VisibleTypePublic, VisibleTypeLimited)) cond = cond.And(accessCond) } From da64f722da7d2dfeab62b2a104bfa86756c99420 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 23:05:34 -0500 Subject: [PATCH 086/124] work on all DBs hopefully --- models/repo_list.go | 7 ++++--- models/user.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 5de2d3ca24c0c..fa2168f497ef5 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -200,11 +200,12 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err } var exprCond builder.Cond - if DbCfg.Type == core.MYSQL { - exprCond = builder.Expr("org_user.org_id = user.id") + if DbCfg.Type == core.POSTGRES { + exprCond = builder.Expr("org_user.org_id = \"user\".id") } else { - builder.Expr("org_user.org_id = \"user\".id") + exprCond = builder.Eq{"org_user.org_id": "user.id"} } + var visibilityCond = builder.NewCond() visibilityCond = builder.Or( builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), diff --git a/models/user.go b/models/user.go index f42fc0db6c96a..9feed036c4386 100644 --- a/models/user.go +++ b/models/user.go @@ -1407,7 +1407,7 @@ func (opts *SearchUserOptions) toConds() builder.Cond { } var accessCond = builder.NewCond() accessCond = builder.Or( - builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("user", exprCond).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("visibility", VisibleTypePublic, VisibleTypeLimited)) cond = cond.And(accessCond) } From 64af3a61026b4ddbdc47c7cea4d8a70139978dca Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 23:20:49 -0500 Subject: [PATCH 087/124] mssql --- models/repo_list.go | 2 ++ models/user.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/models/repo_list.go b/models/repo_list.go index fa2168f497ef5..5d953698c6c0e 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -202,6 +202,8 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err var exprCond builder.Cond if DbCfg.Type == core.POSTGRES { exprCond = builder.Expr("org_user.org_id = \"user\".id") + } else if DbCfg.Type == core.MSSQL { + exprCond = builder.Expr("org_user.org_id = user.id") } else { exprCond = builder.Eq{"org_user.org_id": "user.id"} } diff --git a/models/user.go b/models/user.go index 9feed036c4386..e5547674523d1 100644 --- a/models/user.go +++ b/models/user.go @@ -1402,6 +1402,8 @@ func (opts *SearchUserOptions) toConds() builder.Cond { var exprCond builder.Cond if DbCfg.Type == core.MYSQL { exprCond = builder.Expr("org_user.org_id = user.id") + } else if DbCfg.Type == core.MSSQL { + exprCond = builder.Expr("org_user.org_id = user.id") } else { exprCond = builder.Expr("org_user.org_id = \"user\".id") } From d22dff8cbb588fcea74e0fca4631365f1d0d7c16 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 1 Feb 2019 23:34:15 -0500 Subject: [PATCH 088/124] mssql --- models/repo_list.go | 2 +- models/user.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 5d953698c6c0e..869f414e8e1ab 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -203,7 +203,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err if DbCfg.Type == core.POSTGRES { exprCond = builder.Expr("org_user.org_id = \"user\".id") } else if DbCfg.Type == core.MSSQL { - exprCond = builder.Expr("org_user.org_id = user.id") + exprCond = builder.Expr("org_user.org_id = [user].id") } else { exprCond = builder.Eq{"org_user.org_id": "user.id"} } diff --git a/models/user.go b/models/user.go index e5547674523d1..e7359ff949672 100644 --- a/models/user.go +++ b/models/user.go @@ -1403,13 +1403,13 @@ func (opts *SearchUserOptions) toConds() builder.Cond { if DbCfg.Type == core.MYSQL { exprCond = builder.Expr("org_user.org_id = user.id") } else if DbCfg.Type == core.MSSQL { - exprCond = builder.Expr("org_user.org_id = user.id") + exprCond = builder.Expr("org_user.org_id = [user].id") } else { exprCond = builder.Expr("org_user.org_id = \"user\".id") } var accessCond = builder.NewCond() accessCond = builder.Or( - builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("user", exprCond).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("visibility", VisibleTypePublic, VisibleTypeLimited)) cond = cond.And(accessCond) } From 55cba7cc90130e8bd8cd47cb51192e4fffa46e3f Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 2 Feb 2019 00:02:34 -0500 Subject: [PATCH 089/124] Update config-cheat-sheet.en-us.md --- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index ff40df75b755c..37ee1a79ada10 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -146,7 +146,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `PATH`: **data/gitea.db**: For SQLite3 only, the database file path. - `LOG_SQL`: **true**: Log the executed SQL. - `DB_RETRIES`: **10**: How many ORM init / DB connect attempts allowed. -- `DB_RETRY_BACKOFF`: **3s*: time.Duration to wait before trying another ORM init / DB connect attempt, if failure occured. +- `DB_RETRY_BACKOFF`: **3s**: time.Duration to wait before trying another ORM init / DB connect attempt, if failure occured. ## Indexer (`indexer`) From 655c7720f6247f4ff8d27cfddf0699a50d6f2244 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 2 Feb 2019 12:31:44 -0500 Subject: [PATCH 090/124] Update user.go --- models/user.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/user.go b/models/user.go index e7359ff949672..92a7c2b9d4270 100644 --- a/models/user.go +++ b/models/user.go @@ -82,7 +82,7 @@ type VisibleType int const ( // VisibleTypePublic Visible for everyone - VisibleTypePublic VisibleType = iota + 1 + VisibleTypePublic VisibleType = iota // VisibleTypeLimited Visible for every connected user VisibleTypeLimited @@ -153,7 +153,7 @@ type User struct { NumMembers int Teams []*Team `xorm:"-"` Members []*User `xorm:"-"` - Visibility VisibleType `xorm:"NOT NULL DEFAULT 1"` + Visibility VisibleType `xorm:"NOT NULL DEFAULT 0"` // Preferences DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"` From 3a5d9adfd6b8069969cde502a2495ddb16b219f6 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 2 Feb 2019 12:32:48 -0500 Subject: [PATCH 091/124] Update structs.go --- modules/structs/structs.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/structs/structs.go b/modules/structs/structs.go index 2c1e1d24f4652..fe4cb1d3bc922 100644 --- a/modules/structs/structs.go +++ b/modules/structs/structs.go @@ -6,7 +6,7 @@ package structs // VisibilityModes is a map of org Visibility types var VisibilityModes = map[string]int{ - "public": 1, - "limited": 2, - "private": 3, + "public": 0, + "limited": 1, + "private": 2, } From 3e236c5cac549e36256635d49e1832894d662cda Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 2 Feb 2019 12:33:38 -0500 Subject: [PATCH 092/124] Delete v79.go --- models/migrations/v79.go | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 models/migrations/v79.go diff --git a/models/migrations/v79.go b/models/migrations/v79.go deleted file mode 100644 index 3cfa863b99879..0000000000000 --- a/models/migrations/v79.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2019 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 -} From 148039e955c8150f6003844bb97d22cc769851dd Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 2 Feb 2019 12:34:01 -0500 Subject: [PATCH 093/124] Update migrations.go --- models/migrations/migrations.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 8543da8d8f9bd..2c402e115625f 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -211,8 +211,6 @@ var migrations = []Migration{ NewMigration("add theme to users", addUserDefaultTheme), // v78 -> v79 NewMigration("rename repo is_bare to repo is_empty", renameRepoIsBareToIsEmpty), - // v79 -> v80 - NewMigration("add visibility for user and org", addVisibilityForUserAndOrg), } // Migrate database to current version From fc196286a2bee2fe46cb0d4d48fe0fc32e637aa2 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 2 Feb 2019 12:38:41 -0500 Subject: [PATCH 094/124] Update user.go --- models/user.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/user.go b/models/user.go index 92a7c2b9d4270..2d3d59cbac0e3 100644 --- a/models/user.go +++ b/models/user.go @@ -543,8 +543,8 @@ func (u *User) IsUserOrgOwner(orgID int64) bool { } // IsUserPartOfOrg returns true if user is part of the organization -func (u *User) IsUserPartOfOrg(userID int64) bool { - isMember, err := IsOrganizationMember(u.ID, userID) +func (org *User) IsUserPartOfOrg(userID int64) bool { + isMember, err := IsOrganizationMember(org.ID, userID) if err != nil { log.Error(4, "IsOrganizationMember: %v", err) return false From 35c417559c7807cd21fb3a47678753e5fb6a284c Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 2 Feb 2019 12:42:07 -0500 Subject: [PATCH 095/124] Update user.go --- models/user.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/user.go b/models/user.go index 2d3d59cbac0e3..ff7b4932a2729 100644 --- a/models/user.go +++ b/models/user.go @@ -542,9 +542,9 @@ func (u *User) IsUserOrgOwner(orgID int64) bool { return isOwner } -// IsUserPartOfOrg returns true if user is part of the organization -func (org *User) IsUserPartOfOrg(userID int64) bool { - isMember, err := IsOrganizationMember(org.ID, userID) +// IsUserPartOfOrg returns true is user ID is part of the u organisation. +func (u *User) IsUserPartOfOrg(userID int64) bool { + isMember, err := IsOrganizationMember(u.ID, userID) if err != nil { log.Error(4, "IsOrganizationMember: %v", err) return false From 907a5ba29dcf9581ca9402b197321aefa8859faf Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 2 Feb 2019 14:56:44 -0500 Subject: [PATCH 096/124] update per feedback --- models/org.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/models/org.go b/models/org.go index 11685ef0279c9..add1cb8b5c8ea 100644 --- a/models/org.go +++ b/models/org.go @@ -380,15 +380,13 @@ func HasOrgVisible(org *User, user *User) bool { if user.IsAdmin { return true } - switch org.Visibility { - case VisibleTypePrivate: + if org.Visibility == VisibleTypePrivate { if org.IsUserPartOfOrg(user.ID) { return true } - default: - return true + return false } - return false + return true } // HasOrgsVisible tells if the given user can see at least one of the orgs provided From 583a4007aa21dfe182cb6a0cb7553591a0f2214d Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 2 Feb 2019 14:58:21 -0500 Subject: [PATCH 097/124] fix comment --- models/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/user.go b/models/user.go index ff7b4932a2729..b447c1cad9516 100644 --- a/models/user.go +++ b/models/user.go @@ -542,7 +542,7 @@ func (u *User) IsUserOrgOwner(orgID int64) bool { return isOwner } -// IsUserPartOfOrg returns true is user ID is part of the u organisation. +// IsUserPartOfOrg returns true if user with userID is part of the u organisation. func (u *User) IsUserPartOfOrg(userID int64) bool { isMember, err := IsOrganizationMember(u.ID, userID) if err != nil { From 4fce17925f7ff585af5dd636efd9691de74ba65e Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Feb 2019 10:55:13 -0500 Subject: [PATCH 098/124] Update org.go --- routers/api/v1/org/org.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index f28d2f7e0b224..e3916046f0296 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -129,8 +129,7 @@ func Get(ctx *context.APIContext) { // responses: // "200": // "$ref": "#/responses/Organization" - canSeeOrg := models.HasOrgVisible(ctx.Org.Organization, ctx.User) - if !canSeeOrg { + if !models.HasOrgVisible(ctx.Org.Organization, ctx.User) { ctx.NotFound("HasOrgVisible", nil) return } From c8b844f0d99699cd26932c49dc29f2092d33a533 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Feb 2019 10:55:50 -0500 Subject: [PATCH 099/124] Update repo.go --- routers/api/v1/repo/repo.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index a1f75bf63ef6e..f69cbee0c05e3 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -302,8 +302,7 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) { return } - canSeeOrg := models.HasOrgVisible(org, ctx.User) - if !canSeeOrg { + if !models.HasOrgVisible(org, ctx.User) { ctx.NotFound("HasOrgVisible", nil) return } From 7f053746daaeed08bd48df6d0467a819db8b5c62 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Feb 2019 10:56:26 -0500 Subject: [PATCH 100/124] Update view.go --- routers/repo/view.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/repo/view.go b/routers/repo/view.go index 5a06d64f12207..ec0ea0f78471f 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -295,8 +295,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st // Home render repository home page func Home(ctx *context.Context) { - canSeeOrg := models.HasOrgVisible(ctx.Repo.Repository.Owner, ctx.User) - if !canSeeOrg { + if !models.HasOrgVisible(ctx.Repo.Repository.Owner, ctx.User) { ctx.NotFound("HasOrgVisible", nil) return } From f94e04042b1ddd609b757e862ec1467856ae8c8f Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Feb 2019 10:57:43 -0500 Subject: [PATCH 101/124] Update home.go --- routers/user/home.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/user/home.go b/routers/user/home.go index b0627135ec2c6..7c5fba2192d58 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -387,8 +387,7 @@ func showOrgProfile(ctx *context.Context) { org := ctx.Org.Organization - canSeeOrg := models.HasOrgVisible(org, ctx.User) - if !canSeeOrg { + if !models.HasOrgVisible(org, ctx.User) { ctx.NotFound("HasOrgVisible", nil) return } From b1f7a5d126a6d9f28d307a90fc24330a3217dd97 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Feb 2019 10:59:37 -0500 Subject: [PATCH 102/124] Update list.tmpl --- templates/admin/org/list.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl index 3ea7790afde52..c955ba955cfd8 100644 --- a/templates/admin/org/list.tmpl +++ b/templates/admin/org/list.tmpl @@ -31,7 +31,7 @@ {{.ID}} {{.Name}} - {{if eq .Visibility 3}} + {{if eq .Visibility 2}} {{end}} From ec4b1108bb1d6b65946e5074d6984885c57f9743 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Feb 2019 11:00:10 -0500 Subject: [PATCH 103/124] Update profile.tmpl --- templates/user/profile.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index d7111f5778646..20fe4ad3ad91a 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -64,7 +64,7 @@ {{if and .Orgs .HasOrgsVisible}}
  • {{range .Orgs}} - {{if (or (eq .Visibility 1) (and ($.SignedUser) (or (eq .Visibility 2) (and (.IsUserPartOfOrg $.SignedUserID) (eq .Visibility 3)) ($.IsAdmin))))}} + {{if (or (eq .Visibility 0) (and ($.SignedUser) (or (eq .Visibility 1) (and (.IsUserPartOfOrg $.SignedUserID) (eq .Visibility 2)) ($.IsAdmin))))}} {{end}} {{end}} From 54ddf818352c0cc4e597df5cade0f4b34a524872 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Feb 2019 11:00:43 -0500 Subject: [PATCH 104/124] Update options.tmpl --- templates/org/settings/options.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/org/settings/options.tmpl b/templates/org/settings/options.tmpl index 07941988df982..24007961799e1 100644 --- a/templates/org/settings/options.tmpl +++ b/templates/org/settings/options.tmpl @@ -38,19 +38,19 @@
    - +
    - +
    - +
    From caf2acfa9d2bdf51ce9e8458ab50c842a24e79a7 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Feb 2019 11:01:38 -0500 Subject: [PATCH 105/124] Update create.tmpl --- templates/org/create.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/org/create.tmpl b/templates/org/create.tmpl index 39412b16a476e..cf6f4c4ca3e7a 100644 --- a/templates/org/create.tmpl +++ b/templates/org/create.tmpl @@ -19,19 +19,19 @@
    - +
    - +
    - +
    From 881db82523a968e5e929e6f08d3da3d052551630 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Feb 2019 11:01:48 -0500 Subject: [PATCH 106/124] Update repo_list.tmpl --- 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 ad7e4ce49ab40..a8d96ded4d4a0 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -13,7 +13,7 @@ {{else if .IsMirror}} {{else if .Owner}} - {{if eq .Owner.Visibility 3}} + {{if eq .Owner.Visibility 2}} {{end}} {{end}} From 87d846347cf4908199668e3952aa0725f9012347 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Feb 2019 11:02:36 -0500 Subject: [PATCH 107/124] Update create.tmpl --- templates/org/create.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/org/create.tmpl b/templates/org/create.tmpl index cf6f4c4ca3e7a..02c074af7bd9d 100644 --- a/templates/org/create.tmpl +++ b/templates/org/create.tmpl @@ -19,19 +19,19 @@
    - +
    - +
    - +
    From f33a083e8e878ce2bbc4601cbad6ba889185c67f Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Feb 2019 11:02:45 -0500 Subject: [PATCH 108/124] Update organizations.tmpl --- templates/explore/organizations.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/explore/organizations.tmpl b/templates/explore/organizations.tmpl index 39df708fb1ba6..5578f8befdb92 100644 --- a/templates/explore/organizations.tmpl +++ b/templates/explore/organizations.tmpl @@ -11,7 +11,7 @@
    {{.Name}} {{.FullName}} - {{if eq .Visibility 3}} + {{if eq .Visibility 2}} {{end}} From 5b18778139876bdc98fdff8ece47b0e40290fa56 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Feb 2019 11:03:18 -0500 Subject: [PATCH 109/124] Update list.tmpl --- templates/admin/repo/list.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index 8a40b51baf06d..44b3c148a500e 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -32,7 +32,7 @@ {{.ID}} {{.Owner.Name}} - {{if eq .Owner.Visibility 3}} + {{if eq .Owner.Visibility 2}} {{end}} From be4f40541d18abce1b027482bf8c2884f33cf612 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Feb 2019 14:10:16 -0500 Subject: [PATCH 110/124] Update options.tmpl --- templates/org/settings/options.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/org/settings/options.tmpl b/templates/org/settings/options.tmpl index 24007961799e1..e8cfd97d4e7e4 100644 --- a/templates/org/settings/options.tmpl +++ b/templates/org/settings/options.tmpl @@ -38,19 +38,19 @@
    - +
    - +
    - +
    From 9462c2d0fb7246b564cd5d2285c3a4b13e0e4564 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Tue, 5 Feb 2019 21:57:15 -0500 Subject: [PATCH 111/124] Update structs.go --- modules/structs/structs.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/modules/structs/structs.go b/modules/structs/structs.go index fe4cb1d3bc922..346b29658ed30 100644 --- a/modules/structs/structs.go +++ b/modules/structs/structs.go @@ -4,9 +4,24 @@ package structs +// VisibleType defines the visibility (Organization only) +type VisibleType int + +const ( + // VisibleTypePublic Visible for everyone + VisibleTypePublic VisibleType = iota + + // VisibleTypeLimited Visible for every connected user + VisibleTypeLimited + + // VisibleTypePrivate Visible only for organization's members + VisibleTypePrivate +) + // VisibilityModes is a map of org Visibility types var VisibilityModes = map[string]int{ - "public": 0, - "limited": 1, - "private": 2, + "public": VisibleTypePublic, + "limited": VisibleTypeLimited, + "private": VisibleTypePrivate, } + From 46c75f3a50c2ca619a6ba180fda2dbaf52a96a67 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Tue, 5 Feb 2019 22:00:10 -0500 Subject: [PATCH 112/124] move structs to structs package --- models/user.go | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/models/user.go b/models/user.go index b447c1cad9516..a3cd5b9726c4a 100644 --- a/models/user.go +++ b/models/user.go @@ -25,23 +25,23 @@ import ( "time" "unicode/utf8" - "github.com/Unknwon/com" - "github.com/go-xorm/builder" - "github.com/go-xorm/core" - "github.com/go-xorm/xorm" - "github.com/nfnt/resize" - "golang.org/x/crypto/pbkdf2" - "golang.org/x/crypto/ssh" - "code.gitea.io/git" api "code.gitea.io/sdk/gitea" - + "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/avatar" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/generate" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" + + "github.com/Unknwon/com" + "github.com/go-xorm/builder" + "github.com/go-xorm/core" + "github.com/go-xorm/xorm" + "github.com/nfnt/resize" + "golang.org/x/crypto/pbkdf2" + "golang.org/x/crypto/ssh" ) // UserType defines the user type @@ -77,20 +77,6 @@ var ( ErrUnsupportedLoginType = errors.New("Login source is unknown") ) -// VisibleType defines the visibility (Organization only) -type VisibleType int - -const ( - // VisibleTypePublic Visible for everyone - VisibleTypePublic VisibleType = iota - - // 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"` @@ -153,7 +139,7 @@ type User struct { NumMembers int Teams []*Team `xorm:"-"` Members []*User `xorm:"-"` - Visibility VisibleType `xorm:"NOT NULL DEFAULT 0"` + Visibility structs.VisibleType `xorm:"NOT NULL DEFAULT 0"` // Preferences DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"` @@ -841,7 +827,6 @@ func CreateUser(u *User) (err error) { u.MaxRepoCreation = -1 u.Theme = setting.UI.DefaultTheme u.AllowCreateOrganization = !setting.Admin.DisableRegularOrgCreation - u.Visibility = VisibleTypePublic if _, err = sess.Insert(u); err != nil { return err @@ -1395,7 +1380,7 @@ func (opts *SearchUserOptions) toConds() builder.Cond { if !opts.Private { // user not logged in and so they won't be allowed to see non-public orgs - cond = cond.And(builder.In("visibility", VisibleTypePublic)) + cond = cond.And(builder.In("visibility", structs.VisibleTypePublic)) } if opts.OwnerID > 0 { @@ -1409,8 +1394,8 @@ func (opts *SearchUserOptions) toConds() builder.Cond { } var accessCond = builder.NewCond() accessCond = builder.Or( - builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), - builder.In("visibility", VisibleTypePublic, VisibleTypeLimited)) + builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": structs.VisibleTypePrivate}))), + builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited)) cond = cond.And(accessCond) } From 3fcebe605a1e35cff0efc3406cf31745c21a38e4 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Tue, 5 Feb 2019 22:01:00 -0500 Subject: [PATCH 113/124] Update repo_list.go --- models/repo_list.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 869f414e8e1ab..fe32d71629c4f 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -172,8 +172,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err if !opts.Private { cond = cond.And(builder.Eq{"is_private": false}) - var accessCond = builder.NewCond() - accessCond = builder.Or( + accessCond := builder.Or( builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": VisibleTypeLimited}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization}))) cond = cond.And(accessCond) @@ -208,8 +207,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err exprCond = builder.Eq{"org_user.org_id": "user.id"} } - var visibilityCond = builder.NewCond() - visibilityCond = builder.Or( + visibilityCond := builder.Or( builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), builder.In("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": VisibleTypePublic}, builder.Eq{"visibility": VisibleTypeLimited}))), builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization})), From 88d250a56e60327cf78d9edb35c02c12d760b011 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Tue, 5 Feb 2019 22:05:08 -0500 Subject: [PATCH 114/124] Update org.go --- models/org.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/models/org.go b/models/org.go index add1cb8b5c8ea..7a3ae3e76ae35 100644 --- a/models/org.go +++ b/models/org.go @@ -12,6 +12,7 @@ import ( "strings" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/structs" "github.com/Unknwon/com" "github.com/go-xorm/builder" @@ -371,7 +372,7 @@ func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) { func HasOrgVisible(org *User, user *User) bool { // Not SignedUser if user == nil { - if org.Visibility == VisibleTypePublic { + if org.Visibility == structs.VisibleTypePublic { return true } return false @@ -380,10 +381,8 @@ func HasOrgVisible(org *User, user *User) bool { if user.IsAdmin { return true } - if org.Visibility == VisibleTypePrivate { - if org.IsUserPartOfOrg(user.ID) { - return true - } + + if org.Visibility == structs.VisibleTypePrivate && !org.IsUserPartOfOrg(user.ID) { return false } return true From 1afc0554e3faa1610195650f14831fae7ef778a9 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Tue, 5 Feb 2019 22:25:04 -0500 Subject: [PATCH 115/124] update per @lunny feedback --- models/repo_list.go | 7 ++++--- models/user.go | 8 ++++---- modules/auth/org.go | 5 +++-- modules/setting/setting.go | 4 ++-- modules/structs/{structs.go => org_type.go} | 13 ++++++++++++- routers/org/setting.go | 3 ++- templates/admin/org/list.tmpl | 2 +- templates/admin/repo/list.tmpl | 2 +- templates/explore/organizations.tmpl | 2 +- templates/org/create.tmpl | 6 +++--- templates/user/profile.tmpl | 2 +- 11 files changed, 34 insertions(+), 20 deletions(-) rename modules/structs/{structs.go => org_type.go} (70%) diff --git a/models/repo_list.go b/models/repo_list.go index fe32d71629c4f..0af1306e5a70b 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -8,6 +8,7 @@ import ( "fmt" "strings" + "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" "github.com/go-xorm/builder" @@ -173,7 +174,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err if !opts.Private { cond = cond.And(builder.Eq{"is_private": false}) accessCond := builder.Or( - builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": VisibleTypeLimited}, builder.Eq{"visibility": VisibleTypePrivate}))), + builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": structs.VisibleTypeLimited}, builder.Eq{"visibility": structs.VisibleTypePrivate}))), builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization}))) cond = cond.And(accessCond) } @@ -208,8 +209,8 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err } visibilityCond := builder.Or( - builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": VisibleTypePrivate}))), - builder.In("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": VisibleTypePublic}, builder.Eq{"visibility": VisibleTypeLimited}))), + builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": structs.VisibleTypePrivate}))), + builder.In("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": structs.VisibleTypePublic}, builder.Eq{"visibility": structs.VisibleTypeLimited}))), builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization})), ) cond = cond.And(visibilityCond) diff --git a/models/user.go b/models/user.go index a3cd5b9726c4a..bdce0da6848ec 100644 --- a/models/user.go +++ b/models/user.go @@ -26,14 +26,14 @@ import ( "unicode/utf8" "code.gitea.io/git" - api "code.gitea.io/sdk/gitea" - "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/avatar" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/generate" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" + api "code.gitea.io/sdk/gitea" "github.com/Unknwon/com" "github.com/go-xorm/builder" @@ -137,8 +137,8 @@ type User struct { Description string NumTeams int NumMembers int - Teams []*Team `xorm:"-"` - Members []*User `xorm:"-"` + Teams []*Team `xorm:"-"` + Members []*User `xorm:"-"` Visibility structs.VisibleType `xorm:"NOT NULL DEFAULT 0"` // Preferences diff --git a/modules/auth/org.go b/modules/auth/org.go index cd5342b707237..e4921c2267ee3 100644 --- a/modules/auth/org.go +++ b/modules/auth/org.go @@ -7,6 +7,7 @@ package auth import ( "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/structs" "github.com/go-macaron/binding" "gopkg.in/macaron.v1" @@ -22,7 +23,7 @@ import ( // CreateOrgForm form for creating organization type CreateOrgForm struct { OrgName string `binding:"Required;AlphaDashDot;MaxSize(35)" locale:"org.org_name_holder"` - Visibility models.VisibleType + Visibility structs.VisibleType } // Validate validates the fields @@ -37,7 +38,7 @@ type UpdateOrgSettingForm struct { Description string `binding:"MaxSize(255)"` Website string `binding:"ValidUrl;MaxSize(255)"` Location string `binding:"MaxSize(50)"` - Visibility models.VisibleType + Visibility structs.VisibleType MaxRepoCreation int } diff --git a/modules/setting/setting.go b/modules/setting/setting.go index d72f748c4a5de..2fb2c1d468759 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -624,7 +624,7 @@ func DateLang(lang string) string { } // ExtractKeysFromMapString provides a slice of keys from map -func ExtractKeysFromMapString(in map[string]int) (keys []string) { +func ExtractKeysFromMapString(in map[string]structs.VisibleType) (keys []string) { for k := range in { keys = append(keys, k) } @@ -1238,7 +1238,7 @@ func NewContext() { // Service settings var Service struct { DefaultVisibility string - DefaultVisibilityMode int + DefaultVisibilityMode structs.VisibleType ActiveCodeLives int ResetPwdCodeLives int RegisterEmailConfirm bool diff --git a/modules/structs/structs.go b/modules/structs/org_type.go similarity index 70% rename from modules/structs/structs.go rename to modules/structs/org_type.go index 346b29658ed30..944798df661c2 100644 --- a/modules/structs/structs.go +++ b/modules/structs/org_type.go @@ -19,9 +19,20 @@ const ( ) // VisibilityModes is a map of org Visibility types -var VisibilityModes = map[string]int{ +var VisibilityModes = map[string]VisibleType{ "public": VisibleTypePublic, "limited": VisibleTypeLimited, "private": VisibleTypePrivate, } +func (vt VisibleType) IsPublic() bool { + return vt == VisibleTypePublic +} + +func (vt VisibleType) IsLimited() bool { + return vt == VisibleTypeLimited +} + +func (vt VisibleType) IsPrivate() bool { + return vt == VisibleTypePrivate +} diff --git a/routers/org/setting.go b/routers/org/setting.go index 12f58e75b0633..1c4e75288a177 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/structs" userSetting "code.gitea.io/gitea/routers/user/setting" ) @@ -30,7 +31,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.Data["CurrentVisibility"] = structs.VisibleType(ctx.Org.Organization.Visibility) ctx.HTML(200, tplSettingsOptions) } diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl index c955ba955cfd8..80c6f94775aef 100644 --- a/templates/admin/org/list.tmpl +++ b/templates/admin/org/list.tmpl @@ -31,7 +31,7 @@ {{.ID}} {{.Name}} - {{if eq .Visibility 2}} + {{if .Visibility.IsPrivate() }} {{end}} diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index 44b3c148a500e..e2e13f6dfbb50 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -32,7 +32,7 @@ {{.ID}} {{.Owner.Name}} - {{if eq .Owner.Visibility 2}} + {{if .Owner.Visibility.IsPivate() }} {{end}} diff --git a/templates/explore/organizations.tmpl b/templates/explore/organizations.tmpl index 5578f8befdb92..5c833b32a2800 100644 --- a/templates/explore/organizations.tmpl +++ b/templates/explore/organizations.tmpl @@ -11,7 +11,7 @@
    {{.Name}} {{.FullName}} - {{if eq .Visibility 2}} + {{if .Visibility.IsPrivate() }} {{end}} diff --git a/templates/org/create.tmpl b/templates/org/create.tmpl index 02c074af7bd9d..5ef14825b591d 100644 --- a/templates/org/create.tmpl +++ b/templates/org/create.tmpl @@ -19,19 +19,19 @@
    - +
    - +
    - +
    diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 20fe4ad3ad91a..161db641c294f 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -64,7 +64,7 @@ {{if and .Orgs .HasOrgsVisible}}
  • {{range .Orgs}} - {{if (or (eq .Visibility 0) (and ($.SignedUser) (or (eq .Visibility 1) (and (.IsUserPartOfOrg $.SignedUserID) (eq .Visibility 2)) ($.IsAdmin))))}} + {{if (or .Visibility.IsPublic() (and ($.SignedUser) (or .Visibility.IsLimited() (and (.IsUserPartOfOrg $.SignedUserID) .Visibility.IsPrivate()) ($.IsAdmin))))}} {{end}} {{end}} From dfc6679b609682bb2e465927c55e111939653a7d Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Tue, 5 Feb 2019 22:29:31 -0500 Subject: [PATCH 116/124] split up lines --- models/repo_list.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 0af1306e5a70b..f318c229965f9 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -209,8 +209,19 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err } visibilityCond := builder.Or( - builder.In("owner_id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.OwnerID}, builder.Eq{"visibility": structs.VisibleTypePrivate}))), - builder.In("owner_id", builder.Select("id").From("`user`").Where(builder.Or(builder.Eq{"visibility": structs.VisibleTypePublic}, builder.Eq{"visibility": structs.VisibleTypeLimited}))), + builder.In("owner_id", + builder.Select("org_id").From("org_user"). + LeftJoin("`user`", exprCond). + Where( + builder.And( + builder.Eq{"uid": opts.OwnerID}, + builder.Eq{"visibility": structs.VisibleTypePrivate}))), + builder.In("owner_id", + builder.Select("id").From("`user`"). + Where( + builder.Or( + builder.Eq{"visibility": structs.VisibleTypePublic}, + builder.Eq{"visibility": structs.VisibleTypeLimited}))), builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization})), ) cond = cond.And(visibilityCond) From 0f999461c5259024121c6dc2d2316aaa8934f0e0 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Tue, 5 Feb 2019 22:31:23 -0500 Subject: [PATCH 117/124] fix build --- models/org_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/models/org_test.go b/models/org_test.go index dac399d9cb9d1..b484208be152d 100644 --- a/models/org_test.go +++ b/models/org_test.go @@ -7,6 +7,8 @@ package models import ( "testing" + "code.gitea.io/gitea/modules/structs" + "github.com/stretchr/testify/assert" ) @@ -554,7 +556,7 @@ func TestHasOrgVisibleTypePublic(t *testing.T) { const newOrgName = "test-org-public" org := &User{ Name: newOrgName, - Visibility: VisibleTypePublic, + Visibility: structs.VisibleTypePublic, } AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization}) @@ -577,7 +579,7 @@ func TestHasOrgVisibleTypeLimited(t *testing.T) { const newOrgName = "test-org-limited" org := &User{ Name: newOrgName, - Visibility: VisibleTypeLimited, + Visibility: structs.VisibleTypeLimited, } AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization}) @@ -600,7 +602,7 @@ func TestHasOrgVisibleTypePrivate(t *testing.T) { const newOrgName = "test-org-private" org := &User{ Name: newOrgName, - Visibility: VisibleTypePrivate, + Visibility: structs.VisibleTypePrivate, } AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization}) From c8e22a8a243f17819ac7214b50159a1ff19b0bc4 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Tue, 5 Feb 2019 22:35:10 -0500 Subject: [PATCH 118/124] fix build issues --- models/repo_list.go | 6 ++++-- modules/structs/org_type.go | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index f318c229965f9..83d2665e8c473 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -215,13 +215,15 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err Where( builder.And( builder.Eq{"uid": opts.OwnerID}, - builder.Eq{"visibility": structs.VisibleTypePrivate}))), + builder.Eq{"visibility": structs.VisibleTypePrivate})), + ), builder.In("owner_id", builder.Select("id").From("`user`"). Where( builder.Or( builder.Eq{"visibility": structs.VisibleTypePublic}, - builder.Eq{"visibility": structs.VisibleTypeLimited}))), + builder.Eq{"visibility": structs.VisibleTypeLimited})), + ), builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization})), ) cond = cond.And(visibilityCond) diff --git a/modules/structs/org_type.go b/modules/structs/org_type.go index 944798df661c2..99d885528f094 100644 --- a/modules/structs/org_type.go +++ b/modules/structs/org_type.go @@ -25,14 +25,17 @@ var VisibilityModes = map[string]VisibleType{ "private": VisibleTypePrivate, } +// IsPublic returns true if VisibleType is public func (vt VisibleType) IsPublic() bool { return vt == VisibleTypePublic } +// IsLimited returns true if VisibleType is limited func (vt VisibleType) IsLimited() bool { return vt == VisibleTypeLimited } +// IsPrivate returns true if VisibleType is private func (vt VisibleType) IsPrivate() bool { return vt == VisibleTypePrivate } From 3423b2e2454c3d822e42158638dc6ab378c9c342 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Tue, 5 Feb 2019 22:40:10 -0500 Subject: [PATCH 119/124] Update create.tmpl --- templates/org/create.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/org/create.tmpl b/templates/org/create.tmpl index 5ef14825b591d..c39d9323b91fa 100644 --- a/templates/org/create.tmpl +++ b/templates/org/create.tmpl @@ -25,13 +25,13 @@
  • - +
    - +
    From 3994a5af9bd2bbdad960c9c70a1deca6127089be Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Tue, 5 Feb 2019 22:40:42 -0500 Subject: [PATCH 120/124] Update repo_list.tmpl --- 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 a8d96ded4d4a0..fb738d62af190 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -13,7 +13,7 @@ {{else if .IsMirror}} {{else if .Owner}} - {{if eq .Owner.Visibility 2}} + {{if eq .Owner.Visibility.IsPrivate()}} {{end}} {{end}} From bd0add36635c47a606295e34768b96ec027cb801 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Tue, 5 Feb 2019 22:42:32 -0500 Subject: [PATCH 121/124] update templates --- templates/admin/org/list.tmpl | 2 +- templates/admin/repo/list.tmpl | 2 +- templates/explore/organizations.tmpl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl index 80c6f94775aef..dfcc28ca9c12f 100644 --- a/templates/admin/org/list.tmpl +++ b/templates/admin/org/list.tmpl @@ -31,7 +31,7 @@ {{.ID}} {{.Name}} - {{if .Visibility.IsPrivate() }} + {{if .Visibility.IsPrivate()}} {{end}} diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index e2e13f6dfbb50..f2c2b621d65c9 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -32,7 +32,7 @@ {{.ID}} {{.Owner.Name}} - {{if .Owner.Visibility.IsPivate() }} + {{if .Owner.Visibility.IsPrivate()}} {{end}} diff --git a/templates/explore/organizations.tmpl b/templates/explore/organizations.tmpl index 5c833b32a2800..a8b1d1b7343f7 100644 --- a/templates/explore/organizations.tmpl +++ b/templates/explore/organizations.tmpl @@ -11,7 +11,7 @@
    {{.Name}} {{.FullName}} - {{if .Visibility.IsPrivate() }} + {{if .Visibility.IsPrivate()}} {{end}} From 955ff90cc36a7b3449e1f87e13b8c12af85963e2 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Tue, 5 Feb 2019 22:53:20 -0500 Subject: [PATCH 122/124] update templates --- templates/admin/org/list.tmpl | 2 +- templates/admin/repo/list.tmpl | 2 +- templates/explore/organizations.tmpl | 2 +- templates/explore/repo_list.tmpl | 2 +- templates/org/create.tmpl | 6 +++--- templates/user/profile.tmpl | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl index dfcc28ca9c12f..e9dbc7f8777e1 100644 --- a/templates/admin/org/list.tmpl +++ b/templates/admin/org/list.tmpl @@ -31,7 +31,7 @@ {{.ID}} {{.Name}} - {{if .Visibility.IsPrivate()}} + {{if .Visibility.IsPrivate}} {{end}} diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index f2c2b621d65c9..278bb7263b202 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -32,7 +32,7 @@ {{.ID}} {{.Owner.Name}} - {{if .Owner.Visibility.IsPrivate()}} + {{if .Owner.Visibility.IsPrivate}} {{end}} diff --git a/templates/explore/organizations.tmpl b/templates/explore/organizations.tmpl index a8b1d1b7343f7..4e2bfc9fd9a94 100644 --- a/templates/explore/organizations.tmpl +++ b/templates/explore/organizations.tmpl @@ -11,7 +11,7 @@
    {{.Name}} {{.FullName}} - {{if .Visibility.IsPrivate()}} + {{if .Visibility.IsPrivate}} {{end}} diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index fb738d62af190..94ce2933896dd 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -13,7 +13,7 @@ {{else if .IsMirror}} {{else if .Owner}} - {{if eq .Owner.Visibility.IsPrivate()}} + {{if .Owner.Visibility.IsPrivate}} {{end}} {{end}} diff --git a/templates/org/create.tmpl b/templates/org/create.tmpl index c39d9323b91fa..11bdff72b1788 100644 --- a/templates/org/create.tmpl +++ b/templates/org/create.tmpl @@ -19,19 +19,19 @@
    - +
    - +
    - +
    diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 161db641c294f..b3a500e9f682e 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -64,7 +64,7 @@ {{if and .Orgs .HasOrgsVisible}}
  • {{range .Orgs}} - {{if (or .Visibility.IsPublic() (and ($.SignedUser) (or .Visibility.IsLimited() (and (.IsUserPartOfOrg $.SignedUserID) .Visibility.IsPrivate()) ($.IsAdmin))))}} + {{if (or .Visibility.IsPublic (and ($.SignedUser) (or .Visibility.IsLimited (and (.IsUserPartOfOrg $.SignedUserID) .Visibility.IsPrivate) ($.IsAdmin))))}} {{end}} {{end}} From eb4e19d7d531cd495cb773cc7fe87bbfa083e722 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Tue, 5 Feb 2019 23:29:09 -0500 Subject: [PATCH 123/124] rename DefaultVisibility to DefaultOrgVisibility --- modules/setting/setting.go | 8 ++++---- routers/org/org.go | 2 +- templates/admin/config.tmpl | 2 +- templates/org/create.tmpl | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 9a2c422c23116..03f1d6b5302e5 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -1239,8 +1239,8 @@ func NewContext() { // Service settings var Service struct { - DefaultVisibility string - DefaultVisibilityMode structs.VisibleType + DefaultOrgVisibility string + DefaultOrgVisibilityMode structs.VisibleType ActiveCodeLives int ResetPwdCodeLives int RegisterEmailConfirm bool @@ -1300,8 +1300,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.EnableUserHeatmap = sec.Key("ENABLE_USER_HEATMAP").MustBool(true) - Service.DefaultVisibility = sec.Key("DEFAULT_ORG_VISIBILITY").In("public", ExtractKeysFromMapString(structs.VisibilityModes)) - Service.DefaultVisibilityMode = structs.VisibilityModes[Service.DefaultVisibility] + Service.DefaultOrgVisibility = sec.Key("DEFAULT_ORG_VISIBILITY").In("public", ExtractKeysFromMapString(structs.VisibilityModes)) + Service.DefaultOrgVisibilityMode = structs.VisibilityModes[Service.DefaultOrgVisibility] Service.AutoWatchNewRepos = sec.Key("AUTO_WATCH_NEW_REPOS").MustBool(true) sec = Cfg.Section("openid") diff --git a/routers/org/org.go b/routers/org/org.go index 010f12350b615..3821b32216e77 100644 --- a/routers/org/org.go +++ b/routers/org/org.go @@ -24,7 +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 + ctx.Data["DefaultOrgVisibilityMode"] = setting.Service.DefaultOrgVisibilityMode if !ctx.User.CanCreateOrganization() { ctx.ServerError("Not allowed", errors.New(ctx.Tr("org.form.create_org_not_allowed"))) return diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl index ba699fd8a7920..c76329b49c925 100644 --- a/templates/admin/config.tmpl +++ b/templates/admin/config.tmpl @@ -149,7 +149,7 @@
    {{end}}
    {{.i18n.Tr "admin.config.default_visibility_organization"}}
    -
    {{.Service.DefaultVisibility}}
    +
    {{.Service.DefaultOrgVisibility}}
    {{.i18n.Tr "admin.config.no_reply_address"}}
    {{if .Service.NoReplyAddress}}{{.Service.NoReplyAddress}}{{else}}-{{end}}
    diff --git a/templates/org/create.tmpl b/templates/org/create.tmpl index 11bdff72b1788..acf914c9d412a 100644 --- a/templates/org/create.tmpl +++ b/templates/org/create.tmpl @@ -19,19 +19,19 @@
    - +
    - +
    - +
    From fae9107a7bf7a89a7efa8619031f154e940a8e3b Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Sat, 9 Feb 2019 23:47:08 -0500 Subject: [PATCH 124/124] fix build --- modules/structs/org_type.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/structs/org_type.go b/modules/structs/org_type.go index fbfe9faf0c20b..86dc5c81cd6ab 100644 --- a/modules/structs/org_type.go +++ b/modules/structs/org_type.go @@ -41,7 +41,7 @@ func (vt VisibleType) IsPrivate() bool { } // ExtractKeysFromMapString provides a slice of keys from map -func ExtractKeysFromMapString(in map[string]structs.VisibleType) (keys []string) { +func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) { for k := range in { keys = append(keys, k) }