News Module modification : 'Add News' permission only

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
taufikp
Forum Members
Forum Members
Posts: 27
Joined: Tue May 01, 2007 2:52 am

News Module modification : 'Add News' permission only

Post by taufikp »

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:

Code: Select all

if (!$this->CheckPermission('Add News') && !$this->CheckPermission('Modify News'))
  {
	echo $this->ShowErrors($this->Lang('needpermission', array('Add/Modify News')));
	return;
  }
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:

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);
  }

Now still in the same file, search for echo $this->StartTabContent();, below it add this line:

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!
Last edited by taufikp on Thu Jul 03, 2008 8:48 am, edited 1 time in total.
cyberman

Re: News Module modification : 'Add News' permission only

Post by cyberman »

Thanx.

Maybe you should post this information in patch board of project too ;)

http://dev.cmsmadesimple.org/tracker/?a ... unc=browse
taufikp
Forum Members
Forum Members
Posts: 27
Joined: Tue May 01, 2007 2:52 am

Re: News Module modification : 'Add News' permission only

Post by taufikp »

You're welcome! I'll try to post it there cyberman :)
Post Reply

Return to “Modules/Add-Ons”