Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Hide sections for non admin users
A useful feature (without any plugin) and very simple to add into TXP core: http://goo.gl/dcvmI
What do you think about it?
Last edited by Pat64 (2011-09-28 06:32:54)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: Hide sections for non admin users
Pat64 wrote:
What do you think about it?
Why not do it as a plugin? Much cleaner and it’s less than 10 lines of code. Here’s a possible example with complete (admin) control over who can see what:
if (@txpinterface == 'admin') {
register_callback('smd_per_sec', 'article_ui', 'section');
}
function smd_per_sec($event, $step, $data, $rec) {
global $txp_user;
// Admins can see everything
if($GLOBALS['privs'] === '1') {
return;
}
// Get all the sections from the database
$seclist = array();
$rs = safe_rows('name, is_default', 'txp_section', "1=1");
foreach ($rs as $sec) {
// Can only see the section if this user has privs for "section.{section_name}"
// or it's the default section
if (has_privs('section.'.$sec['name']) || $sec['is_default'] == '1') {
$seclist[$sec['name']] = $sec['name'];
}
}
// Build the filtered select list...
$seclist = selectInput('Section', $seclist, $rec['Section'], false, '', 'section');
// ... and display it
return n.graf('<label for="section">'.gTxt('section').'</label> '.
'<span class="small">['.eLink('section', '', '', '', gTxt('edit')).']</span>'.br.
$seclist).n.'</fieldset>';
}
If you happen to have smd_user_manager installed you can then go and add privs areas for sections you want users to be able to publish to, and set the tick boxes to permit certain groups of user to see them.
If that’s overkill you can do it more cheaply by either:
- hard-coding the list of sections you want
- setting a txp_pref with the allowed (or denied: your call) sections
Then compare that list with the current section in the loop and add it to the $seclist
array or not depending on what you want to achieve.
Salt to taste.
Last edited by Bloke (2011-12-09 13:09:27)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Hide sections for non admin users
Hi Block
A plugin like that can solve a lot of problems for site maintenaires with a lot of editors, with some tweek the plugin can be adapted to individual author (each author with his own section for example) and can rid the javascript limitation of other plugins.
Offline
Re: Hide sections for non admin users
Dragondz wrote:
with some tweek the plugin can be adapted to individual author
Yes, and that’s the power of pluggable_ui()
at work. Nothing against Patrick’s approach: it works well, but as he says it creates a support headache. If such a thing was included in the core then someone would ultimately want more flexibility or perhaps to even limit the list for admins too, so imo it’s better to have the core default to an open policy in this case and allow plugins to restrict that if necessary.
Of course, it’d be nice if the Sections tab had pluggable_ui()
so Patrick’s mod could be less moddy and more pluginy. But since the Sections tab is so fugly, that sort of thing is going to be deferred to Txp 5 when the whole page can be re-thought.
In the meantime you can take the above code and do what you like with it. If you want to code a sexy interface around it to control which sections can be permitted down to a user level, that’s cool.
The alternative is to use smd_user_manager as I outlined above to make new groups of users that make sense for your intended workflow, create users and assign them to those groups, then add privs for section.{section_name}
to determine which groups can see which sections. The downside? It means that adding general purpose sections is a two-step-process:
- create section in the Sections tab
- add privs for it via smd_um
But the flexibility it offers outweighs the hassle of coding a dedicated plugin by hand or hacking the core, imho.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Hide sections for non admin users
Hi Stef.
Thanks for your code example. The purpose of this thread is: (Core Devs) Do you plan – Do you find some interest – to add that kind of feature into TXP core files? IMO, capacity to hide sections to non admin users could be every days useful ;)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: Hide sections for non admin users
Pat64 wrote:
(Core Devs) Do you plan – Do you find some interest – to add that kind of feature into TXP core files?
I haven’t discussed this with the others but at the moment for me, the answer would be no. Being able to hide sections from All Users (except Admins) is not granular enough for my tastes. I suspect others too would prefer to allow Copy Editors to post to some sections and Freelancers to write to others. Doing it your way doesn’t feel “complete” enough, if that makes sense.
In essence, to do this feature justice would require a better core interface than we have. Plus the number of sites where there is a need to do this and the above plugin snippet couldn’t help is zero. So for now at least I say we carry on as normal and use the above plugin (or a variation) to cater for the special cases.
Of course if someone can find a way to make your mod more general purpose with ease, then by all means bring it here. Never say never!
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Hide sections for non admin users
Bloke wrote:
(…) Never say never!
Sure :)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: Hide sections for non admin users
Bloke wrote:
Why not do it as a plugin? Much cleaner and it’s less than 10 lines of code. Here’s a possible example with complete (admin) control over who can see what:
if (@txpinterface == 'admin') {
register_callback('smd_per_sec', 'article_ui', 'section');
}
function smd_per_sec($event, $step, $data, $rec) {
global $txp_user;
// Admins can see everything
if($GLOBALS['privs'] === '1') {
return;
}
// Get all the sections from the database
$seclist = array();
$rs = safe_rows('name, is_default', 'txp_section', "1=1");
foreach ($rs as $sec) {
// Can only see the section if this user has privs for "section.{section_name}"
// or it's the default section
if (has_privs('section.'.$sec['name']) || $sec['is_default'] == '1') {
$seclist[$sec['name']] = $sec['name'];
}
}
// Build the filtered select list...
$seclist = selectInput('Section', $seclist, $rec['Section'], false, '', 'section');
// ... and display it
return n.graf('<label for="section">'.gTxt('section').'</label> '.
'<span class="small">['.eLink('section', '', '', '', gTxt('edit')).']</span>'.br.
$seclist).n.'</fieldset>';
}
Hi again!
Question: Where do one have to insert the code in this time? will ied_plugin_composer do?
{Edited to add some Textile, to remedy consequences of full quoting and make question visible at all. – Uli}
Last edited by uli (2013-11-19 14:56:50)
Offline
Re: Hide sections for non admin users
admi wrote:
Where do one have to insert the code in this time? will ied_plugin_composer do?
Yes. Start a new plugin as you have done before and paste this code in, then enable and save the plugin.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Hide sections for non admin users
I can see some real utility in having greater control of access baked into the core. Have Access rights by groups: Copy Editors, freelancers, etc, and assigning individuals to those groups.
not sure if this is feasible or desirable by the core devs.
…. texted postive
Offline
Re: Hide sections for non admin users
bici wrote:
Have Access rights by groups… and assigning individuals to those groups.
smd_user_manager does that to some degree. But it’s a bit hacky in its present form because the core API isn’t as hot as it is in 4.6-dev. I’m sure I can improve the plugin to have less code duplication at some point.
At the core level, I haven’t really thought it through. The pre-defined roles and permissions are set up in a file and moving them to the DB isn’t all I thought it would crack up to be so we might be better off with plugins to fill this gap.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline