Skip to content

Commit 91012b5

Browse files
authored
Merge branch 'master' into oidc-core-implementation
2 parents 65dd5bf + 3175d08 commit 91012b5

35 files changed

+1335
-3700
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ rules:
346346
unicorn/catch-error-name: [0]
347347
unicorn/consistent-function-scoping: [2]
348348
unicorn/custom-error-definition: [0]
349+
unicorn/empty-brace-spaces: [2]
349350
unicorn/error-message: [0]
350351
unicorn/escape-case: [0]
351352
unicorn/expiring-todo-comments: [0]
@@ -361,6 +362,7 @@ rules:
361362
unicorn/no-for-loop: [0]
362363
unicorn/no-hex-escape: [0]
363364
unicorn/no-keyword-prefix: [0]
365+
unicorn/no-lonely-if: [2]
364366
unicorn/no-nested-ternary: [0]
365367
unicorn/no-new-buffer: [0]
366368
unicorn/no-null: [0]
@@ -377,6 +379,7 @@ rules:
377379
unicorn/prefer-add-event-listener: [2]
378380
unicorn/prefer-array-find: [2]
379381
unicorn/prefer-dataset: [2]
382+
unicorn/prefer-date-now: [2]
380383
unicorn/prefer-event-key: [2]
381384
unicorn/prefer-includes: [2]
382385
unicorn/prefer-math-trunc: [2]

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ lint: lint-frontend lint-backend
317317

318318
.PHONY: lint-frontend
319319
lint-frontend: node_modules
320-
npx eslint --max-warnings=0 web_src/js build templates webpack.config.js
321-
npx stylelint --max-warnings=0 web_src/less
320+
npx eslint --color --max-warnings=0 web_src/js build templates webpack.config.js
321+
npx stylelint --color --max-warnings=0 web_src/less
322322

323323
.PHONY: lint-backend
324324
lint-backend: golangci-lint revive vet
@@ -330,7 +330,7 @@ watch:
330330
.PHONY: watch-frontend
331331
watch-frontend: node-check node_modules
332332
rm -rf $(WEBPACK_DEST_ENTRIES)
333-
NODE_ENV=development npx webpack --hide-modules --display-entrypoints=false --watch --progress
333+
NODE_ENV=development npx webpack --watch --progress
334334

335335
.PHONY: watch-backend
336336
watch-backend: go-check
@@ -660,7 +660,7 @@ webpack: $(WEBPACK_DEST)
660660

661661
$(WEBPACK_DEST): $(WEBPACK_SOURCES) $(WEBPACK_CONFIGS) package-lock.json | node_modules
662662
rm -rf $(WEBPACK_DEST_ENTRIES)
663-
npx webpack --hide-modules --display-entrypoints=false
663+
npx webpack
664664
@touch $(WEBPACK_DEST)
665665

666666
.PHONY: svg

cmd/admin.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ var (
282282
Value: "",
283283
Usage: "Use a custom Email URL (option for GitHub)",
284284
},
285+
cli.StringFlag{
286+
Name: "icon-url",
287+
Value: "",
288+
Usage: "Custom icon URL for OAuth2 login source",
289+
},
285290
}
286291

287292
microcmdAuthUpdateOauth = cli.Command{
@@ -606,6 +611,7 @@ func parseOAuth2Config(c *cli.Context) *models.OAuth2Config {
606611
ClientSecret: c.String("secret"),
607612
OpenIDConnectAutoDiscoveryURL: c.String("auto-discover-url"),
608613
CustomURLMapping: customURLMapping,
614+
IconURL: c.String("icon-url"),
609615
}
610616
}
611617

@@ -658,6 +664,10 @@ func runUpdateOauth(c *cli.Context) error {
658664
oAuth2Config.OpenIDConnectAutoDiscoveryURL = c.String("auto-discover-url")
659665
}
660666

667+
if c.IsSet("icon-url") {
668+
oAuth2Config.IconURL = c.String("icon-url")
669+
}
670+
661671
// update custom URL mapping
662672
var customURLMapping = &oauth2.CustomURLMapping{}
663673

docs/content/doc/installation/database-preparation.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ You need a database to use Gitea. Gitea supports PostgreSQL, MySQL, SQLite, and
1919

2020
Database instance can be on same machine as Gitea (local database setup), or on different machine (remote database).
2121

22-
Note: All steps below requires that the database engine of your choice is installed on your system. For remote database setup, install the server part on database instance and client part on your Gitea server. In addition, make sure you use same engine version for both server and client for some engine features to work. For security reason, protect `root` (MySQL) or `postgres` (PostgreSQL) database superuser with secure password. The steps assumes that you run Linux for both database and Gitea servers.
22+
Note: All steps below requires that the database engine of your choice is installed on your system. For remote database setup, install the server application on database instance and client program on your Gitea server. The client program is used to test connection to the database from Gitea server, while Gitea itself use database driver provided by Go to accomplish the same thing. In addition, make sure you use same engine version for both server and client for some engine features to work. For security reason, protect `root` (MySQL) or `postgres` (PostgreSQL) database superuser with secure password. The steps assumes that you run Linux for both database and Gitea servers.
2323

