mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: permissions bug related to deleting language mappings
This commit is contained in:
parent
acda62488d
commit
16b683fcbd
@ -115,13 +115,17 @@ func (h *SettingsHandler) DeleteLanguageMapping(w http.ResponseWriter, r *http.R
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
mapping := &models.LanguageMapping{
|
if mapping, err := h.languageMappingSrvc.GetById(uint(id)); err != nil || mapping == nil {
|
||||||
ID: uint(id),
|
w.WriteHeader(http.StatusNotFound)
|
||||||
UserID: user.ID,
|
templates[conf.SettingsTemplate].Execute(w, h.buildViewModel(r).WithError("mapping not found"))
|
||||||
|
return
|
||||||
|
} else if mapping.UserID != user.ID {
|
||||||
|
w.WriteHeader(http.StatusForbidden)
|
||||||
|
templates[conf.SettingsTemplate].Execute(w, h.buildViewModel(r).WithError("not allowed to delete mapping"))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.languageMappingSrvc.Delete(mapping)
|
if err := h.languageMappingSrvc.Delete(&models.LanguageMapping{ID: uint(id)}); err != nil {
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
templates[conf.SettingsTemplate].Execute(w, h.buildViewModel(r).WithError("could not delete mapping"))
|
templates[conf.SettingsTemplate].Execute(w, h.buildViewModel(r).WithError("could not delete mapping"))
|
||||||
return
|
return
|
||||||
|
@ -89,7 +89,7 @@
|
|||||||
<form class="float-right" action="settings/language_mappings/delete" method="post">
|
<form class="float-right" action="settings/language_mappings/delete" method="post">
|
||||||
<input type="hidden" id="mapping_id" name="mapping_id" required value="{{ $mapping.ID }}">
|
<input type="hidden" id="mapping_id" name="mapping_id" required value="{{ $mapping.ID }}">
|
||||||
<button type="submit" class="py-1 px-3 rounded bg-red-500 hover:bg-red-600 text-white text-sm">
|
<button type="submit" class="py-1 px-3 rounded bg-red-500 hover:bg-red-600 text-white text-sm">
|
||||||
Remove
|
X
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user