1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 03:36:16 +00:00

Break a lot of stuff

Starring:
* Fix some bugs for /rename/
* Introduce /delete/, /remove-media/
* Introduce some bugs for the methods mentioned above
This commit is contained in:
Timur Ismagilov 2022-02-20 00:12:28 +03:00
parent eb9acb718e
commit 41651f9e9b
6 changed files with 198 additions and 208 deletions

View File

@ -26,6 +26,9 @@ func Rename(oldHypha hyphae.ExistingHypha, newName string, recursive bool, u *us
switch targetHypha := hyphae.ByName(newName); targetHypha.(type) { switch targetHypha := hyphae.ByName(newName); targetHypha.(type) {
case hyphae.ExistingHypha: case hyphae.ExistingHypha:
if targetHypha.CanonicalName() == oldHypha.CanonicalName() {
return nil
}
rejectRenameLog(oldHypha, u, fmt.Sprintf("name %s taken already", newName)) rejectRenameLog(oldHypha, u, fmt.Sprintf("name %s taken already", newName))
return errors.New("ui.rename_taken_tip") // FIXME: There is a bug related to this. return errors.New("ui.rename_taken_tip") // FIXME: There is a bug related to this.
} }

View File

@ -9,17 +9,11 @@ import (
"github.com/bouncepaw/mycorrhiza/user" "github.com/bouncepaw/mycorrhiza/user"
) )
// UnattachHypha unattaches hypha and makes a history record about that. // RemoveMedia unattaches hypha and makes a history record about that.
func UnattachHypha(u *user.User, h hyphae.Hypha, lc *l18n.Localizer) error { func RemoveMedia(u *user.User, h *hyphae.MediaHypha, lc *l18n.Localizer) error {
if err := CanUnattach(u, h, lc); err != nil {
return err
}
H := h.(*hyphae.MediaHypha)
hop := history. hop := history.
Operation(history.TypeUnattachHypha). Operation(history.TypeUnattachHypha).
WithFilesRemoved(H.MediaFilePath()). WithFilesRemoved(h.MediaFilePath()).
WithMsg(fmt.Sprintf("Unattach %s", h.CanonicalName())). WithMsg(fmt.Sprintf("Unattach %s", h.CanonicalName())).
WithUser(u). WithUser(u).
Apply() Apply()
@ -30,10 +24,10 @@ func UnattachHypha(u *user.User, h hyphae.Hypha, lc *l18n.Localizer) error {
return fmt.Errorf("Could not unattach this hypha due to internal server errors: <code>%v</code>", hop.Errs) return fmt.Errorf("Could not unattach this hypha due to internal server errors: <code>%v</code>", hop.Errs)
} }
if H.HasTextFile() { if h.HasTextFile() {
hyphae.Insert(hyphae.ShrinkMediaToTextual(H)) hyphae.Insert(hyphae.ShrinkMediaToTextual(h))
} else { } else {
hyphae.DeleteHypha(H) hyphae.DeleteHypha(h)
} }
return nil return nil
} }

View File

@ -35,15 +35,9 @@ var minimalRights = map[string]int{
"upload-binary": 1, "upload-binary": 1,
"upload-text": 1, "upload-text": 1,
"rename": 2, "rename": 2,
"rename-ask": 2,
"rename-confirm": 2,
"remove-media": 2, "remove-media": 2,
"unattach-ask": 2,
"unattach-confirm": 2,
"update-header-links": 3, "update-header-links": 3,
"delete": 3, "delete": 3,
"delete-ask": 3,
"delete-confirm": 3,
"reindex": 4, "reindex": 4,
"admin": 4, "admin": 4,
"admin/shutdown": 4, "admin/shutdown": 4,

View File

@ -7,7 +7,7 @@
lc := l18n.FromRequest(rq) lc := l18n.FromRequest(rq)
%} %}
{%= modalBegin( {%= modalBegin(
"delete-confirm", "delete",
hyphaName, hyphaName,
"", "",
fmt.Sprintf(lc.Get("ui.ask_delete"), beautifulLink(hyphaName))) %} fmt.Sprintf(lc.Get("ui.ask_delete"), beautifulLink(hyphaName))) %}
@ -16,25 +16,27 @@
{%= modalEnd(hyphaName, true, lc) %} {%= modalEnd(hyphaName, true, lc) %}
{% endfunc %} {% endfunc %}
{% func UnattachAskHTML(rq *http.Request, hyphaName string) %} {% func RemoveMediaAskHTML(rq *http.Request, hyphaName string) %}
{% code {% code
lc := l18n.FromRequest(rq) lc := l18n.FromRequest(rq)
%} %}
{%= modalBegin( {%= modalBegin(
"unattach", "remove-media",
hyphaName, hyphaName,
"", "",
fmt.Sprintf(lc.Get("ui.ask_unattach"), beautifulLink(hyphaName))) %} fmt.Sprintf(lc.Get("ui.ask_remove_media"), beautifulLink(hyphaName))) %}
{%= modalReallyWant(hyphaName, lc.Get("ui.ask_unattach_verb"), lc) %} {%= modalReallyWant(hyphaName, lc.Get("ui.ask_remove_media_verb"), lc) %}
{%= modalEnd(hyphaName, true, lc) %} {%= modalEnd(hyphaName, true, lc) %}
{% endfunc %} {% endfunc %}
bloody hell !!
{% func RenameAskHTML(rq *http.Request, hyphaName string) %} {% func RenameAskHTML(rq *http.Request, hyphaName string) %}
{% code {% code
lc := l18n.FromRequest(rq) lc := l18n.FromRequest(rq)
%} %}
{%= modalBegin( {%= modalBegin(
"rename-confirm", "rename",
hyphaName, hyphaName,
` method="post" enctype="multipart/form-data"`, ` method="post" enctype="multipart/form-data"`,
fmt.Sprintf(lc.Get("ui.ask_rename"), beautifulLink(hyphaName))) %} fmt.Sprintf(lc.Get("ui.ask_rename"), beautifulLink(hyphaName))) %}

View File

