Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* giteaofficial/main:
  Fix i18n for Link Account button, re-format tmpl (go-gitea#19835)
  [skip ci] Updated translations via Crowdin
  Adding button to link accounts from user settings (go-gitea#19792)
  fix(telegram): fix link bot to release tag (go-gitea#19830)
  Fix raw endpoint PDF file headers (go-gitea#19825)
  • Loading branch information
zjjhot committed May 29, 2022
2 parents 2bb0c27 + e0273ba commit 99bbcfa
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 32 deletions.
8 changes: 6 additions & 2 deletions modules/typesniffer/typesniffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ import (
// Use at most this many bytes to determine Content Type.
const sniffLen = 1024

// SvgMimeType MIME type of SVG images.
const SvgMimeType = "image/svg+xml"
const (
// SvgMimeType MIME type of SVG images.
SvgMimeType = "image/svg+xml"
// ApplicationOctetStream MIME type of binary files.
ApplicationOctetStream = "application/octet-stream"
)

var (
svgTagRegex = regexp.MustCompile(`(?si)\A\s*(?:(<!--.*?-->|<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg[\s>\/]`)
Expand Down
18 changes: 9 additions & 9 deletions options/locale/locale_el-GR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ code.desc=Πρόσβαση στον πηγαίο κώδικα, αρχεία, υ
branch=Κλάδος
tree=Δέντρο
clear_ref=`Καθαρισμός τρέχουσας αναφοράς`
filter_branch_and_tag=Φιλτράρισμα κλάδου ή ετικέτας
filter_branch_and_tag=Φίλτρο κλάδου ή ετικέτας
find_tag=Εύρεση ετικέτας
branches=Κλάδοι
tags=Ετικέτες
Expand Down Expand Up @@ -1528,8 +1528,8 @@ pulls.still_in_progress=Ακόμα είναι σε εξέλιξη;
pulls.add_prefix=Προσθήκη <strong>%s</strong> προθέματος
pulls.remove_prefix=Αφαίρεση <strong>%s</strong> προθέματος
pulls.data_broken=Αυτό το pull request είναι κατεστραμμένο λόγω των πληροφοριών του fork που λείπουν.
pulls.files_conflicted=Αυτό το pull request έχει αλλαγές που έρχονται σε σύγκρουση με το κλάδο που στοχεύει.
pulls.is_checking=Η συγχώνευση ελέγχου σύγκρουσης είναι σε εξέλιξη. Δοκιμάστε ξανά σε λίγα λεπτά.
pulls.files_conflicted=Αυτό το pull request περιέχει αλλαγές που συγκρούονται με το κλάδο προορισμού.
pulls.is_checking=Ο έλεγχος συγκρούσεων κατά την συγχώνευση είναι σε εξέλιξη. Δοκιμάστε ξανά σε λίγα λεπτά.
pulls.is_empty=Αυτός ο κλάδος είναι ίσος με τον κλάδο-στόχο.
pulls.required_status_check_failed=Ορισμένοι απαιτούμενοι έλεγχοι δεν ήταν επιτυχείς.
pulls.required_status_check_missing=Λείπουν ορισμένοι απαιτούμενοι έλεγχοι.
Expand All @@ -1542,9 +1542,9 @@ pulls.blocked_by_changed_protected_files_1=Αυτό το Pull Request έχει
pulls.blocked_by_changed_protected_files_n=Αυτό το Pull Request έχει αποκλειστεί επειδή αλλάζει προστατευμένα αρχεία:
pulls.can_auto_merge_desc=Αυτό το Pull Request μπορεί να συγχωνευθεί αυτόματα.
pulls.cannot_auto_merge_desc=Αυτό το pull request δεν μπορεί να συγχωνευθεί αυτόματα λόγω συγκρούσεων.
pulls.cannot_auto_merge_helper=Συγχώνευση χειροκίνητα για την επίλυση των συγκρούσεων.
pulls.num_conflicting_files_1=%d αλληλοσυγκρουόμενο αρχείο
pulls.num_conflicting_files_n=%d αλληλοσυγκρουόμενα αρχεία
pulls.cannot_auto_merge_helper=Χειροκίνητη Συγχώνευση για την επίλυση των συγκρούσεων.
pulls.num_conflicting_files_1=%d αρχείο σε σύγκρουση
pulls.num_conflicting_files_n=%d αρχεία σε σύγκρουση
pulls.approve_count_1=%d έγκριση
pulls.approve_count_n=%d εγκρίσεις
pulls.reject_count_1=%d αίτημα αλλαγής
Expand Down Expand Up @@ -1576,7 +1576,7 @@ pulls.squash_merge_pull_request_on_status_success=Στρίμωγμα και Συ
pulls.invalid_merge_option=Δεν μπορείτε να χρησιμοποιήσετε αυτήν την επιλογή συγχώνευσης για αυτό το pull request.
pulls.merge_conflict=Η Συγχώνευση Απέτυχε: Υπήρξε μια διένεξη κατά τη συγχώνευση. Υπόδειξη: Δοκιμάστε μια διαφορετική στρατηγική
pulls.merge_conflict_summary=Μήνυμα Σφάλματος
pulls.rebase_conflict=Η Συγχώνευση Απέτυχε: Υπήρξε μια διένεξη κατά την αλλαγή βάσης της υποβολής: %[1]s. Υπόδειξη: Δοκιμάστε μια διαφορετική στρατηγική
pulls.rebase_conflict=Η Συγχώνευση Απέτυχε: Υπήρξε μια σύγκρουση κατά την αλλαγή βάσης της υποβολής: %[1]s. Υπόδειξη: Δοκιμάστε μια διαφορετική στρατηγική
pulls.rebase_conflict_summary=Μήνυμα Σφάλματος
; </summary><code>%[2]s<br>%[3]s</code></details>
pulls.unrelated_histories=H Συγχώνευση Απέτυχε: Η κεφαλή και η βάση της συγχώνευσης δεν μοιράζονται μια κοινή ιστορία. Συμβουλή: Δοκιμάστε μια διαφορετική στρατηγική
Expand Down Expand Up @@ -1791,7 +1791,7 @@ settings.site=Ιστοσελίδα
settings.update_settings=Ενημέρωση Ρυθμίσεων
settings.branches.update_default_branch=Ενημέρωση Προεπιλεγμένου Κλάδου
settings.advanced_settings=Ρυθμίσεις Για Προχωρημένους
settings.wiki_desc=Ενεργοποίηση Wiki Αποθετηρίου
settings.wiki_desc=Ενεργοποίηση Wiki
settings.use_internal_wiki=Χρήση Εσωτερικού Wiki
settings.use_external_wiki=Χρήση Εξωτερικού Wiki
settings.external_wiki_url=URL Εξωτερικού Wiki
Expand All @@ -1805,7 +1805,7 @@ settings.external_tracker_url_error=Το URL της εξωτερικής υπη
settings.external_tracker_url_desc=Οι επισκέπτες ανακατευθύνονται στο URL εξωτερικής υπηρεσίας ζητημάτων όταν κάνετε κλικ στην καρτέλα ζητήματα.
settings.tracker_url_format=Μορφή URL Εξωτερικής Υπηρεσίας Ζητημάτων
settings.tracker_url_format_error=Η μορφή URL της εξωτερικής υπηρεσίας ζητήματων δεν είναι έγκυρη διεύθυνση URL.
settings.tracker_issue_style=Μορφή Αριθμών Εξωτερικής Υπηρεσίας Ζητημάτων
settings.tracker_issue_style=Αρίθμηση Εξωτερικής Υπηρεσίας Ζητημάτων
settings.tracker_issue_style.numeric=Αριθμητικό
settings.tracker_issue_style.alphanumeric=Αλφαριθμητικό
settings.tracker_url_format_desc=Χρησιμοποιήστε τα <code>{user}</code>, <code>{repo}</code> και <code>{index}</code> για το όνομα χρήστη, το όνομα αποθετηρίου και το ευρετήριο ζητημάτων.
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ webauthn_delete_key_desc = If you remove a security key you can no longer sign i
manage_account_links = Manage Linked Accounts
manage_account_links_desc = These external accounts are linked to your Gitea account.
account_links_not_available = There are currently no external accounts linked to your Gitea account.
link_account = Link Account
remove_account_link = Remove Linked Account
remove_account_link_desc = Removing a linked account will revoke its access to your Gitea account. Continue?
remove_account_link_success = The linked account has been removed.
Expand Down
8 changes: 6 additions & 2 deletions routers/common/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ func ServeData(ctx *context.Context, name string, size int64, reader io.Reader)
}
if (st.IsImage() || st.IsPDF()) && (setting.UI.SVG.Enabled || !st.IsSvgImage()) {
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, name))
if st.IsSvgImage() {
if st.IsSvgImage() || st.IsPDF() {
ctx.Resp.Header().Set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; sandbox")
ctx.Resp.Header().Set("X-Content-Type-Options", "nosniff")
ctx.Resp.Header().Set("Content-Type", typesniffer.SvgMimeType)
if st.IsSvgImage() {
ctx.Resp.Header().Set("Content-Type", typesniffer.SvgMimeType)
} else {
ctx.Resp.Header().Set("Content-Type", typesniffer.ApplicationOctetStream)
}
}
} else {
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name))
Expand Down
12 changes: 11 additions & 1 deletion routers/web/auth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,17 @@ func SignInOAuthCallback(ctx *context.Context) {
}

if u == nil {
if !setting.Service.AllowOnlyInternalRegistration && setting.OAuth2Client.EnableAutoRegistration {
if ctx.Doer != nil {
// attach user to already logged in user
err = externalaccount.LinkAccountToUser(ctx.Doer, gothUser)
if err != nil {
ctx.ServerError("UserLinkAccount", err)
return
}

ctx.Redirect(setting.AppSubURL + "/user/settings/security")
return
} else if !setting.Service.AllowOnlyInternalRegistration && setting.OAuth2Client.EnableAutoRegistration {
// create new user with details from oauth2 provider
var missingFields []string
if gothUser.UserID == "" {
Expand Down
9 changes: 9 additions & 0 deletions routers/web/user/setting/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/auth/source/oauth2"
)

const (
Expand Down Expand Up @@ -109,6 +110,14 @@ func loadSecurityData(ctx *context.Context) {
}
ctx.Data["AccountLinks"] = sources

orderedOAuth2Names, oauth2Providers, err := oauth2.GetActiveOAuth2Providers()
if err != nil {
ctx.ServerError("GetActiveOAuth2Providers", err)
return
}
ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names
ctx.Data["OAuth2Providers"] = oauth2Providers

openid, err := user_model.GetUserOpenIDs(ctx.Doer.ID)
if err != nil {
ctx.ServerError("GetUserOpenIDs", err)
Expand Down
8 changes: 4 additions & 4 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,6 @@ func RegisterRoutes(m *web.Route) {
}, openIDSignInEnabled)
m.Get("/sign_up", auth.SignUp)
m.Post("/sign_up", bindIgnErr(forms.RegisterForm{}), auth.SignUpPost)
m.Group("/oauth2", func() {
m.Get("/{provider}", auth.SignInOAuth)
m.Get("/{provider}/callback", auth.SignInOAuthCallback)
})
m.Get("/link_account", linkAccountEnabled, auth.LinkAccount)
m.Post("/link_account_signin", linkAccountEnabled, bindIgnErr(forms.SignInForm{}), auth.LinkAccountPostSignIn)
m.Post("/link_account_signup", linkAccountEnabled, bindIgnErr(forms.RegisterForm{}), auth.LinkAccountPostRegister)
Expand Down Expand Up @@ -452,6 +448,10 @@ func RegisterRoutes(m *web.Route) {
m.Get("/task/{task}", reqSignIn, user.TaskStatus)
m.Get("/stopwatches", reqSignIn, user.GetStopwatches)
m.Get("/search", ignExploreSignIn, user.Search)
m.Group("/oauth2", func() {
m.Get("/{provider}", auth.SignInOAuth)
m.Get("/{provider}/callback", auth.SignInOAuthCallback)
})
})
// ***** END: User *****

Expand Down
2 changes: 1 addition & 1 deletion services/webhook/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func getPullRequestPayloadInfo(p *api.PullRequestPayload, linkFormatter linkForm

func getReleasePayloadInfo(p *api.ReleasePayload, linkFormatter linkFormatter, withSender bool) (text string, color int) {
repoLink := linkFormatter(p.Repository.HTMLURL, p.Repository.FullName)
refLink := linkFormatter(p.Repository.HTMLURL+"/src/"+util.PathEscapeSegments(p.Release.TagName), p.Release.TagName)
refLink := linkFormatter(p.Repository.HTMLURL+"/releases/tag/"+util.PathEscapeSegments(p.Release.TagName), p.Release.TagName)

switch p.Action {
case api.HookReleasePublished:
Expand Down
4 changes: 2 additions & 2 deletions services/webhook/matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ func TestMatrixPayload(t *testing.T) {
require.NotNil(t, pl)
require.IsType(t, &MatrixPayloadUnsafe{}, pl)

assert.Equal(t, "[[test/repo](http://localhost:3000/test/repo)] Release created: [v1.0](http://localhost:3000/test/repo/src/v1.0) by [user1](https://try.gitea.io/user1)", pl.(*MatrixPayloadUnsafe).Body)
assert.Equal(t, `[<a href="http://localhost:3000/test/repo">test/repo</a>] Release created: <a href="http://localhost:3000/test/repo/src/v1.0">v1.0</a> by <a href="https://try.gitea.io/user1">user1</a>`, pl.(*MatrixPayloadUnsafe).FormattedBody)
assert.Equal(t, "[[test/repo](http://localhost:3000/test/repo)] Release created: [v1.0](http://localhost:3000/test/repo/releases/tag/v1.0) by [user1](https://try.gitea.io/user1)", pl.(*MatrixPayloadUnsafe).Body)
assert.Equal(t, `[<a href="http://localhost:3000/test/repo">test/repo</a>] Release created: <a href="http://localhost:3000/test/repo/releases/tag/v1.0">v1.0</a> by <a href="https://try.gitea.io/user1">user1</a>`, pl.(*MatrixPayloadUnsafe).FormattedBody)
})
}

Expand Down
2 changes: 1 addition & 1 deletion services/webhook/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestSlackPayload(t *testing.T) {
require.NotNil(t, pl)
require.IsType(t, &SlackPayload{}, pl)

assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Release created: <http://localhost:3000/test/repo/src/v1.0|v1.0> by <https://try.gitea.io/user1|user1>", pl.(*SlackPayload).Text)
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Release created: <http://localhost:3000/test/repo/releases/tag/v1.0|v1.0> by <https://try.gitea.io/user1|user1>", pl.(*SlackPayload).Text)
})
}

Expand Down
2 changes: 1 addition & 1 deletion services/webhook/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestTelegramPayload(t *testing.T) {
require.NotNil(t, pl)
require.IsType(t, &TelegramPayload{}, pl)

assert.Equal(t, `[<a href="http://localhost:3000/test/repo">test/repo</a>] Release created: <a href="http://localhost:3000/test/repo/src/v1.0">v1.0</a> by <a href="https://try.gitea.io/user1">user1</a>`, pl.(*TelegramPayload).Message)
assert.Equal(t, `[<a href="http://localhost:3000/test/repo">test/repo</a>] Release created: <a href="http://localhost:3000/test/repo/releases/tag/v1.0">v1.0</a> by <a href="https://try.gitea.io/user1">user1</a>`, pl.(*TelegramPayload).Message)
})
}

Expand Down
35 changes: 26 additions & 9 deletions templates/user/settings/security/accountlinks.tmpl
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
<h4 class="ui top attached header">
{{.i18n.Tr "settings.manage_account_links"}}
{{if .OrderedOAuth2Names}}
<div class="ui right">
<div class="ui dropdown">
<div class="ui primary tiny button">{{.i18n.Tr "settings.link_account"}}</div>
<div class="menu">
{{range $key := .OrderedOAuth2Names}}
{{$provider := index $.OAuth2Providers $key}}
<a class="item" href="{{AppSubUrl}}/user/oauth2/{{$key}}">
<img width="20" height="20" src="{{AppSubUrl}}{{$provider.Image}}" alt="{{$provider.DisplayName}}">
{{$provider.DisplayName}}
</a>
{{end}}
</div>
</div>
</div>
{{end}}
</h4>

<div class="ui attached segment">
<div class="ui key list">
<div class="item">
{{.i18n.Tr "settings.manage_account_links_desc"}}
</div>
{{if .AccountLinks}}
{{range $loginSource, $provider := .AccountLinks}}
<div class="item">
<div class="right floated content">
<button class="ui red tiny button delete-button" data-modal-id="delete-account-link" data-url="{{AppSubUrl}}/user/settings/security/account_link" data-id="{{$loginSource.ID}}">
{{$.i18n.Tr "settings.delete_key"}}
</button>
</div>
{{range $loginSource, $provider := .AccountLinks}}
<div class="item">
<div class="right floated content">
<button class="ui red tiny button delete-button" data-modal-id="delete-account-link" data-url="{{AppSubUrl}}/user/settings/security/account_link" data-id="{{$loginSource.ID}}">
{{$.i18n.Tr "settings.delete_key"}}
</button>
</div>
<div class="content">
<strong>{{$provider}}</strong>
{{if $loginSource.IsActive}}<span class="text red">{{$.i18n.Tr "settings.active"}}</span>{{end}}
</div>
</div>
{{end}}
</div>
{{end}}
{{end}}
</div>
</div>
Expand Down

0 comments on commit 99bbcfa

Please sign in to comment.