Contribution plugin. Disable the public and anonymous options

Hello. I am using Contribution plugin. I have a question about it.
How to disable the public and anonymous item options?
I would like the user not to control the public view of the document they contributed.
The public options is a trouble because it allows the contributor (user) to decide whether a document is public or ceases to be so at any time, even though the admin has already configured it as public.

Thanks a lot.

Contribution form

Contribution panel (user view)

The plugin is opinionated about who has control of the visibility and anonymity of contributed items. In other words, there is no easy way to prevent contributrors from changing the status of their own contributions. This is by design as a way to ensure ownership.

It could work the way you’re asking if you’re comfortable modifying the code. Open this file:

/plugins/Contribution/controllers/ContributionController.php

And in Contribution_ContributionController::myContributionsAction(), change these lines:

        if(!empty($_POST)) {
            foreach($_POST['contribution_public'] as $id=>$value) {
                $contribItem = $contribItemTable->find($id);
                if($value) {
                    $contribItem->public = true;
                } else {
                    $contribItem->makeNotPublic();
                }
                $contribItem->public = $value;
                $contribItem->anonymous = $_POST['contribution_anonymous'][$id];

                if($contribItem->save()) {
                    $this->_helper->flashMessenger( __('Your contributions have been updated.'), 'success');
                } else {
                    $this->_helper->flashMessenger($contribItem->getErrors());
                }

                $contribItems[] = $contribItem;
            }
        } else {
            $contribItems = $contribItemTable->findBy(array('contributor'=>$user->id));
        }

To this:

        //~ if(!empty($_POST)) {
            //~ foreach($_POST['contribution_public'] as $id=>$value) {
                //~ $contribItem = $contribItemTable->find($id);
                //~ if($value) {
                    //~ $contribItem->public = true;
                //~ } else {
                    //~ $contribItem->makeNotPublic();
                //~ }
                //~ $contribItem->public = $value;
                //~ $contribItem->anonymous = $_POST['contribution_anonymous'][$id];

                //~ if($contribItem->save()) {
                    //~ $this->_helper->flashMessenger( __('Your contributions have been updated.'), 'success');
                //~ } else {
                    //~ $this->_helper->flashMessenger($contribItem->getErrors());
                //~ }

                //~ $contribItems[] = $contribItem;
            //~ }
        //~ } else {
            $contribItems = $contribItemTable->findBy(array('contributor'=>$user->id));
        //~ }

You’re essentially disabling the code that allows contributors to edit their contributions.

Thanks. I’m trying other ways. Remove these line from my-contributions.php worked for me:


image

Now users can’t changing the status of their own contributions.

I also found a solution to disable the public option of the contribution form. I added these lines in ContributionController.php. In this way, marking the public option is a necessary condition for the user to send the document. If the user does not check the public option, a message appears on the screen.


image

I still haven’t found a solution to remove the anonymous option.

:slightly_smiling_face: