Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* 'main' of https://github.com/go-gitea/gitea:
  Fix EasyMDE image paste bug during refactoring (go-gitea#18207)
  Sort locales according to their names (go-gitea#18211)
  Restore setting of ctx.Repo.Mirror (go-gitea#18205)
  [skip ci] Updated translations via Crowdin
  Show OAuth callback error message (go-gitea#18185)
  • Loading branch information
zjj committed Jan 8, 2022
2 parents 65adde5 + 70d7475 commit eeef0f3
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 10 deletions.
8 changes: 4 additions & 4 deletions modules/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,14 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {

if repo.IsMirror {
var err error
mirror, err := repo_model.GetMirrorByRepoID(repo.ID)
ctx.Repo.Mirror, err = repo_model.GetMirrorByRepoID(repo.ID)
if err != nil {
ctx.ServerError("GetMirrorByRepoID", err)
return
}
ctx.Data["MirrorEnablePrune"] = mirror.EnablePrune
ctx.Data["MirrorInterval"] = mirror.Interval
ctx.Data["Mirror"] = mirror
ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune
ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval
ctx.Data["Mirror"] = ctx.Repo.Mirror
}

pushMirrors, err := repo_model.GetPushMirrorsByRepoID(repo.ID)
Expand Down
10 changes: 9 additions & 1 deletion modules/translation/translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
package translation

import (
"sort"
"strings"

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/options"
"code.gitea.io/gitea/modules/setting"
Expand All @@ -31,7 +34,7 @@ var (
supportedTags []language.Tag
)

// AllLangs returns all supported langauages
// AllLangs returns all supported languages sorted by name
func AllLangs() []LangType {
return allLangs
}
Expand Down Expand Up @@ -72,6 +75,11 @@ func InitLocales() {
for i, v := range langs {
allLangs = append(allLangs, LangType{v, names[i]})
}

// Sort languages case insensitive according to their name - needed for the user settings
sort.Slice(allLangs, func(i, j int) bool {
return strings.ToLower(allLangs[i].Name) < strings.ToLower(allLangs[j].Name)
})
}

// Match matches accept languages
Expand Down
3 changes: 3 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ oauth_signup_submit = Complete Account
oauth_signin_tab = Link to Existing Account
oauth_signin_title = Sign In to Authorize Linked Account
oauth_signin_submit = Link Account
oauth.signin.error = There was an error processing the authorization request. If this error persists, please contact the site administrator.
oauth.signin.error.access_denied = The authorization request was denied.
oauth.signin.error.temporarily_unavailable = Authorization failed because the authentication server is temporarily unavailable. Please try again later.
openid_connect_submit = Connect
openid_connect_title = Connect to an existing account
openid_connect_desc = The chosen OpenID URI is unknown. Associate it with a new account here.
Expand Down
4 changes: 4 additions & 0 deletions options/locale/locale_pt-PT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ view_home=Ver %s
search_repos=Procurar um repositório…
filter=Outros filtros
filter_by_team_repositories=Filtrar por repositórios da equipa
feed_of=Fonte de "%s"

show_archived=Arquivado
show_both_archived_unarchived=Apresentando arquivados e não arquivados
Expand Down Expand Up @@ -1435,6 +1436,8 @@ pulls.compare_changes=Novo pedido de integração
pulls.compare_changes_desc=Escolha o ramo de destino e o ramo de origem.
pulls.compare_base=integrar em
pulls.compare_compare=puxar de
pulls.switch_comparison_type=Trocar o tipo de comparação
pulls.switch_head_and_base=Trocar o topo com a base
pulls.filter_branch=Filtrar ramo
pulls.no_results=Não foram encontrados quaisquer resultados.
pulls.nothing_to_compare=Estes ramos são iguais. Não há necessidade de criar um pedido de integração.
Expand Down Expand Up @@ -2080,6 +2083,7 @@ diff.too_many_files=Alguns ficheiros não foram mostrados porque foram modificad
diff.show_more=Mostrar mais
diff.load=Carregar diff
diff.generated=gerado
diff.vendored=externo
diff.comment.placeholder=Deixar um comentário
diff.comment.markdown_info=A formatação com markdown é suportada.
diff.comment.add_single_comment=Adicionar um único comentário
Expand Down
11 changes: 11 additions & 0 deletions options/locale/locale_zh-CN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ commits.signed_by_untrusted_user_unmatched=由与提交者不匹配的未授信
commits.gpg_key_id=GPG 密钥 ID
commits.ssh_key_fingerprint=SSH 密钥指纹
ext_issues=访问外部工单
ext_issues.desc=链接到外部工单跟踪系统。
projects=项目
Expand Down Expand Up @@ -1578,6 +1579,7 @@ signing.wont_sign.commitssigned=合并将不会被签名,因为所有相关的
signing.wont_sign.approved=合并将不会被签名,因为合并请求未被批准
signing.wont_sign.not_signed_in=您还没有登录。
ext_wiki=访问外部百科
ext_wiki.desc=链接到外部 wiki。
wiki=百科
Expand Down Expand Up @@ -1834,6 +1836,8 @@ settings.webhook.response=响应内容
settings.webhook.headers=头信息
settings.webhook.payload=内容
settings.webhook.body=响应体
settings.webhook.replay.description=重放此 webhook。
settings.webhook.delivery.success=一个事件已被添加到推送队列。可能需要过几秒钟才会显示在推送记录中。
settings.githooks_desc=Git Hook 是 Git 本身提供的功能。您可以在下方编辑 hook 文件以设置自定义操作。
settings.githook_edit_desc=如果钩子未启动,则会显示样例文件中的内容。如果想要删除某个钩子,则提交空白文本即可。
settings.githook_name=钩子名称
Expand Down Expand Up @@ -2258,7 +2262,13 @@ teams.leave=离开团队
teams.leave.detail=离开 %s?
teams.can_create_org_repo=创建仓库
teams.can_create_org_repo_helper=成员可以在组织中创建仓库。创建者将自动获得创建的仓库的管理员权限。
teams.none_access=无访问权限
teams.none_access_helper=成员无法查看此单元或对其执行任何其他操作。
teams.general_access=常规访问
teams.general_access_helper=成员权限将由以下权限表决定。
teams.read_access=读取
teams.read_access_helper=成员可以查看和克隆团队仓库。
teams.write_access=写入
teams.write_access_helper=成员可以查看和推送提交到团队仓库。
teams.admin_access=管理员权限
teams.admin_access_helper=成员可以拉取和推送到团队仓库同时可以添加协作者。
Expand Down Expand Up @@ -2887,6 +2897,7 @@ error.probable_bad_signature=警告!虽然数据库中有一个此ID的密钥
error.probable_bad_default_signature=警告!虽然默认密钥拥有此ID,但它没有验证此提交!此提交是有疑问的。
[units]
unit=单元
error.no_unit_allowed_repo=您没有被允许访问此仓库的任何单元。
error.unit_not_allowed=您没有权限访问此仓库单元
36 changes: 35 additions & 1 deletion routers/web/auth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ func (err AccessTokenError) Error() string {
return fmt.Sprintf("%s: %s", err.ErrorCode, err.ErrorDescription)
}

// errCallback represents a oauth2 callback error
type errCallback struct {
Code string
Description string
}

func (err errCallback) Error() string {
return err.Description
}

// TokenType specifies the kind of token
type TokenType string

Expand Down Expand Up @@ -810,7 +820,6 @@ func SignInOAuthCallback(ctx *context.Context) {
}

u, gothUser, err := oAuth2UserLoginCallback(authSource, ctx.Req, ctx.Resp)

if err != nil {
if user_model.IsErrUserProhibitLogin(err) {
uplerr := err.(*user_model.ErrUserProhibitLogin)
Expand All @@ -819,6 +828,19 @@ func SignInOAuthCallback(ctx *context.Context) {
ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
return
}
if callbackErr, ok := err.(errCallback); ok {
log.Info("Failed OAuth callback: (%v) %v", callbackErr.Code, callbackErr.Description)
switch callbackErr.Code {
case "access_denied":
ctx.Flash.Error(ctx.Tr("auth.oauth.signin.error.access_denied"))
case "temporarily_unavailable":
ctx.Flash.Error(ctx.Tr("auth.oauth.signin.error.temporarily_unavailable"))
default:
ctx.Flash.Error(ctx.Tr("auth.oauth.signin.error"))
}
ctx.Redirect(setting.AppSubURL + "/user/login")
return
}
ctx.ServerError("UserSignIn", err)
return
}
Expand Down Expand Up @@ -1065,6 +1087,18 @@ func oAuth2UserLoginCallback(authSource *auth.Source, request *http.Request, res
log.Error("OAuth2 Provider %s returned too long a token. Current max: %d. Either increase the [OAuth2] MAX_TOKEN_LENGTH or reduce the information returned from the OAuth2 provider", authSource.Name, setting.OAuth2.MaxTokenLength)
err = fmt.Errorf("OAuth2 Provider %s returned too long a token. Current max: %d. Either increase the [OAuth2] MAX_TOKEN_LENGTH or reduce the information returned from the OAuth2 provider", authSource.Name, setting.OAuth2.MaxTokenLength)
}
// goth does not provide the original error message
// https://github.com/markbates/goth/issues/348
if strings.Contains(err.Error(), "server response missing access_token") || strings.Contains(err.Error(), "could not find a matching session for this request") {
errorCode := request.FormValue("error")
errorDescription := request.FormValue("error_description")
if errorCode != "" || errorDescription != "" {
return nil, goth.User{}, errCallback{
Code: errorCode,
Description: errorDescription,
}
}
}
return nil, goth.User{}, err
}

Expand Down
6 changes: 4 additions & 2 deletions web_src/js/features/repo-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,10 @@ export function initRepoPullRequestReview() {

const $reviewBox = $('.review-box');
if ($reviewBox.length === 1) {
createCommentEasyMDE($reviewBox.find('textarea'));
initCompImagePaste($reviewBox);
(async () => {
await createCommentEasyMDE($reviewBox.find('textarea'));
initCompImagePaste($reviewBox);
})();
}

// The following part is only for diff views
Expand Down
7 changes: 5 additions & 2 deletions web_src/js/features/repo-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ export function initRepoCommentForm() {
});
}

createCommentEasyMDE($('.comment.form textarea:not(.review-textarea)'));
(async () => {
await createCommentEasyMDE($('.comment.form textarea:not(.review-textarea)'));
initCompImagePaste($('.comment.form'));
})();

initBranchSelector();
initCompMarkupContentPreviewTab($('.comment.form'));
initCompImagePaste($('.comment.form'));

// List submits
function initListSubmits(selector, outerSelector) {
Expand Down

0 comments on commit eeef0f3

Please sign in to comment.