Add 'restricted' option to NoticeTitle; if set, only users with 'richedit' role get the fancy extra title field.
This commit is contained in:
parent
d7f03dab9e
commit
8ad933c86f
@ -51,6 +51,12 @@ define('NOTICE_TITLE_PLUGIN_VERSION', '0.1');
|
|||||||
|
|
||||||
class NoticeTitlePlugin extends Plugin
|
class NoticeTitlePlugin extends Plugin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// By default, notice-title widget will be available to all users.
|
||||||
|
// With restricted on, only users who have been granted the
|
||||||
|
// "richedit" role get it.
|
||||||
|
public $restricted = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database schema setup
|
* Database schema setup
|
||||||
*
|
*
|
||||||
@ -137,14 +143,16 @@ class NoticeTitlePlugin extends Plugin
|
|||||||
|
|
||||||
function onStartShowNoticeFormData($form)
|
function onStartShowNoticeFormData($form)
|
||||||
{
|
{
|
||||||
$form->out->element('style',
|
if ($this->isAllowedRichEdit()) {
|
||||||
null,
|
$form->out->element('style',
|
||||||
'label#notice_data-text-label { display: none }');
|
null,
|
||||||
$form->out->element('input', array('type' => 'text',
|
'label#notice_data-text-label { display: none }');
|
||||||
'id' => 'notice_title',
|
$form->out->element('input', array('type' => 'text',
|
||||||
'name' => 'notice_title',
|
'id' => 'notice_title',
|
||||||
'size' => 40,
|
'name' => 'notice_title',
|
||||||
'maxlength' => Notice_title::MAXCHARS));
|
'size' => 40,
|
||||||
|
'maxlength' => Notice_title::MAXCHARS));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +170,7 @@ class NoticeTitlePlugin extends Plugin
|
|||||||
function onStartNoticeSaveWeb($action, &$authorId, &$text, &$options)
|
function onStartNoticeSaveWeb($action, &$authorId, &$text, &$options)
|
||||||
{
|
{
|
||||||
$title = $action->trimmed('notice_title');
|
$title = $action->trimmed('notice_title');
|
||||||
if (!empty($title)) {
|
if (!empty($title) && $this->isAllowedRichEdit()) {
|
||||||
if (mb_strlen($title) > Notice_title::MAXCHARS) {
|
if (mb_strlen($title) > Notice_title::MAXCHARS) {
|
||||||
throw new Exception(sprintf(_m("The notice title is too long (max %d characters).",
|
throw new Exception(sprintf(_m("The notice title is too long (max %d characters).",
|
||||||
Notice_title::MAXCHARS)));
|
Notice_title::MAXCHARS)));
|
||||||
@ -186,7 +194,7 @@ class NoticeTitlePlugin extends Plugin
|
|||||||
|
|
||||||
$title = $action->trimmed('notice_title');
|
$title = $action->trimmed('notice_title');
|
||||||
|
|
||||||
if (!empty($title)) {
|
if (!empty($title) && $this->isAllowedRichEdit()) {
|
||||||
|
|
||||||
$nt = new Notice_title();
|
$nt = new Notice_title();
|
||||||
|
|
||||||
@ -327,4 +335,24 @@ class NoticeTitlePlugin extends Plugin
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the current user have permission to use the notice-title widget?
|
||||||
|
* Always true unless the plugin's "restricted" setting is on, in which
|
||||||
|
* case it's limited to users with the "richedit" role.
|
||||||
|
*
|
||||||
|
* @fixme make that more sanely configurable :)
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
private function isAllowedRichEdit()
|
||||||
|
{
|
||||||
|
if ($this->restricted) {
|
||||||
|
$user = common_current_user();
|
||||||
|
return !empty($user) && $user->hasRole('richedit');
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user