New form to describe change before publishing zone modifications
This commit is contained in:
parent
463bbef239
commit
4bd40bfd7b
22
api/zones.go
22
api/zones.go
|
@ -423,6 +423,11 @@ func diffZones(c *gin.Context) {
|
|||
c.JSON(http.StatusOK, rrCorected)
|
||||
}
|
||||
|
||||
type applyZoneForm struct {
|
||||
WantedCorrections []string `json:"wantedCorrections"`
|
||||
CommitMsg string `json:"commitMessage"`
|
||||
}
|
||||
|
||||
// applyZone performs the requested changes with the provider.
|
||||
//
|
||||
// @Summary Performs requested changes to the real zone.
|
||||
|
@ -459,8 +464,8 @@ func applyZone(c *gin.Context) {
|
|||
Records: records,
|
||||
}
|
||||
|
||||
var wantedCorrections []string
|
||||
err = c.ShouldBindJSON(&wantedCorrections)
|
||||
var form applyZoneForm
|
||||
err = c.ShouldBindJSON(&form)
|
||||
if err != nil {
|
||||
log.Printf("%s sends invalid string array JSON: %s", c.ClientIP(), err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
|
||||
|
@ -469,7 +474,7 @@ func applyZone(c *gin.Context) {
|
|||
|
||||
corrections, err := provider.GetDomainCorrections(domain, dc)
|
||||
for _, cr := range corrections {
|
||||
for ic, wc := range wantedCorrections {
|
||||
for ic, wc := range form.WantedCorrections {
|
||||
if wc == cr.Msg {
|
||||
log.Printf("%s: apply correction: %s", domain.DomainName, cr.Msg)
|
||||
err := cr.F()
|
||||
|
@ -479,21 +484,20 @@ func applyZone(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
wantedCorrections = append(wantedCorrections[:ic], wantedCorrections[ic+1:]...)
|
||||
form.WantedCorrections = append(form.WantedCorrections[:ic], form.WantedCorrections[ic+1:]...)
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(wantedCorrections) > 0 {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Unable to perform the following changes: %s", wantedCorrections)})
|
||||
if len(form.WantedCorrections) > 0 {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Unable to perform the following changes: %s", form.WantedCorrections)})
|
||||
return
|
||||
}
|
||||
|
||||
// Create a new zone in history for futher updates
|
||||
newZone := zone.DerivateNew()
|
||||
//newZone.IdAuthor = //TODO get current user id
|
||||
err = storage.MainStore.CreateZone(newZone)
|
||||
if err != nil {
|
||||
log.Printf("%s was unable to CreateZone: %s", c.ClientIP(), err.Error())
|
||||
|
@ -513,7 +517,9 @@ func applyZone(c *gin.Context) {
|
|||
|
||||
// Commit changes in previous zone
|
||||
now := time.Now()
|
||||
// zone.ZoneMeta.IdAuthor = // TODO get current user id
|
||||
zone.ZoneMeta.IdAuthor = user.Id
|
||||
zone.CommitMsg = &form.CommitMsg
|
||||
zone.ZoneMeta.CommitDate = &now
|
||||
zone.ZoneMeta.Published = &now
|
||||
|
||||
zone.LastModified = time.Now()
|
||||
|
|
|
@ -29,13 +29,13 @@ export async function retrieveZone(domain: Domain | DomainInList): Promise<ZoneM
|
|||
return await handleApiResponse<ZoneMeta>(res);
|
||||
}
|
||||
|
||||
export async function applyZone(domain: Domain | DomainInList, id: string, selectedDiffs: Array<string>): Promise<ZoneMeta> {
|
||||
export async function applyZone(domain: Domain | DomainInList, id: string, wantedCorrections: Array<string>, commitMessage: string): Promise<ZoneMeta> {
|
||||
const dnid = encodeURIComponent(domain.id);
|
||||
id = encodeURIComponent(id);
|
||||
const res = await fetch(`/api/domains/${dnid}/zone/${id}/apply_changes`, {
|
||||
method: 'POST',
|
||||
headers: {'Accept': 'application/json'},
|
||||
body: JSON.stringify(selectedDiffs),
|
||||
body: JSON.stringify({wantedCorrections, commitMessage}),
|
||||
});
|
||||
return await handleApiResponse<ZoneMeta>(res);
|
||||
}
|
||||
|
|
|
@ -94,6 +94,7 @@
|
|||
"others": "{{count:eq; 0:no other change; 1:{{count}} other change; default:{{count}} others changes}}"
|
||||
},
|
||||
"attached-new": "New domain attached to happyDomain!",
|
||||
"commit-msg": "What's changed:",
|
||||
"create-new-key": "Create new {{id}} key",
|
||||
"discard": "Discard",
|
||||
"drop-alias": "Drop alias",
|
||||
|
|
|
@ -94,6 +94,7 @@
|
|||
"others": "{{count:eq; 0:pas d'autres changements; 1:{{count}} autre changement; default:{{count}} autres changements}}"
|
||||
},
|
||||
"attached-new": "Nouveau domaine lié à happyDomain!",
|
||||
"commit-msg": "Description du changement :",
|
||||
"create-new-key": "Créer une nouvelle clé {{id}}",
|
||||
"discard": "Supprimer",
|
||||
"drop-alias": "Supprimer l'alias",
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
Container,
|
||||
Icon,
|
||||
Input,
|
||||
Label,
|
||||
Modal,
|
||||
ModalBody,
|
||||
ModalFooter,
|
||||
|
@ -230,6 +231,7 @@
|
|||
}
|
||||
|
||||
let selectedDiff: Array<string> | null = null;
|
||||
let diffCommitMsg = "";
|
||||
let selectedDiffCreated = 0;
|
||||
let selectedDiffDeleted = 0;
|
||||
let selectedDiffModified = 0;
|
||||
|
@ -243,7 +245,7 @@
|
|||
|
||||
propagationInProgress = true;
|
||||
try {
|
||||
retrieveZoneDone(await APIApplyZone(domain, selectedHistory, selectedDiff));
|
||||
retrieveZoneDone(await APIApplyZone(domain, selectedHistory, selectedDiff, diffCommitMsg));
|
||||
} finally {
|
||||
applyZoneModalIsOpen = false;
|
||||
}
|
||||
|
@ -599,6 +601,17 @@
|
|||
{/if}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<div class="w-100 row">
|
||||
<div class="col-auto d-flex flex-column justify-content-center">
|
||||
<label for="commitmsg">{$t('domains.commit-msg')}</label>
|
||||
</div>
|
||||
<div class="col">
|
||||
<Input
|
||||
id="commitmsg"
|
||||
bind:value={diffCommitMsg}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{#if zoneDiff}
|
||||
{#if zoneDiffCreated}
|
||||
<span class="text-success">
|
||||
|
|
Loading…
Reference in New Issue