2424
**Table of Contents**
2525

docs/content/doc/usage/command-line.en-us.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Admin operations:
114114
- `--custom-token-url`: Use a custom Token URL (option for GitLab/GitHub).
115115
- `--custom-profile-url`: Use a custom Profile URL (option for GitLab/GitHub).
116116
- `--custom-email-url`: Use a custom Email URL (option for GitHub).
117+
- `--icon-url`: Custom icon URL for OAuth2 login source.
117118
- Examples:
118119
- `gitea admin auth add-oauth --name external-github --provider github --key OBTAIN_FROM_SOURCE --secret OBTAIN_FROM_SOURCE`
119120
- `update-oauth`:
@@ -129,6 +130,7 @@ Admin operations:
129130
- `--custom-token-url`: Use a custom Token URL (option for GitLab/GitHub).
130131
- `--custom-profile-url`: Use a custom Profile URL (option for GitLab/GitHub).
131132
- `--custom-email-url`: Use a custom Email URL (option for GitHub).
133+
- `--icon-url`: Custom icon URL for OAuth2 login source.
132134
- Examples:
133135
- `gitea admin auth update-oauth --id 1 --name external-github-updated`
134136
- `add-ldap`: Add new LDAP (via Bind DN) authentication source
@@ -465,4 +467,4 @@ Restore-repo restore repository data from disk dir:
465467
- `--repo_dir dir`, `-r dir`: Repository dir path to restore from
466468
- `--owner_name lunny`: Restore destination owner name
467469
- `--repo_name tango`: Restore destination repository name
468-
- `--units <units>`: Which items will be restored, one or more units should be separated as comma. wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.
470+
- `--units <units>`: Which items will be restored, one or more units should be separated as comma. wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.

models/action.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ func (a *Action) GetIssueContent() string {
289289
// GetFeedsOptions options for retrieving feeds
290290
type GetFeedsOptions struct {
291291
RequestedUser *User // the user we want activity for
292+
RequestedTeam *Team // the team we want activity for
292293
Actor *User // the user viewing the activity
293294
IncludePrivate bool // include private actions
294295
OnlyPerformedBy bool // only actions performed by requested user
@@ -357,6 +358,15 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
357358
}
358359
}
359360

361+
if opts.RequestedTeam != nil {
362+
env := opts.RequestedUser.AccessibleTeamReposEnv(opts.RequestedTeam)
363+
teamRepoIDs, err := env.RepoIDs(1, opts.RequestedUser.NumRepos)
364+
if err != nil {
365+
return nil, fmt.Errorf("GetTeamRepositories: %v", err)
366+
}
367+
cond = cond.And(builder.In("repo_id", teamRepoIDs))
368+
}
369+
360370
cond = cond.And(builder.Eq{"user_id": opts.RequestedUser.ID})
361371

