Closed marijnkampf closed 13 years ago
Hey Marijn, thanks for the pull request.
Two minor things.
$body
array. We could use only the first message in $body[]
- which might be cleaner for users, we'd just have to make sure the behaviour was clearly documented.Your thoughts?
Don't know whether I meant to Close the pull request (sorry, still getting to grips with github).
Heh - no, shouldn't close it (means I can't auto-merge from GitHub), but that's ok I can do it the 'normal way anyway.
Re: "As it's onAccessDenied I don't think it will be an issue with multiple decorators, as they will only be called after it is known the call failed. Using $body[0] will only show the body from the last call, which may add confusion. I'm not sure whether the implode or $body[0] would be the best solution."
My feeling is this is not the right way to get an error message. onAccessDenied
is a trigger function for auditing rather than for user interaction. The module is specifically designed to allow multiple permission schemes with precedence going to passes over fails. That means a message per permission scheme isn't appropriate (since you'll get failure messages for passed permissions).
A static method on SecureFileController is probably the best option. That way it is globally configurable to something appropriate per site, but default is a nice string.
I'll cherry-pick the relevant commits above, and add the method.
As far as I can tell the current extend('onAccessDenied') doesn't allow for customisation of the failure message displayed to the user. I've altered the call to extend('onAccessDenied') to allow overriding of permission failure message.
Sample code to extend the message:
mysite/code/FileMessage.php
<?php class FileMessage extends DataObjectDecorator { function onAccessDenied($body) { return "You have to login before you can access this file. You can create an account for free."; }
mysite/_config.php
DataObject::add_extension('File', 'FileMessage');
If user doesn't have permission he/she is shown a custom friendly message at the login screen.