ownCloud message output to templates is inflexible
There are several places in ownCloud where general messages are output. Two such places include warnings on the admin page and on the login page.
When these warning are output, the warnings themselves are hardcoded into the template, and are displayed only if a flag is assigned into the template renderer. While this correctly outputs the warning, it is inflexible in that:
- The output of a new message requires that the new message also be hardcoded into the template, including all additional wrapping HTML.
- Apps cannot add new messages to existing core templates, regardless of how useful they may be.
It is also undesirable in that it sometimes places logic in the view that should be in the controller. For example, a warning may be displayed in the admin page that recommends admins require SSL connections to the server. The flag that is used to display this message is !$_["isConnectedViaHTTPS"]. Ignoring the logic applied by the negation, if a future change allowed users behind proxies to disable this message, the condition would look something like !$_["isConnectedViaHTTPS"] && !$_["HTTPSNotRequired"] which places the logic about whether to display the message in the template, rather than the controller, where it belongs.
Proposed Solution
Rather than trigger this output from the template with a flag, messages of different types should be accumulated in a array, and the array forwarded to the template. The template would then use a standard partial to output the messages.
Using this technique, multiple messages could be accumulated for output on both rendered templates and JSON responses. The rendering of these messages could be standardized in the UI, providing an improved user experience.
Example implementation The current code for output of the message regarding HTTP/HTTPS mentioned above includes one line in the controller code:
$tmpl->assign('isConnectedViaHTTPS', $connectedHTTPS);
And several lines of interwoven PHP and HTML in the admin.php template.
The change proposed would move the logic involved and the message itself into the controller, along with some rendering information:
$messages = array();
if(!connectedHTTPS) {
$messages['connecthttps'] = array(
'class' => 'warning',
'message' => $l->t('You are accessing %s via HTTP. We strongly suggest you configure your server to require using HTTPS instead.', $theme->getTitle()),
);
}
// Allow other apps to modify the displayed messages
$this->emit(__CLASS__, 'admin_messages', array(&$messages) );
$tmpl->assign('messages', $messages);
Then within the template, a partial or simple loop would be used to render the messages array.
:+1:
good idea. Let's look into that for ownCloud 7
Defer to OC8 ?
Oc8 from my pov
I'm highly uncertain if this is still needed -> backlog
We use a controller for this now -> invalid