362372
if opts.OnlyPerformedBy {

models/login_source.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ type OAuth2Config struct {
131131
ClientSecret string
132132
OpenIDConnectAutoDiscoveryURL string
133133
CustomURLMapping *oauth2.CustomURLMapping
134+
IconURL string
134135
}
135136

136137
// FromDB fills up an OAuth2Config from serialized format.

models/oauth2.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ func GetActiveOAuth2Providers() ([]string, map[string]OAuth2Provider, error) {
111111
var orderedKeys []string
112112
providers := make(map[string]OAuth2Provider)
113113
for _, source := range loginSources {
114-
providers[source.Name] = OAuth2Providers[source.OAuth2().Provider]
114+
prov := OAuth2Providers[source.OAuth2().Provider]
115+
if source.OAuth2().IconURL != "" {
116+
prov.Image = source.OAuth2().IconURL
117+
}
118+
providers[source.Name] = prov
115119
orderedKeys = append(orderedKeys, source.Name)
116120
}
117121

models/org.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ type AccessibleReposEnvironment interface {
746746
type accessibleReposEnv struct {
747747
org *User
748748
user *User
749+
team *Team
749750
teamIDs []int64
750751
e Engine
751752
keyword string
@@ -782,16 +783,31 @@ func (org *User) accessibleReposEnv(e Engine, userID int64) (AccessibleReposEnvi
782783
}, nil
783784
}
784785

786+
// AccessibleTeamReposEnv an AccessibleReposEnvironment for the repositories in `org`
787+
// that are accessible to the specified team.
788+
func (org *User) AccessibleTeamReposEnv(team *Team) AccessibleReposEnvironment {
789+
return &accessibleReposEnv{
790+
org: org,
791+
team: team,
792+
e: x,
793+
orderBy: SearchOrderByRecentUpdated,
794+
}
795+
}
796+
785797
func (env *accessibleReposEnv) cond() builder.Cond {
786798
var cond = builder.NewCond()
787-
if env.user == nil || !env.user.IsRestricted {
788-
cond = cond.Or(builder.Eq{
789-
"`repository`.owner_id": env.org.ID,
790-
"`repository`.is_private": false,
791-
})
792-
}
793-
if len(env.teamIDs) > 0 {
794-
cond = cond.Or(builder.In("team_repo.team_id", env.teamIDs))
799+
if env.team != nil {
800+
cond = cond.And(builder.Eq{"team_repo.team_id": env.team.ID})
801+
} else {
802+
if env.user == nil || !env.user.IsRestricted {
803+
cond = cond.Or(builder.Eq{
804+
"`repository`.owner_id": env.org.ID,
805+
"`repository`.is_private": false,
806+
})
807+
}
808+
if len(env.teamIDs) > 0 {
809+
cond = cond.Or(builder.In("team_repo.team_id", env.teamIDs))
810+
}
795811
}
796812
if env.keyword != "" {
797813
cond = cond.And(builder.Like{"`repository`.lower_name", strings.ToLower(env.keyword)})

models/repo_list.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ type SearchRepoOptions struct {
138138
Keyword string
139139
OwnerID int64
140140
PriorityOwnerID int64
141+
TeamID int64
141142
OrderBy SearchOrderBy
142143
Private bool // Include private repositories in results
143144
StarredByID int64
@@ -294,6 +295,10 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
294295
cond = cond.And(accessCond)
295296
}
296297

298+
if opts.TeamID > 0 {
299+
cond = cond.And(builder.In("`repository`.id", builder.Select("`team_repo`.repo_id").From("team_repo").Where(builder.Eq{"`team_repo`.team_id": opts.TeamID})))
300+
}
301+
297302
if opts.Keyword != "" {
298303
// separate keyword
299304
var subQueryCond = builder.NewCond()

models/user_heatmap.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ type UserHeatmapData struct {
1717

1818
// GetUserHeatmapDataByUser returns an array of UserHeatmapData
1919
func GetUserHeatmapDataByUser(user *User, doer *User) ([]*UserHeatmapData, error) {
20+
return getUserHeatmapData(user, nil, doer)
21+
}
22+
23+
// GetUserHeatmapDataByUserTeam returns an array of UserHeatmapData
24+
func GetUserHeatmapDataByUserTeam(user *User, team *Team, doer *User) ([]*UserHeatmapData, error) {
25+
return getUserHeatmapData(user, team, doer)
26+
}
27+
28+
func getUserHeatmapData(user *User, team *Team, doer *User) ([]*UserHeatmapData, error) {
2029
hdata := make([]*UserHeatmapData, 0)
2130

2231
if !activityReadable(user, doer) {
@@ -39,6 +48,7 @@ func GetUserHeatmapDataByUser(user *User, doer *User) ([]*UserHeatmapData, error
3948

4049
cond, err := activityQueryCondition(GetFeedsOptions{
4150
RequestedUser: user,
51+
RequestedTeam: team,
4252
Actor: doer,
4353
IncludePrivate: true, // don't filter by private, as we already filter by repo access
4454
IncludeDeleted: true,

modules/auth/auth_form.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type AuthenticationForm struct {
5656
Oauth2AuthURL string
5757
Oauth2ProfileURL string
5858
Oauth2EmailURL string
59+
Oauth2IconURL string
5960
SSPIAutoCreateUsers bool
6061
SSPIAutoActivateUsers bool
6162
SSPIStripDomainNames bool

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ my_mirrors = My Mirrors
216216
view_home = View %s
217217
search_repos = Find a repository…
218218
filter = Other Filters
219+
filter_by_team_repositories = Filter by team repositories
219220
220221
show_archived = Archived
221222
show_both_archived_unarchived = Showing both archived and unarchived
@@ -2202,6 +2203,7 @@ auths.enable_tls = Enable TLS Encryption
22022203
auths.skip_tls_verify = Skip TLS Verify
22032204
auths.pam_service_name = PAM Service Name
22042205
auths.oauth2_provider = OAuth2 Provider
2206+
auths.oauth2_icon_url = Icon URL
22052207
auths.oauth2_clientID = Client ID (Key)
22062208
auths.oauth2_clientSecret = Client Secret
22072209
auths.openIdConnectAutoDiscoveryURL = OpenID Connect Auto Discovery URL

options/locale/locale_tr-TR.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ my_mirrors=Yansılarım
216216
view_home=%s Görüntüle
217217
search_repos=Depo bul…
218218
filter=Diğer Süzgeçler
219+
filter_by_team_repositories=Takım depolarına göre süz
219220
220221
show_archived=Arşivlenmiş
221222
show_both_archived_unarchived=Arşivlenenler ve arşivlenmeyenlerin hepsi gösteriliyor

options/locale/locale_zh-TW.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ principal_state_desc=此主體在過去 7 天內曾被使用
554554
show_openid=在個人資料顯示
555555
hide_openid=從個人資料隱藏
556556
ssh_disabled=已停用 SSH
557+
ssh_externally_managed=此 SSH 金鑰由此使用者的外部服務所管理
557558
manage_social=管理關聯的社群帳戶
558559
social_desc=這些社群帳戶已經連結到你的 Gitea 帳戶。請確保您認得這些帳戶,因為這些帳戶能用來登入寧的 Gitea 帳戶。
559560
unbind=解除連結

0 commit comments

Comments
 (0)