Allow editing push mirrors after creation (#26151)

Allow users to edit the sync interval for existing push mirrors.
Currently, there is no way to modify the interval once the mirror is
created.
<details>
  <summary>Screenshots</summary>
  
## Before
<img width="936" alt="Screenshot 2023-07-26 at 9 31 21 AM"
src="35b8a40c-4320-474c-a866-1dea0f1fa0de">


## After
<img width="945" alt="Screenshot 2023-07-26 at 9 44 40 AM"
src="ee12e12f-0f68-4feb-90eb-33366f5997d3">

### On hover

<img width="247" alt="image"
src="2f32de45-bd50-4150-9623-3be2ef3ea7f8">
<img width="237" alt="image"
src="49f4ab4d-ccff-4489-80ce-a9788a73c3bb">
<img width="245" alt="image"
src="165fc888-9d48-438a-b730-d4beb12122af">

### Edit modal
<img width="905" alt="image"
src="2a7ca24b-4f36-4e0e-9799-39f2ecc46413">

### Only valid times are allowed
<img width="728" alt="Screenshot 2023-07-26 at 9 50 01 AM"
src="ced6d330-c235-4e29-8f17-28daddcf1444">
<img width="853" alt="image"
src="8636f62a-70d1-4684-a3e8-b205adc03580">

</details>
Fixes #21295

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
puni9869 2023-08-01 21:30:59 +05:30 committed by GitHub
parent ab0e588217
commit ab388deb0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 7 deletions

View file

@ -299,6 +299,43 @@ func SettingsPost(ctx *context.Context) {
ctx.Flash.Info(ctx.Tr("repo.settings.mirror_sync_in_progress"))
ctx.Redirect(repo.Link() + "/settings")
case "push-mirror-update":
if !setting.Mirror.Enabled {
ctx.NotFound("", nil)
return
}
// This section doesn't require repo_name/RepoName to be set in the form, don't show it
// as an error on the UI for this action
ctx.Data["Err_RepoName"] = nil
interval, err := time.ParseDuration(form.PushMirrorInterval)
if err != nil || (interval != 0 && interval < setting.Mirror.MinInterval) {
ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &forms.RepoSettingForm{})
return
}
id, err := strconv.ParseInt(form.PushMirrorID, 10, 64)
if err != nil {
ctx.ServerError("UpdatePushMirrorIntervalPushMirrorID", err)
return
}
m := &repo_model.PushMirror{
ID: id,
Interval: interval,
}
if err := repo_model.UpdatePushMirrorInterval(ctx, m); err != nil {
ctx.ServerError("UpdatePushMirrorInterval", err)
return
}
// Background why we are adding it to Queue
// If we observed its implementation in the context of `push-mirror-sync` where it
// is evident that pushing to the queue is necessary for updates.
// So, there are updates within the given interval, it is necessary to update the queue accordingly.
mirror_module.AddPushMirrorToQueue(m.ID)
ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success"))
ctx.Redirect(repo.Link() + "/settings")
case "push-mirror-remove":
if !setting.Mirror.Enabled {
ctx.NotFound("", nil)