Skip to content

Commit 51b0c34

Browse files
committed
Merge branch 'master' into rss-repo
2 parents 44ede67 + a0c043f commit 51b0c34

File tree

9 files changed

+67
-45
lines changed

9 files changed

+67
-45
lines changed

docs/content/doc/developers/guidelines-backend.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ To maintain understandable code and avoid circular dependencies it is important
4242
- `modules/setting`: Store all system configurations read from ini files and has been referenced by everywhere. But they should be used as function parameters when possible.
4343
- `modules/git`: Package to interactive with `Git` command line or Gogit package.
4444
- `public`: Compiled frontend files (javascript, images, css, etc.)
45-
- `routers`: Handling of server requests. As it uses other Gitea packages to serve the request, other packages (models, modules or services) shall not depend on routers.
45+
- `routers`: Handling of server requests. As it uses other Gitea packages to serve the request, other packages (models, modules or services) must not depend on routers.
4646
- `routers/api` Contains routers for `/api/v1` aims to handle RESTful API requests.
4747
- `routers/install` Could only respond when system is in INSTALL mode (INSTALL_LOCK=false).
4848
- `routers/private` will only be invoked by internal sub commands, especially `serv` and `hooks`.
@@ -106,10 +106,20 @@ i.e. `servcies/user`, `models/repository`.
106106
Since there are some packages which use the same package name, it is possible that you find packages like `modules/user`, `models/user`, and `services/user`. When these packages are imported in one Go file, it's difficult to know which package we are using and if it's a variable name or an import name. So, we always recommend to use import aliases. To differ from package variables which are commonly in camelCase, just use **snake_case** for import aliases.
107107
i.e. `import user_service "code.gitea.io/gitea/services/user"`
108108

109+
### Important Gotchas
110+
111+
- Never write `x.Update(exemplar)` without an explicit `WHERE` clause:
112+
- This will cause all rows in the table to be updated with the non-zero values of the exemplar - including IDs.
113+
- You should usually write `x.ID(id).Update(exemplar)`.
114+
- If during a migration you are inserting into a table using `x.Insert(exemplar)` where the ID is preset:
115+
- You will need to ``SET IDENTITY_INSERT `table` ON`` for the MSSQL variant (the migration will fail otherwise)
116+
- However, you will also need to update the id sequence for postgres - the migration will silently pass here but later insertions will fail:
117+
``SELECT setval('table_name_id_seq', COALESCE((SELECT MAX(id)+1 FROM `table_name`), 1), false)``
118+
109119
### Future Tasks
110120

111121
Currently, we are creating some refactors to do the following things:
112122

113123
- Correct that codes which doesn't follow the rules.
114124
- There are too many files in `models`, so we are moving some of them into a sub package `models/xxx`.
115-
- Some `modules` sub packages should be moved to `services` because they depends on `models`.
125+
- Some `modules` sub packages should be moved to `services` because they depend on `models`.

models/migrations/v210.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,11 @@ func remigrateU2FCredentials(x *xorm.Engine) error {
174174
regs = regs[:0]
175175
}
176176

177+
if x.Dialect().URI().DBType == schemas.POSTGRES {
178+
if _, err := x.Exec("SELECT setval('webauthn_credential_id_seq', COALESCE((SELECT MAX(id)+1 FROM `webauthn_credential`), 1), false)"); err != nil {
179+
return err
180+
}
181+
}
182+
177183
return nil
178184
}

models/repo.go

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -218,50 +218,44 @@ func getReviewers(ctx context.Context, repo *repo_model.Repository, doerID, post
218218
return nil, err
219219
}
220220

221-
var users []*user_model.User
222-
e := db.GetEngine(ctx)
221+
cond := builder.And(builder.Neq{"`user`.id": posterID})
223222

