core icon indicating copy to clipboard operation
core copied to clipboard

ownCloud message output to templates is inflexible

Open ringmaster opened this issue 13 years ago • 6 comments

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:

  1. The output of a new message requires that the new message also be hardcoded into the template, including all additional wrapping HTML.
  2. 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.

ringmaster avatar Nov 27 '13 02:11 ringmaster

:+1:

MorrisJobke avatar Nov 27 '13 08:11 MorrisJobke

good idea. Let's look into that for ownCloud 7

karlitschek avatar Nov 27 '13 08:11 karlitschek

Defer to OC8 ?

PVince81 avatar Jun 20 '14 16:06 PVince81

Oc8 from my pov

DeepDiver1975 avatar Jun 20 '14 16:06 DeepDiver1975

I'm highly uncertain if this is still needed -> backlog

DeepDiver1975 avatar Jan 09 '15 14:01 DeepDiver1975

We use a controller for this now -> invalid

RobinMcCorkell avatar Aug 29 '15 21:08 RobinMcCorkell