News Module modification : 'Add News' permission only
Posted: Thu Jul 03, 2008 8:38 am
The company I work for is hiring freelancers to write news, however their access will be limited to add news only and they must not see other modules. And while they're in News module page, they must not be able to delete, publish, create category, etc. "Add News" is the only option they shall see. Of course editing the news and changing its category is still allowed.
So I made little modification to the News module. Here's what I've done:
- Create new permission directly to the database, add "Add News" into table cms_permissions
- Update the ID number in cms_permissions_seq to the latest ID number in cms_permissions
- Create new group in CMSMS, I called this group "Freelancer"
- Assign 'Add News' permission to the group above. This permission will be the only permission they have
- Add users and assign Freelancer group to them
The administration stuff is done, now I open and edit these three files in News module: News.module.php, action.defaultadmin.php, and action.addarticle.php.
In News.module.php:
- Find function 'VisibleToAdminUser'
- Add this "$this->CheckPermission('Add News') ||" after "return" statement
In action.addarticle.php search for $this->CheckPermission('Modify News'). Change it like below:
Now, we must be aware that Admin group will have access to all permissions, we need to have a flag to identify user permission correctly.
Open action.defaultadmin.php and search for $this->CheckPermission('Modify News'). Edit it like shown below:
Now still in the same file, search for echo $this->StartTabContent();, below it add this line:
That's it! Now users in Freelancer group will only see "News" in "Content" menu and one tab only, 'Articles', in the News module.
Cheers!
So I made little modification to the News module. Here's what I've done:
- Create new permission directly to the database, add "Add News" into table cms_permissions
- Update the ID number in cms_permissions_seq to the latest ID number in cms_permissions
- Create new group in CMSMS, I called this group "Freelancer"
- Assign 'Add News' permission to the group above. This permission will be the only permission they have
- Add users and assign Freelancer group to them
The administration stuff is done, now I open and edit these three files in News module: News.module.php, action.defaultadmin.php, and action.addarticle.php.
In News.module.php:
- Find function 'VisibleToAdminUser'
- Add this "$this->CheckPermission('Add News') ||" after "return" statement
In action.addarticle.php search for $this->CheckPermission('Modify News'). Change it like below:
Code: Select all
if (!$this->CheckPermission('Add News') && !$this->CheckPermission('Modify News'))
{
echo $this->ShowErrors($this->Lang('needpermission', array('Add/Modify News')));
return;
}
Open action.defaultadmin.php and search for $this->CheckPermission('Modify News'). Edit it like shown below:
Code: Select all
// to identify whether the user is having 'Modify News' permission or not
$use_modify = false;
if ($this->CheckPermission('Modify News'))
{
echo $this->SetTabHeader('articles',$this->Lang('articles'), ('articles' == $tab)?true:false);
echo $this->SetTabHeader('categories',$this->Lang('categories'), ('categories' == $tab)?true:false);
echo $this->SetTabHeader('customfields',$this->Lang('customfields'),
('customfields'==$tab)?true:false);
$use_modify = true; // user has Modify News permission, so Add News permission won't be activated
}
// ADD NEWS
// will be called only if user does not have 'Modify News' permission
if ($this->CheckPermission('Add News') && !$use_modify)
{
echo $this->SetTabHeader('articles',$this->Lang('articles'), ('articles' == $tab)?true:false);
}
Code: Select all
// ADD NEWS
// will be called only if user doesn't have Modify News permission
if ($this->CheckPermission('Add News') && !$use_modify)
{
echo $this->StartTab('articles', $params);
include(dirname(__FILE__).'/function.admin_articlestab.php');
echo $this->EndTab();
}
That's it! Now users in Freelancer group will only see "News" in "Content" menu and one tab only, 'Articles', in the News module.
Cheers!