224223
if repo.IsPrivate || repo.Owner.Visibility == api.VisibleTypePrivate {
225224
// This a private repository:
226225
// Anyone who can read the repository is a requestable reviewer
227-
if err := e.
228-
SQL("SELECT * FROM `user` WHERE id in ("+
229-
"SELECT user_id FROM `access` WHERE repo_id = ? AND mode >= ? AND user_id != ?"+ // private org repos
230-
") ORDER BY name",
231-
repo.ID, perm.AccessModeRead,
232-
posterID).
233-
Find(&users); err != nil {
234-
return nil, err
235-
}
226+
227+
cond = cond.And(builder.In("`user`.id",
228+
builder.Select("user_id").From("access").Where(
229+
builder.Eq{"repo_id": repo.ID}.
230+
And(builder.Gte{"mode": perm.AccessModeRead}),
231+
),
232+
))
236233

237234
if repo.Owner.Type == user_model.UserTypeIndividual && repo.Owner.ID != posterID {
238235
// as private *user* repos don't generate an entry in the `access` table,
239236
// the owner of a private repo needs to be explicitly added.
240-
users = append(users, repo.Owner)
237+
cond = cond.Or(builder.Eq{"`user`.id": repo.Owner.ID})
241238
}
242239

243-
return users, nil
244-
}
245-
246-
// This is a "public" repository:
247-
// Any user that has read access, is a watcher or organization member can be requested to review
248-
if err := e.
249-
SQL("SELECT * FROM `user` WHERE id IN ( "+
250-
"SELECT user_id FROM `access` WHERE repo_id = ? AND mode >= ? "+
251-
"UNION "+
252-
"SELECT user_id FROM `watch` WHERE repo_id = ? AND mode IN (?, ?) "+
253-
"UNION "+
254-
"SELECT uid AS user_id FROM `org_user` WHERE org_id = ? "+
255-
") AND id != ? ORDER BY name",
256-
repo.ID, perm.AccessModeRead,
257-
repo.ID, repo_model.WatchModeNormal, repo_model.WatchModeAuto,
258-
repo.OwnerID,
259-
posterID).
260-
Find(&users); err != nil {
261-
return nil, err
262-
}
263-
264-
return users, nil
240+
} else {
241+
// This is a "public" repository:
242+
// Any user that has read access, is a watcher or organization member can be requested to review
243+
cond = cond.And(builder.And(builder.In("`user`.id",
244+
builder.Select("user_id").From("access").
245+
Where(builder.Eq{"repo_id": repo.ID}.
246+
And(builder.Gte{"mode": perm.AccessModeRead})),
247+
).Or(builder.In("`user`.id",
248+
builder.Select("user_id").From("watch").
249+
Where(builder.Eq{"repo_id": repo.ID}.
250+
And(builder.In("mode", repo_model.WatchModeNormal, repo_model.WatchModeAuto))),
251+
).Or(builder.In("`user`.id",
252+
builder.Select("uid").From("org_user").
253+
Where(builder.Eq{"org_id": repo.OwnerID}),
254+
)))))
255+
}
256+
257+
users := make([]*user_model.User, 0, 8)
258+
return users, db.GetEngine(ctx).Where(cond).OrderBy("name").Find(&users)
265259
}
266260

267261
// GetReviewers get all users can be requested to review:

modules/context/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func (ctx *Context) ServerError(logMsg string, logErr error) {
269269
func (ctx *Context) serverErrorInternal(logMsg string, logErr error) {
270270
if logErr != nil {
271271
log.ErrorWithSkip(2, "%s: %v", logMsg, logErr)
272-
if errors.Is(logErr, &net.OpError{}) {
272+
if _, ok := logErr.(*net.OpError); ok || errors.Is(logErr, &net.OpError{}) {
273273
// This is an error within the underlying connection
274274
// and further rendering will not work so just return
275275
return

options/locale/locale_es-ES.ini

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ search=Buscar
268268
code=Código
269269
search.fuzzy=Parcial
270270
search.match=Coincidir
271+
code_search_unavailable=Actualmente la búsqueda de código no está disponible. Póngase en contacto con el administrador de su sitio.
271272
repo_no_results=No se ha encontrado ningún repositorio coincidente.
272273
user_no_results=No se ha encontrado ningún usuario coincidente.
273274
org_no_results=No se ha encontrado ninguna organización coincidente.
@@ -549,6 +550,14 @@ continue=Continuar
549550
cancel=Cancelar
550551
language=Idioma
551552
ui=Tema
553+
hidden_comment_types=Tipos de comentarios ocultos
554+
comment_type_group_reference=Referencia
555+
comment_type_group_label=Etiqueta
556+
comment_type_group_milestone=Hito
557+
comment_type_group_assignee=Asignado
558+
comment_type_group_title=Título
559+
comment_type_group_branch=Rama
560+
comment_type_group_time_tracking=Seguimiento de Tiempo
552561
privacy=Privacidad
553562
keep_activity_private=Ocultar la actividad de la página del perfil
554563
keep_activity_private_popup=Hace la actividad visible sólo para ti y los administradores
@@ -2779,6 +2788,9 @@ monitor.queue.pool.flush.title=Vaciar cola
27792788
monitor.queue.pool.flush.desc=Al vaciar la cola se añadirá un worker que terminará una vez que la cola esté vacía, o se agote.
27802789
monitor.queue.pool.flush.submit=Añadir trabajador de vaciado
27812790
monitor.queue.pool.flush.added=Trabajador de vaciado añadido por %[1]s
2791+
monitor.queue.pool.pause.title=Pausar cola
2792+
monitor.queue.pool.pause.submit=Pausar cola
2793+
monitor.queue.pool.resume.submit=Reanudar cola
27822794

27832795
monitor.queue.settings.title=Ajustes del grupo
27842796
monitor.queue.settings.desc=Los grupos de trabajadores se crean dinámicamente como un impulso en respuesta al bloqueo de la cola de sus trabajadores. Estos cambios no afectarán a los grupos de trabajadores actuales.

options/locale/locale_pt-PT.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,9 @@ issues.lock.reason=Motivo do bloqueio
13731373
issues.lock.title=Bloquear diálogo sobre esta questão.
13741374
issues.unlock.title=Desbloquear diálogo sobre esta questão.
13751375
issues.comment_on_locked=Não pode comentar numa questão bloqueada.
1376+
issues.delete=Eliminar
1377+
issues.delete.title=Pretende eliminar esta questão?
1378+
issues.delete.text=Tem a certeza que quer eliminar esta questão? Isso irá remover todo o conteúdo permanentemente. Como alternativa considere fechá-la, se pretender mantê-la em arquivo.
13761379
issues.tracker=Gestor de tempo
13771380
issues.start_tracking_short=Iniciar cronómetro
13781381
issues.start_tracking=Iniciar contagem de tempo

routers/web/admin/auths.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func NewAuthSource(ctx *context.Context) {
9393
ctx.Data["PageIsAdmin"] = true
9494
ctx.Data["PageIsAdminAuthentications"] = true
9595

96-
ctx.Data["type"] = auth.LDAP
96+
ctx.Data["type"] = auth.LDAP.Int()
9797
ctx.Data["CurrentTypeName"] = auth.Names[auth.LDAP]
9898
ctx.Data["CurrentSecurityProtocol"] = ldap.SecurityProtocolNames[ldap.SecurityProtocolUnencrypted]
9999
ctx.Data["smtp_auth"] = "PLAIN"
@@ -112,7 +112,7 @@ func NewAuthSource(ctx *context.Context) {
112112
ctx.Data["SSPIDefaultLanguage"] = ""
113113

114114
// only the first as default
115-
ctx.Data["oauth2_provider"] = oauth2providers[0]
115+
ctx.Data["oauth2_provider"] = oauth2providers[0].Name
116116

117117
ctx.HTML(http.StatusOK, tplAuthNew)
118118
}
@@ -253,9 +253,6 @@ func NewAuthSourcePost(ctx *context.Context) {
253253
ctx.Data["SSPISeparatorReplacement"] = "_"
254254
ctx.Data["SSPIDefaultLanguage"] = ""
255255

256-
// FIXME: most error path to render tplAuthNew will fail and result in 500
257-
// * template: admin/auth/new:17:68: executing "admin/auth/new" at <.type.Int>: can't evaluate field Int in type interface {}
258-
// * template: admin/auth/source/oauth:5:93: executing "admin/auth/source/oauth" at <.oauth2_provider.Name>: can't evaluate field Name in type interface {}
259256
hasTLS := false
260257
var config convert.Conversion
261258
switch auth.Type(form.Type) {

templates/admin/auth/new.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<div class="inline required field {{if .Err_Type}}error{{end}}">
1515
<label>{{.i18n.Tr "admin.auths.auth_type"}}</label>
1616
<div class="ui selection type dropdown">
17-
<input type="hidden" id="auth_type" name="type" value="{{.type.Int}}">
17+
<input type="hidden" id="auth_type" name="type" value="{{.type}}">
1818
<div class="text">{{.CurrentTypeName}}</div>
1919
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
2020
<div class="menu">

templates/admin/auth/source/oauth.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<div class="inline required field">
33
<label>{{.i18n.Tr "admin.auths.oauth2_provider"}}</label>
44
<div class="ui selection type dropdown">
5-
<input type="hidden" id="oauth2_provider" name="oauth2_provider" value="{{.oauth2_provider.Name}}">
6-
<div class="text">{{.oauth2_provider.Name}}</div>
5+
<input type="hidden" id="oauth2_provider" name="oauth2_provider" value="{{.oauth2_provider}}">
6+
<div class="text">{{.oauth2_provider}}</div>
77
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
88
<div class="menu">
99
{{range .OAuth2Providers}}

0 commit comments

Comments
 (0)