Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+11 votes
2.2k views
in Plugins by
Originated from my core hack: https://github.com/q2a/question2answer/issues/256#issuecomment-114180418

Released as plugin: https://github.com/q2apro/q2apro-userrules

See comments for what it does: https://github.com/q2apro/q2apro-userrules/blob/master/q2apro-userrules-overrides.php

Overview:
- do not show answer button if spam-limit exceeded
- normal users are not allowed to edit posts after x min
- edit time frame: 5 min (300s) for questions/comments + 20 min (1200s) for answers
- questions cannot be reopened, only admin
- Expert: allowed to edit own answers and all questions
- Editor: can edit all posts in forum, but not admin posts
- admin has all rights
- only experts, moderators, admins can close questions
- do not show retag button as it does the same as edit button

Hope that helps.
Q2A version: 1.7
by

3 Answers

0 votes
by

@q2apro.com its nice plugin.

How i add for moderator only edit and hide question. For QA_USER_LEVEL_EDITOR i add this code. Its nice work.

// Redakteur (highest level)
        else if ($level==QA_USER_LEVEL_EDITOR) 
        {
            // can edit all posts in forum, but not admin posts
            $rules['editable'] = $rules['editbutton'] = $rules['hideable'] = ($post['userid']!=1);
            // can clear flags
            $rules['clearflaggable'] = ($post['flagcount']>=(@$post['userflag'] ? 2 : 1));
        }

after  $rules['editable'] i add $rules['editbutton'] = $rules['hideable'] its nice work.

And i add for Moderator add 

if ($level==QA_USER_LEVEL_EXPERT) 
        {
            // allowed to edit own answers and all questions
            // time frame: allow edit after 5 min and up to 7 days (604800 sec), can edit his own answer immediately
            $rules['editable'] = $rules['editbutton'] = $rules['hideable'] =
                ($rules['isbyuser'] || $post['type']=='Q') // can edit his own post and all questions in forum
                    && (!isset($post['closedbyid'])) // post is not closed, if closed it must be of user to let him edit or Redakteur-Level
                        && ($post['userid']!=1); // never allow question-posts of admin to be edited
        }

but its not work.

by
I find it. Thanks.
I add

if ($level>=QA_USER_LEVEL_MODERATOR)
        {
            $rules['editable'] = $rules['editbutton'] = $rules['hideable'] = true;
        }

after // admin has all rights code
0 votes
by
Hi. Thanks for the effort.
I think your plugin has a little problem.
I installed it on my test site.
And it changed what I had selected in "posting"

 

I tried to fix but still the same user can add more than one answer per question. The standard editor has also been changed.
Note: I do not activated the plugin or modified options. I have just installed and then uninstalled it and my site was back to normal.
by
Can you give some more details, it is not clear what exactly is the problem with the editor?

"the same user can add more than one answer per question." - Oh, you are right, just now I see that there is a problem. This was due to calling the base function with parameters set "=null". I have fixed that now, line 16: https://github.com/q2apro/q2apro-userrules/blob/master/q2apro-userrules-overrides.php
+1 vote
by

One bug. The $rules['closeable']  should consider if qa_opt('allow_close_questions')  option.

so it should be

// experts, moderators, admins can close questions

$rules['closeable'] = ( qa_opt('allow_close_questions') && $level>=QA_USER_LEVEL_EXPERT && !$rules['closed'] );

...