Add new sub pages only to pages where you have edit permission

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
SimonSchaufi

Add new sub pages only to pages where you have edit permission

Post by SimonSchaufi »

The changes i made change the dropdown field in the addpages.php. If a user has limited access (no permission to edit all pages but can edit some pages) he will not be able to add new pages to the root for example which would cause trouble. With this new function he will only be able to add new pages UNDER the pages where he has the permission to edit them (or if he is an additional editor). This is optional and can be deleted if you want.

please replace this function in class.contentoperations.inc.php:
        function CreateHierarchyDropdown($current = '', $parent = '', $name = 'parent_id')
        {
                $userid = get_userid(); //added
             
                $result = '';

                $allcontent =& ContentOperations::GetAllContent();

                if ($allcontent !== FALSE && count($allcontent) > 0)
                {
                        $result .= '';
                     
                        if(check_permission($userid, 'Modify Any Page')){ //added
                                $result .= 'None';
                        } //added
                     
                        $curhierarchy = '';

                        foreach ($allcontent as $one)
                        {
                                if ($one->Id() == $current)
                                {
                                        #Grab hierarchy just in case we need to check children
                                        #(which will always be after)
                                        $curhierarchy = $one->Hierarchy();

                                        #Then jump out.  We don't want ourselves in the list.
                                        continue;
                                }
                                #If it's a child of the current, we don't want to show it as it
                                #could cause a deadlock.
                                if ($curhierarchy != '' && strstr($one->Hierarchy() . '.', $curhierarchy
. '.') == $one->Hierarchy() . '.')
                                {
                                        continue;
                                }
                             
                                if( in_array($userid, $one->GetAdditionalEditors()) || $userid == $one->Owner()
|| check_permission($userid, 'Modify Any Page')){ //added

                                        #Don't include content types that do not want children either...
                                        if ($one->WantsChildren() == true)
                                        {
                                                $result .= 'Id().'"';

                                                #Select current parent if it exists
                                                if ($one->Id() == $parent)
                                                {
                                                        $result .= ' selected="selected"';
                                                }

                                                $result .= '>'.$one->Hierarchy().'. -
'.$one->Name().'';
                                        }
                                } //added
                        }

                        $result .= '';
                }

                return $result;
        }
Last edited by SimonSchaufi on Thu Oct 11, 2007 3:28 pm, edited 1 time in total.
cyberman

Re: Add new sub pages only to pages where you have edit permission

Post by cyberman »

Thanks for that Simon.

Maybe you can add it to forge ...
SimonSchaufi

Re: Add new sub pages only to pages where you have edit permission

Post by SimonSchaufi »

done already...

i added it as a feature request.
Pierre M.

Re: Add new sub pages only to pages where you have edit permission

Post by Pierre M. »

Thank you Simon.
Pierre
SimonSchaufi

Re: Add new sub pages only to pages where you have edit permission

Post by SimonSchaufi »

if the list is empty there must still be a permission check that the user is not allowed to add pages to root without having the rights.
Post Reply

Return to “Developers Discussion”