Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Limit category a user can add a link

Quote Reply
Limit category a user can add a link
Is there a way to limit a user to only be able to add links to one category? It doesn't look like there is any standard way to do this, but wondering if I added a field in the User table that defined the catIDs they were able to submit to? If i did this, how would one go about writing a global that would check that field and only display that/those categories listed in the field in the dropdown menu of categories on the add form?

Does that make sense? Do you think it would work? Basically i want to create a category for each user and limit them to adding links to their category. I looked into the Editor route, but don't want them to see all the fields shown in the Editor admin. Just want them to submit a link and get get defaulted to their category.

thanks
Quote Reply
Re: [pshadow] Limit category a user can add a link In reply to
I did this by 'switching off' the drop down selection in setup and then adding a field CatAdd Yes/No.
In the templates I used <%if CatAdd eq 'Yes'%> to control whether to display/allow people to add a link or not.
Quote Reply
Re: [Alba] Limit category a user can add a link In reply to
Thanks for the response. It's not quite the same thing I'm trying to do, but I'll try to use this and see if I can make it do what I'm looking to do. I think yours is to shut off categories all together. Where I'm trying to say User A can only post links in Category A and User B only in Category B, etc. So, maybe I can do something like you did but make the CatAdd field an actual catID and then do something similar in the template to show category dropdown only if CatID matches.

In your implementation, what happens if they go to the add form and the CatAdd is No? Do they get an error message when trying to submit a link or does the link get inserted into a top level category?
Quote Reply
Re: [pshadow] Limit category a user can add a link In reply to
Quote:
In your implementation, what happens if they go to the add form and the CatAdd is No? Do they get an error message when trying to submit a link or does the link get inserted into a top level category?

They don't see the 'add' link on the category pages therefore cannot add a link.
Quote Reply
Re: [Alba] Limit category a user can add a link In reply to
Ah, so you put your code in the header template and it only shows the "Add a Link" if that user drills down to a category where CatADD eq Yes.

Very cool. That should help, thanks for your responses.
Quote Reply
Re: [pshadow] Limit category a user can add a link In reply to
Hmm, so I tried the following:

<%if Name eq Username%> to show the "Add a Link". It doesn't seem to work putting two variables in an if statement? If I replace "Username" with the actual username it works. How do I get it to pull the Username dynamically?

I place <%Name%><%Username%> after this if statement and it displays both correctly on the page so it's can pull the two from the database but just not in that statement. Am I missing something?
Quote Reply
Re: [pshadow] Limit category a user can add a link In reply to
I figured it out. I needed to add a "$" in front of Username:

<%if Name eq $Username%>
Quote Reply
Re: [pshadow] Limit category a user can add a link In reply to
o.k. that worked but I've run into another issue. When you get to the Add a Link page, the URL has the category ID in it. If you change that ID in the URL you can insert a link in any other category.

So, I tried the same <%if Name eq $Username%> wrapped around the Add a Link form to keep the form from being displayed unless there was again a match. Then I'd display a "No Permission" type message if it wasn't.

Problem is "Name" (the category name) isn't available in the Add.cgi page. I created a catname global to retrieve the "Name" and it works on that page. However when I try to do a <%if catname($ID) eq $Username%> it doesn't work. Can you put a global in a there?
Quote Reply
Re: [pshadow] Limit category a user can add a link In reply to
I think I figured it out using another global, posting if others have similar idea:

sub {

my $id = $_[0];

my $cat_tbl = $DB->table('Category');
my $category_full = $cat_tbl->select(['Name'],{ ID => $id })->fetchrow;
return if !$category_full;

my ($name) = split /\//, $category_full;

return { CatUserMatch => $name };

}

this gets me the Name based on Category ID, then in the add.cgi I have:
<%cat_user_match($ID)%>
<%if CatUserMatch eq $Username%>

seems to work...

Last edited by:

pshadow: Sep 25, 2005, 2:31 PM