Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
749 views
in Q2A Core by
If I want to restrict posting of questions based on a certain profile field value, what should be the ideal way to do it?
Q2A version: 1.8

1 Answer

+1 vote
by
selected by
 
Best answer

It is unclear exactly WHEN you want to restrict it. If you want to restrict it while the user tries to answer the question, you could use a filter module. In there implement the appropriate method and fetch the logged in user profile fields to process them. Then decide whether to proceed or to show an error.

However, in practice, I guess you don't even want the user to see the ask form. In that case, you'll have to remove any ask button links. You can get that done with a layer.

Note what I mention above about the layer is just removing a button. You still need to take care of the GET and the POST to the ask page. The GET, you can handle it by redirecting the user or showing them a no-permission error. This can be done in the layer itself. For the POST, you can take advantage of the filter module exactly as explained originally.

So the layer doesn't really replace the filter module but rather complements it to provide a better user experience.

by
Thank you Pupi. Actually I exactly want a new permission to the already existing list of required ones like "Regiatered Users", "Email confirmed", "Enough points" and show the User the corresponding reason. Actually the profile field I mentioned is "Verified" and so it exactly works as a normal permission and so no need to hide the "Ask button". Sorry for the confusion.

Is filter module the right way for this or extending the set of available permission list?
by
But the permit will allow or block for asking questions. There already exists a permit for that. You want to modify how the permit is obtained. In that case, you might be interested in overriding qa_permit_error(). I wouldn't do it... it is quite a core function. So every time the "permit_post_q" is checked and would return a pass your override will catch it and perform the extra processing.

Alternatively, if you want to add a new (redundant) privilege to be displayed in the user profile, you can do that, again, with the layer, dynamically adding the permit row where you want it.

Regarding setting the level (in a combobox) the user needs to bypass the barrier, that's just a matter of creating the admin option field. You could hardcode that part anyway.

Specifically answering your last question question. There is no standard approach to extending the permissions. The recipe is half a spoon of knowing Q2A and half a spoon of creativity :)
by
Thank you Pupi. That's exactly what I wanted -- a new permit to allow questions. I might need to do all of those which you mentioned
...