Skip to content

Commit 538536d

Browse files
committed
fix
1 parent 18a1050 commit 538536d

File tree

5 files changed

+22
-30
lines changed

5 files changed

+22
-30
lines changed

routers/web/user/package.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"errors"
99
"net/http"
1010
"net/url"
11-
"strings"
1211

1312
"code.gitea.io/gitea/models/db"
1413
org_model "code.gitea.io/gitea/models/organization"
@@ -432,7 +431,6 @@ func PackageSettings(ctx *context.Context) {
432431
ctx.Data["Title"] = pd.Package.Name
433432
ctx.Data["IsPackagesPage"] = true
434433
ctx.Data["PackageDescriptor"] = pd
435-
ctx.Data["OwnerID"] = pd.Owner.ID
436434
ctx.Data["CanWritePackages"] = ctx.Package.AccessMode >= perm.AccessModeWrite || ctx.IsUserSiteAdmin()
437435

438436
if pd.Package.RepoID > 0 {
@@ -441,7 +439,7 @@ func PackageSettings(ctx *context.Context) {
441439
ctx.ServerError("GetRepositoryByID", err)
442440
return
443441
}
444-
ctx.Data["LinkedRepoFullName"] = repo.FullName()
442+
ctx.Data["LinkedRepoName"] = repo.Name
445443
}
446444

447445
ctx.HTML(http.StatusOK, tplPackagesSettings)
@@ -454,37 +452,29 @@ func PackageSettingsPost(ctx *context.Context) {
454452
form := web.GetForm(ctx).(*forms.PackageSettingForm)
455453
switch form.Action {
456454
case "link":
457-
if form.RepoFullName == "" { // remove the link
455+
if form.RepoName == "" { // remove the link
458456
if err := packages_model.SetRepositoryLink(ctx, pd.Package.ID, 0); err != nil {
459-
ctx.Flash.Error(ctx.Tr("packages.settings.unlink.error"))
460-
} else {
461-
ctx.Flash.Success(ctx.Tr("packages.settings.unlink.success"))
457+
ctx.JSONError(ctx.Tr("packages.settings.unlink.error"))
458+
return
462459
}
460+
461+
ctx.Flash.Success(ctx.Tr("packages.settings.unlink.success"))
463462
ctx.JSONRedirect("")
464463
return
465464
}
466465

467-
owner, name, _ := strings.Cut(form.RepoFullName, "/")
468-
repo, err := repo_model.GetRepositoryByOwnerAndName(ctx, owner, name)
466+
repo, err := repo_model.GetRepositoryByName(ctx, pd.Owner.ID, form.RepoName)
469467
if err != nil {
470468
if repo_model.IsErrRepoNotExist(err) {
471-
ctx.Flash.Error(ctx.Tr("packages.settings.link.repo_not_found", form.RepoFullName))
472-
ctx.JSONRedirect("")
469+
ctx.JSONError(ctx.Tr("packages.settings.link.repo_not_found", form.RepoName))
473470
} else {
474471
ctx.ServerError("GetRepositoryByOwnerAndName", err)
475472
}
476473
return
477474
}
478475

479-
if repo.OwnerID != pd.Owner.ID {
480-
ctx.Flash.Error(ctx.Tr("packages.settings.link.repo_not_found", form.RepoFullName))
481-
ctx.JSONRedirect("")
482-
return
483-
}
484-
485476
if err := packages_model.SetRepositoryLink(ctx, pd.Package.ID, repo.ID); err != nil {
486-
ctx.Flash.Error(ctx.Tr("packages.settings.link.error"))
487-
ctx.JSONRedirect("")
477+
ctx.JSONError(ctx.Tr("packages.settings.link.error"))
488478
return
489479
}
490480

services/forms/user_form.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ func (f *WebauthnDeleteForm) Validate(req *http.Request, errs binding.Errors) bi
416416

417417
// PackageSettingForm form for package settings
418418
type PackageSettingForm struct {
419-
Action string
420-
RepoFullName string `form:"repo_full_name"`
419+
Action string
420+
RepoName string `form:"repo_name"`
421421
}
422422

423423
// Validate validates the fields

templates/package/settings.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{template "base/head" .}}
2-
<div role="main" aria-label="{{.Title}}" class="page-content repository settings options{{if .ContextUser.IsOrganization}} organization{{end}}">
2+
<div role="main" aria-label="{{.Title}}" class="page-content package settings options{{if .ContextUser.IsOrganization}} organization{{end}}">
33
{{if .ContextUser.IsOrganization}}
44
{{template "org/header" .}}
55
{{else}}
@@ -19,9 +19,9 @@
1919
<form class="ui form form-fetch-action ignore-dirty tw-flex-1 tw-flex" action="{{.Link}}" method="post">
2020
{{.CsrfTokenHtml}}
2121
<input type="hidden" name="action" value="link">
22-
<div id="search-repo-box" class="ui search" data-full-name="true" data-uid="{{.OwnerID}}">
22+
<div id="search-repo-box" class="ui search" data-uid="{{.PackageDescriptor.Owner.ID}}">
2323
<div class="ui input">
24-
<input class="prompt" name="repo_full_name" value="{{.LinkedRepoFullName}}" placeholder="{{ctx.Locale.Tr "search.repo_kind"}}" autocomplete="off">
24+
<input class="prompt" name="repo_name" value="{{.LinkedRepoName}}" placeholder="{{ctx.Locale.Tr "search.repo_kind"}}" autocomplete="off">
2525
</div>
2626
</div>
2727
<button class="ui primary button tw-ml-2">{{ctx.Locale.Tr "packages.settings.link.button"}}</button>

web_src/js/features/comp/SearchRepoBox.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ import {fomanticQuery} from '../../modules/fomantic/base.ts';
33
const {appSubUrl} = window.config;
44

55
export function initCompSearchRepoBox() {
6-
// on the page "page-content organization teams"
6+
// on the page "page-content organization teams" and "page-content package settings"
7+
const searchRepobox = document.querySelector('#search-repo-box');
8+
if (!searchRepobox) return;
9+
10+
const uid = searchRepobox.getAttribute('data-uid');
11+
712
const $searchRepoBox = fomanticQuery('#search-repo-box');
8-
const showFullName = $searchRepoBox.data('full-name');
913
$searchRepoBox.search({
1014
minCharacters: 2,
1115
apiSettings: {
12-
url: `${appSubUrl}/repo/search?q={query}&uid=${$searchRepoBox.data('uid')}`,
16+
url: `${appSubUrl}/repo/search?q={query}&uid=${uid}`,
1317
onResponse(response: any) {
1418
const items = [];
1519
for (const item of response.data) {
1620
let title = item.repository.full_name.split('/')[1];
17-
if (showFullName) {
18-
title = item.repository.full_name;
19-
}
2021
items.push({
2122
title,
2223
description: item.repository.full_name,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {initCompSearchRepoBox} from './comp/SearchRepoBox.ts';
22

33
export function initPackageSettings() {
4+
if (!document.querySelector('.page-content.package.settings')) return;
45
initCompSearchRepoBox();
56
}

0 commit comments

Comments
 (0)