@ -39,7 +39,7 @@ func StreamDeleteAskHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName
`) `)
//line views/modal.qtpl:9 //line views/modal.qtpl:9
streammodalBegin(qw422016, streammodalBegin(qw422016,
"delete-confirm", "delete",
hyphaName, hyphaName,
"", "",
fmt.Sprintf(lc.Get("ui.ask_delete"), beautifulLink(hyphaName))) fmt.Sprintf(lc.Get("ui.ask_delete"), beautifulLink(hyphaName)))
@ -91,7 +91,7 @@ func DeleteAskHTML(rq *http.Request, hyphaName string) string {
} }
//line views/modal.qtpl:19 //line views/modal.qtpl:19
func StreamUnattachAskHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName string) { func StreamRemoveMediaAskHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName string) {
//line views/modal.qtpl:19 //line views/modal.qtpl:19
qw422016.N().S(` qw422016.N().S(`
`) `)
@ -103,15 +103,15 @@ func StreamUnattachAskHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaNam
`) `)
//line views/modal.qtpl:23 //line views/modal.qtpl:23
streammodalBegin(qw422016, streammodalBegin(qw422016,
"unattach", "remove-media",
hyphaName, hyphaName,
"", "",
fmt.Sprintf(lc.Get("ui.ask_unattach"), beautifulLink(hyphaName))) fmt.Sprintf(lc.Get("ui.ask_remove_media"), beautifulLink(hyphaName)))
//line views/modal.qtpl:27 //line views/modal.qtpl:27
qw422016.N().S(` qw422016.N().S(`
`) `)
//line views/modal.qtpl:28 //line views/modal.qtpl:28
streammodalReallyWant(qw422016, hyphaName, lc.Get("ui.ask_unattach_verb"), lc) streammodalReallyWant(qw422016, hyphaName, lc.Get("ui.ask_remove_media_verb"), lc)
//line views/modal.qtpl:28 //line views/modal.qtpl:28
qw422016.N().S(` qw422016.N().S(`
`) `)
@ -124,22 +124,22 @@ func StreamUnattachAskHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaNam
} }
//line views/modal.qtpl:30 //line views/modal.qtpl:30
func WriteUnattachAskHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName string) { func WriteRemoveMediaAskHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName string) {
//line views/modal.qtpl:30 //line views/modal.qtpl:30
qw422016 := qt422016.AcquireWriter(qq422016) qw422016 := qt422016.AcquireWriter(qq422016)
//line views/modal.qtpl:30 //line views/modal.qtpl:30
StreamUnattachAskHTML(qw422016, rq, hyphaName) StreamRemoveMediaAskHTML(qw422016, rq, hyphaName)
//line views/modal.qtpl:30 //line views/modal.qtpl:30
qt422016.ReleaseWriter(qw422016) qt422016.ReleaseWriter(qw422016)
//line views/modal.qtpl:30 //line views/modal.qtpl:30
} }
//line views/modal.qtpl:30 //line views/modal.qtpl:30
func UnattachAskHTML(rq *http.Request, hyphaName string) string { func RemoveMediaAskHTML(rq *http.Request, hyphaName string) string {
//line views/modal.qtpl:30 //line views/modal.qtpl:30
qb422016 := qt422016.AcquireByteBuffer() qb422016 := qt422016.AcquireByteBuffer()
//line views/modal.qtpl:30 //line views/modal.qtpl:30
WriteUnattachAskHTML(qb422016, rq, hyphaName) WriteRemoveMediaAskHTML(qb422016, rq, hyphaName)
//line views/modal.qtpl:30 //line views/modal.qtpl:30
qs422016 := string(qb422016.B) qs422016 := string(qb422016.B)
//line views/modal.qtpl:30 //line views/modal.qtpl:30
@ -149,233 +149,236 @@ func UnattachAskHTML(rq *http.Request, hyphaName string) string {
//line views/modal.qtpl:30 //line views/modal.qtpl:30
} }
//line views/modal.qtpl:32 // bloody hell !!
func StreamRenameAskHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName string) { //
//line views/modal.qtpl:32
qw422016.N().S(`
`)
//line views/modal.qtpl:34
lc := l18n.FromRequest(rq)
//line views/modal.qtpl:35 //line views/modal.qtpl:34
func StreamRenameAskHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName string) {
//line views/modal.qtpl:34
qw422016.N().S(` qw422016.N().S(`
`) `)
//line views/modal.qtpl:36 //line views/modal.qtpl:36
lc := l18n.FromRequest(rq)
//line views/modal.qtpl:37
qw422016.N().S(`
`)
//line views/modal.qtpl:38
streammodalBegin(qw422016, streammodalBegin(qw422016,
"rename-confirm", "rename",
hyphaName, hyphaName,
` method="post" enctype="multipart/form-data"`, ` method="post" enctype="multipart/form-data"`,
fmt.Sprintf(lc.Get("ui.ask_rename"), beautifulLink(hyphaName))) fmt.Sprintf(lc.Get("ui.ask_rename"), beautifulLink(hyphaName)))
//line views/modal.qtpl:40 //line views/modal.qtpl:42
qw422016.N().S(` qw422016.N().S(`
<label for="new-name">`) <label for="new-name">`)
//line views/modal.qtpl:41 //line views/modal.qtpl:43
qw422016.E().S(lc.Get("ui.rename_to")) qw422016.E().S(lc.Get("ui.rename_to"))
//line views/modal.qtpl:41 //line views/modal.qtpl:43
qw422016.N().S(`</label> qw422016.N().S(`</label>
<input type="text" value="`) <input type="text" value="`)
//line views/modal.qtpl:42 //line views/modal.qtpl:44
qw422016.E().S(hyphaName) qw422016.E().S(hyphaName)
//line views/modal.qtpl:42 //line views/modal.qtpl:44
qw422016.N().S(`" required autofocus id="new-name" name="new-name"/> qw422016.N().S(`" required autofocus id="new-name" name="new-name"/>
<input type="checkbox" id="recursive" name="recursive" value="true" checked/> <input type="checkbox" id="recursive" name="recursive" value="true" checked/>
<label for="recursive">`) <label for="recursive">`)
//line views/modal.qtpl:45 //line views/modal.qtpl:47
qw422016.E().S(lc.Get("ui.rename_recurse")) qw422016.E().S(lc.Get("ui.rename_recurse"))
//line views/modal.qtpl:45 //line views/modal.qtpl:47
qw422016.N().S(`</label> qw422016.N().S(`</label>
<p>`) <p>`)
//line views/modal.qtpl:47 //line views/modal.qtpl:49
qw422016.E().S(lc.Get("ui.rename_tip")) qw422016.E().S(lc.Get("ui.rename_tip"))
//line views/modal.qtpl:47 //line views/modal.qtpl:49
qw422016.N().S(`</p> qw422016.N().S(`</p>
`) `)
//line views/modal.qtpl:48 //line views/modal.qtpl:50
streammodalEnd(qw422016, hyphaName, false, lc) streammodalEnd(qw422016, hyphaName, false, lc)
//line views/modal.qtpl:48 //line views/modal.qtpl:50
qw422016.N().S(` qw422016.N().S(`
`) `)
//line views/modal.qtpl:49 //line views/modal.qtpl:51
} }
//line views/modal.qtpl:49 //line views/modal.qtpl:51
func WriteRenameAskHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName string) { func WriteRenameAskHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName string) {
//line views/modal.qtpl:49 //line views/modal.qtpl:51
qw422016 := qt422016.AcquireWriter(qq422016) qw422016 := qt422016.AcquireWriter(qq422016)
//line views/modal.qtpl:49 //line views/modal.qtpl:51
StreamRenameAskHTML(qw422016, rq, hyphaName) StreamRenameAskHTML(qw422016, rq, hyphaName)
//line views/modal.qtpl:49 //line views/modal.qtpl:51
qt422016.ReleaseWriter(qw422016) qt422016.ReleaseWriter(qw422016)
//line views/modal.qtpl:49 //line views/modal.qtpl:51
} }
//line views/modal.qtpl:49 //line views/modal.qtpl:51
func RenameAskHTML(rq *http.Request, hyphaName string) string { func RenameAskHTML(rq *http.Request, hyphaName string) string {
//line views/modal.qtpl:49 //line views/modal.qtpl:51
qb422016 := qt422016.AcquireByteBuffer() qb422016 := qt422016.AcquireByteBuffer()
//line views/modal.qtpl:49 //line views/modal.qtpl:51
WriteRenameAskHTML(qb422016, rq, hyphaName) WriteRenameAskHTML(qb422016, rq, hyphaName)
//line views/modal.qtpl:49 //line views/modal.qtpl:51
qs422016 := string(qb422016.B) qs422016 := string(qb422016.B)
//line views/modal.qtpl:49 //line views/modal.qtpl:51
qt422016.ReleaseByteBuffer(qb422016) qt422016.ReleaseByteBuffer(qb422016)
//line views/modal.qtpl:49 //line views/modal.qtpl:51
return qs422016 return qs422016
//line views/modal.qtpl:49 //line views/modal.qtpl:51
} }
//line views/modal.qtpl:51 //line views/modal.qtpl:53
func streammodalReallyWant(qw422016 *qt422016.Writer, hyphaName, verb string, lc *l18n.Localizer) { func streammodalReallyWant(qw422016 *qt422016.Writer, hyphaName, verb string, lc *l18n.Localizer) {
//line views/modal.qtpl:51 //line views/modal.qtpl:53
qw422016.N().S(` qw422016.N().S(`
<p class="modal__confirmation-msg">`) <p class="modal__confirmation-msg">`)
//line views/modal.qtpl:52 //line views/modal.qtpl:54
qw422016.N().S(lc.Get("ui.ask_really", &l18n.Replacements{"verb": verb, "name": fmt.Sprintf("<em>%s</em>", hyphaName)})) qw422016.N().S(lc.Get("ui.ask_really", &l18n.Replacements{"verb": verb, "name": fmt.Sprintf("<em>%s</em>", hyphaName)}))
//line views/modal.qtpl:52 //line views/modal.qtpl:54
qw422016.N().S(`</p> qw422016.N().S(`</p>
`) `)
//line views/modal.qtpl:53 //line views/modal.qtpl:55
} }
//line views/modal.qtpl:53 //line views/modal.qtpl:55
func writemodalReallyWant(qq422016 qtio422016.Writer, hyphaName, verb string, lc *l18n.Localizer) { func writemodalReallyWant(qq422016 qtio422016.Writer, hyphaName, verb string, lc *l18n.Localizer) {
//line views/modal.qtpl:53 //line views/modal.qtpl:55
qw422016 := qt422016.AcquireWriter(qq422016) qw422016 := qt422016.AcquireWriter(qq422016)
//line views/modal.qtpl:53 //line views/modal.qtpl:55
streammodalReallyWant(qw422016, hyphaName, verb, lc) streammodalReallyWant(qw422016, hyphaName, verb, lc)
//line views/modal.qtpl:53 //line views/modal.qtpl:55
qt422016.ReleaseWriter(qw422016) qt422016.ReleaseWriter(qw422016)
//line views/modal.qtpl:53 //line views/modal.qtpl:55
} }
//line views/modal.qtpl:53 //line views/modal.qtpl:55
func modalReallyWant(hyphaName, verb string, lc *l18n.Localizer) string { func modalReallyWant(hyphaName, verb string, lc *l18n.Localizer) string {
//line views/modal.qtpl:53 //line views/modal.qtpl:55
qb422016 := qt422016.AcquireByteBuffer() qb422016 := qt422016.AcquireByteBuffer()
//line views/modal.qtpl:53 //line views/modal.qtpl:55
writemodalReallyWant(qb422016, hyphaName, verb, lc) writemodalReallyWant(qb422016, hyphaName, verb, lc)
//line views/modal.qtpl:53 //line views/modal.qtpl:55
qs422016 := string(qb422016.B) qs422016 := string(qb422016.B)
//line views/modal.qtpl:53 //line views/modal.qtpl:55
qt422016.ReleaseByteBuffer(qb422016) qt422016.ReleaseByteBuffer(qb422016)
//line views/modal.qtpl:53 //line views/modal.qtpl:55
return qs422016 return qs422016
//line views/modal.qtpl:53 //line views/modal.qtpl:55
} }
//line views/modal.qtpl:55 //line views/modal.qtpl:57
func streammodalBegin(qw422016 *qt422016.Writer, path, hyphaName, formAttrs, legend string) { func streammodalBegin(qw422016 *qt422016.Writer, path, hyphaName, formAttrs, legend string) {
//line views/modal.qtpl:55 //line views/modal.qtpl:57
qw422016.N().S(` qw422016.N().S(`
<div class="layout"> <div class="layout">
<main class="main-width"> <main class="main-width">
<form class="modal" action="/`) <form class="modal" action="/`)
//line views/modal.qtpl:58 //line views/modal.qtpl:60
qw422016.E().S(path) qw422016.E().S(path)
//line views/modal.qtpl:58 //line views/modal.qtpl:60
qw422016.N().S(`/`) qw422016.N().S(`/`)
//line views/modal.qtpl:58 //line views/modal.qtpl:60
qw422016.E().S(hyphaName) qw422016.E().S(hyphaName)
//line views/modal.qtpl:58 //line views/modal.qtpl:60
qw422016.N().S(`"`) qw422016.N().S(`"`)
//line views/modal.qtpl:58 //line views/modal.qtpl:60
qw422016.N().S(formAttrs) qw422016.N().S(formAttrs)
//line views/modal.qtpl:58 //line views/modal.qtpl:60
qw422016.N().S(`> qw422016.N().S(`>
<fieldset class="modal__fieldset"> <fieldset class="modal__fieldset">
<legend class="modal__title">`) <legend class="modal__title">`)
//line views/modal.qtpl:60 //line views/modal.qtpl:62
qw422016.N().S(legend) qw422016.N().S(legend)
//line views/modal.qtpl:60 //line views/modal.qtpl:62
qw422016.N().S(`</legend> qw422016.N().S(`</legend>
`) `)
//line views/modal.qtpl:61 //line views/modal.qtpl:63
} }
//line views/modal.qtpl:61 //line views/modal.qtpl:63
func writemodalBegin(qq422016 qtio422016.Writer, path, hyphaName, formAttrs, legend string) { func writemodalBegin(qq422016 qtio422016.Writer, path, hyphaName, formAttrs, legend string) {
//line views/modal.qtpl:61 //line views/modal.qtpl:63
qw422016 := qt422016.AcquireWriter(qq422016) qw422016 := qt422016.AcquireWriter(qq422016)
//line views/modal.qtpl:61 //line views/modal.qtpl:63
streammodalBegin(qw422016, path, hyphaName, formAttrs, legend) streammodalBegin(qw422016, path, hyphaName, formAttrs, legend)
//line views/modal.qtpl:61 //line views/modal.qtpl:63
qt422016.ReleaseWriter(qw422016) qt422016.ReleaseWriter(qw422016)
//line views/modal.qtpl:61 //line views/modal.qtpl:63
} }
//line views/modal.qtpl:61 //line views/modal.qtpl:63
func modalBegin(path, hyphaName, formAttrs, legend string) string { func modalBegin(path, hyphaName, formAttrs, legend string) string {
//line views/modal.qtpl:61 //line views/modal.qtpl:63
qb422016 := qt422016.AcquireByteBuffer() qb422016 := qt422016.AcquireByteBuffer()
//line views/modal.qtpl:61 //line views/modal.qtpl:63
writemodalBegin(qb422016, path, hyphaName, formAttrs, legend) writemodalBegin(qb422016, path, hyphaName, formAttrs, legend)
//line views/modal.qtpl:61 //line views/modal.qtpl:63
qs422016 := string(qb422016.B) qs422016 := string(qb422016.B)
//line views/modal.qtpl:61 //line views/modal.qtpl:63
qt422016.ReleaseByteBuffer(qb422016) qt422016.ReleaseByteBuffer(qb422016)
//line views/modal.qtpl:61 //line views/modal.qtpl:63
return qs422016 return qs422016
//line views/modal.qtpl:61 //line views/modal.qtpl:63
} }
//line views/modal.qtpl:63 //line views/modal.qtpl:65
func streammodalEnd(qw422016 *qt422016.Writer, hyphaName string, shouldFocusOnConfirm bool, lc *l18n.Localizer) { func streammodalEnd(qw422016 *qt422016.Writer, hyphaName string, shouldFocusOnConfirm bool, lc *l18n.Localizer) {
//line views/modal.qtpl:63 //line views/modal.qtpl:65
qw422016.N().S(` qw422016.N().S(`
<button type="submit" value="Confirm" class="btn" `) <button type="submit" value="Confirm" class="btn" `)
//line views/modal.qtpl:64 //line views/modal.qtpl:66
if shouldFocusOnConfirm { if shouldFocusOnConfirm {
//line views/modal.qtpl:64 //line views/modal.qtpl:66
qw422016.N().S(`autofocus`) qw422016.N().S(`autofocus`)
//line views/modal.qtpl:64 //line views/modal.qtpl:66
} }
//line views/modal.qtpl:64 //line views/modal.qtpl:66
qw422016.N().S(`>`) qw422016.N().S(`>`)
//line views/modal.qtpl:64 //line views/modal.qtpl:66
qw422016.E().S(lc.Get("ui.confirm")) qw422016.E().S(lc.Get("ui.confirm"))
//line views/modal.qtpl:64 //line views/modal.qtpl:66
qw422016.N().S(`</button> qw422016.N().S(`</button>
<a href="/hypha/`) <a href="/hypha/`)
//line views/modal.qtpl:65 //line views/modal.qtpl:67
qw422016.E().S(hyphaName) qw422016.E().S(hyphaName)
//line views/modal.qtpl:65 //line views/modal.qtpl:67
qw422016.N().S(`" class="btn btn_weak">`) qw422016.N().S(`" class="btn btn_weak">`)
//line views/modal.qtpl:65 //line views/modal.qtpl:67
qw422016.E().S(lc.Get("ui.cancel")) qw422016.E().S(lc.Get("ui.cancel"))
//line views/modal.qtpl:65 //line views/modal.qtpl:67
qw422016.N().S(`</a> qw422016.N().S(`</a>
</fieldset> </fieldset>
</form> </form>
</main> </main>
</div> </div>
`) `)
//line views/modal.qtpl:70 //line views/modal.qtpl:72
} }
//line views/modal.qtpl:70 //line views/modal.qtpl:72
func writemodalEnd(qq422016 qtio422016.Writer, hyphaName string, shouldFocusOnConfirm bool, lc *l18n.Localizer) { func writemodalEnd(qq422016 qtio422016.Writer, hyphaName string, shouldFocusOnConfirm bool, lc *l18n.Localizer) {
//line views/modal.qtpl:70 //line views/modal.qtpl:72
qw422016 := qt422016.AcquireWriter(qq422016) qw422016 := qt422016.AcquireWriter(qq422016)
//line views/modal.qtpl:70 //line views/modal.qtpl:72
streammodalEnd(qw422016, hyphaName, shouldFocusOnConfirm, lc) streammodalEnd(qw422016, hyphaName, shouldFocusOnConfirm, lc)
//line views/modal.qtpl:70 //line views/modal.qtpl:72
qt422016.ReleaseWriter(qw422016) qt422016.ReleaseWriter(qw422016)
//line views/modal.qtpl:70 //line views/modal.qtpl:72
} }
//line views/modal.qtpl:70 //line views/modal.qtpl:72
func modalEnd(hyphaName string, shouldFocusOnConfirm bool, lc *l18n.Localizer) string { func modalEnd(hyphaName string, shouldFocusOnConfirm bool, lc *l18n.Localizer) string {
//line views/modal.qtpl:70 //line views/modal.qtpl:72
qb422016 := qt422016.AcquireByteBuffer() qb422016 := qt422016.AcquireByteBuffer()
//line views/modal.qtpl:70 //line views/modal.qtpl:72
writemodalEnd(qb422016, hyphaName, shouldFocusOnConfirm, lc) writemodalEnd(qb422016, hyphaName, shouldFocusOnConfirm, lc)
//line views/modal.qtpl:70 //line views/modal.qtpl:72
qs422016 := string(qb422016.B) qs422016 := string(qb422016.B)
//line views/modal.qtpl:70 //line views/modal.qtpl:72
qt422016.ReleaseByteBuffer(qb422016) qt422016.ReleaseByteBuffer(qb422016)
//line views/modal.qtpl:70 //line views/modal.qtpl:72
return qs422016 return qs422016
//line views/modal.qtpl:70 //line views/modal.qtpl:72
} }

View File

@ -19,108 +19,95 @@ import (
) )
func initMutators(r *mux.Router) { func initMutators(r *mux.Router) {
// Those that do not actually mutate anything:
r.PathPrefix("/edit/").HandlerFunc(handlerEdit) r.PathPrefix("/edit/").HandlerFunc(handlerEdit)
r.PathPrefix("/rename/").HandlerFunc(handlerRename).Methods("GET", "POST") r.PathPrefix("/rename/").HandlerFunc(handlerRename).Methods("GET", "POST")
r.PathPrefix("/delete-ask/").HandlerFunc(handlerDeleteAsk) r.PathPrefix("/delete/").HandlerFunc(handlerDelete).Methods("GET", "POST")
r.PathPrefix("/unattach-ask/").HandlerFunc(handlerUnattachAsk) r.PathPrefix("/remove-media/").HandlerFunc(handlerRemoveMedia).Methods("GET", "POST")
// And those that do mutate something:
r.PathPrefix("/upload-binary/").HandlerFunc(handlerUploadBinary) r.PathPrefix("/upload-binary/").HandlerFunc(handlerUploadBinary)
r.PathPrefix("/upload-text/").HandlerFunc(handlerUploadText) r.PathPrefix("/upload-text/").HandlerFunc(handlerUploadText)
r.PathPrefix("/delete-confirm/").HandlerFunc(handlerDeleteConfirm)
r.PathPrefix("/unattach-confirm/").HandlerFunc(handlerUnattachConfirm)
} }
/// TODO: this is ridiculous, refactor heavily: /// TODO: this is no longer ridiculous, but is now ugly. Gotta make it at least bearable to look at :-/
func factoryHandlerAsker( func handlerRemoveMedia(w http.ResponseWriter, rq *http.Request) {
actionPath string,
asker func(*user.User, hyphae.Hypha, *l18n.Localizer) error,
succTitleKey string,
succPageTemplate func(*http.Request, string) string,
) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, rq *http.Request) {
util.PrepareRq(rq) util.PrepareRq(rq)
var ( var (
hyphaName = util.HyphaNameFromRq(rq, actionPath)
h = hyphae.ByName(hyphaName)
u = user.FromRequest(rq) u = user.FromRequest(rq)
lc = l18n.FromRequest(rq) lc = l18n.FromRequest(rq)
h = hyphae.ByName(util.HyphaNameFromRq(rq, "delete"))
) )
if err := asker(u, h, lc); err != nil { if !u.CanProceed("remove-media") {
httpErr( httpErr(w, lc, http.StatusForbidden, h.CanonicalName(), "no rights")
w,
lc,
http.StatusInternalServerError,
hyphaName,
err.Error())
return return
} }
if rq.Method == "GET" {
util.HTTP200Page( util.HTTP200Page(
w, w,
views.BaseHTML( views.BaseHTML(
fmt.Sprintf(lc.Get(succTitleKey), util.BeautifulName(hyphaName)), fmt.Sprintf(lc.Get("ui.ask_remove_media"), util.BeautifulName(h.CanonicalName())),
succPageTemplate(rq, hyphaName), views.RemoveMediaAskHTML(rq, h.CanonicalName()),
lc, lc,
u)) u))
}
}
var handlerUnattachAsk = factoryHandlerAsker(
"unattach-ask",
shroom.CanUnattach,
"ui.ask_unattach",
views.UnattachAskHTML,
)
var handlerDeleteAsk = factoryHandlerAsker(
"delete-ask",
shroom.CanDelete,
"ui.ask_delete",
views.DeleteAskHTML,
)
func factoryHandlerConfirmer(
actionPath string,
confirmer func(hyphae.Hypha, *user.User, *http.Request) error,
) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, rq *http.Request) {
util.PrepareRq(rq)
var (
hyphaName = util.HyphaNameFromRq(rq, actionPath)
h = hyphae.ByName(hyphaName)
u = user.FromRequest(rq)
lc = l18n.FromRequest(rq)
)
if err := confirmer(h, u, rq); err != nil {
httpErr(w, lc, http.StatusInternalServerError, hyphaName,
err.Error())
return return
} }
http.Redirect(w, rq, "/hypha/"+hyphaName, http.StatusSeeOther) switch h := h.(type) {
case *hyphae.EmptyHypha, *hyphae.TextualHypha:
httpErr(w, lc, http.StatusForbidden, h.CanonicalName(), "no media to remove")
return
case *hyphae.MediaHypha:
if err := shroom.RemoveMedia(u, h, lc); err != nil {
httpErr(w, lc, http.StatusInternalServerError, h.CanonicalName(), err.Error())
return
}
} }
} }
var handlerUnattachConfirm = factoryHandlerConfirmer( func handlerDelete(w http.ResponseWriter, rq *http.Request) {
"unattach-confirm", util.PrepareRq(rq)
func(h hyphae.Hypha, u *user.User, rq *http.Request) error { var (
return shroom.UnattachHypha(u, h, l18n.FromRequest(rq)) u = user.FromRequest(rq)
}, lc = l18n.FromRequest(rq)
h = hyphae.ByName(util.HyphaNameFromRq(rq, "delete"))
) )
var handlerDeleteConfirm = factoryHandlerConfirmer( switch h.(type) {
"delete-confirm", case *hyphae.EmptyHypha:
func(h hyphae.Hypha, u *user.User, rq *http.Request) error { log.Printf("%s tries to delete empty hypha %s", u.Name, h.CanonicalName())
return shroom.DeleteHypha(u, h, l18n.FromRequest(rq)) // TODO: localize
}, httpErr(w, lc, http.StatusForbidden, h.CanonicalName(), "Cannot delete an empty hypha")
) return
}
if !u.CanProceed("delete") {
log.Printf("%s has no rights to delete %s\n", u.Name, h.CanonicalName())
httpErr(w, lc, http.StatusForbidden, h.CanonicalName(), "No rights")
return
}
if rq.Method == "GET" {
util.HTTP200Page(
w,
views.BaseHTML(
fmt.Sprintf(lc.Get("ui.ask_delete"), util.BeautifulName(h.CanonicalName())),
views.DeleteAskHTML(rq, h.CanonicalName()),
lc,
u))
return
}
if err := shroom.DeleteHypha(u, h, lc); err != nil {
log.Println(err)
httpErr(w, lc, http.StatusInternalServerError, h.CanonicalName(), err.Error())
}
http.Redirect(w, rq, "/hypha/"+h.CanonicalName(), http.StatusSeeOther)
}
func handlerRename(w http.ResponseWriter, rq *http.Request) { func handlerRename(w http.ResponseWriter, rq *http.Request) {
util.PrepareRq(rq) util.PrepareRq(rq)
var ( var (
u = user.FromRequest(rq) u = user.FromRequest(rq)
lc = l18n.FromRequest(rq) lc = l18n.FromRequest(rq)
h = hyphae.ByName(util.HyphaNameFromRq(rq, "rename-confirm")) h = hyphae.ByName(util.HyphaNameFromRq(rq, "rename"))
) )
switch h.(type) { switch h.(type) {
@ -130,6 +117,12 @@ func handlerRename(w http.ResponseWriter, rq *http.Request) {
return return
} }
if !u.CanProceed("rename") {
log.Printf("%s has no rights to rename %s\n", u.Name, h.CanonicalName())
httpErr(w, lc, http.StatusForbidden, h.CanonicalName(), "No rights")
return
}
var ( var (
oldHypha = h.(hyphae.ExistingHypha) oldHypha = h.(hyphae.ExistingHypha)
newName = util.CanonicalName(rq.PostFormValue("new-name")) newName = util.CanonicalName(rq.PostFormValue("new-name"))
@ -144,6 +137,7 @@ func handlerRename(w http.ResponseWriter, rq *http.Request) {
views.RenameAskHTML(rq, oldHypha.CanonicalName()), views.RenameAskHTML(rq, oldHypha.CanonicalName()),
lc, lc,
u)) u))
return
} }
if err := shroom.Rename(oldHypha, newName, recursive, u); err != nil { if err := shroom.Rename(oldHypha, newName, recursive, u); err != nil {