Answers.Body: <p>I've got a custom extension that's designed to designate specific contribution pages as 'admin only', here: <a href="https://github.com/adixon/ca.civicrm.contributextra" rel="noreferrer">https://github.com/adixon/ca.civicrm.contributextra</a></p>
  
  <p>The actual permissions to access 'admin only' contribution pages is just set to being logged in (I just wanted to hide them from anonymous access), so it'll do what you want. It'll also generate an admin link from contact summary pages' contribution tab to the designated admin-only contribution pages.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-17T00:23:19.557Z
Answers.Text: Thanks, I'm experimenting with your extension.  I have one problem with it though.   When I set a contribution page to admin-only, it's only viewable to drupal site admins.  I'm not certain how to set it to authenticated users.  Is there a config within civi or should I look at the code?  I did modify the redirect to suit my needs.  Thank you
Answers.UserDisplayName: Peter_
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-19T13:29:45.257Z
Answers.Text: You don't need to do anything other than mark it as admin-only - the current implementation only limits access to non-anonymous users, i.e. any authenticated user will have access to it. The relevant code is line 176, here: https://github.com/adixon/ca.civicrm.contributextra/blob/master/contributextra.php
Answers.UserDisplayName: Alan Dixon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-19T18:57:20.013Z
Answers.LastActivityDate: 2015-08-19T18:57:20.013Z
Answers.UserDisplayName: Alan Dixon
Answers.Body: <p>Please <a href="https://civicrm.stackexchange.com/posts/4637/edit">edit</a> your question to expand on exactly why your goal is "to restrict our member signup page ... to people who have registered to our Drupal site"? </p>
  
  <p>Is there something "extra special" about the people who have registered on your Drupal site such that they have to be pre-approved before they can register?</p>
  
  <p>Is there any reason why people who haven't registered should not be able to <strong>view</strong> the membership page?  </p>
  
  <p>You may be able to accomplish what you need without resorting to code by making "Drupal account creation" compulsory on your signup page (done in "advanced settings" on the profile settings page) and requiring administrator approval for creating a Drupal user account.(Select  "Visitors, but administrator approval is required" for <strong>Registration and cancellation</strong> on yoursite/admin/config/people/accounts.)</p>
  
  <p>That way you could vet the "applicants" for membership before their Drupal account is created and refund the membership fees for those who are not acceptable for what ever reason.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-12T17:25:29.830Z
Answers.Text: HI JoAnne, to me it doesn't seem relevant to the question, which I thought was clear.   But if it helps, let me give you some background, which I do not think belongs in the question itself.  We are a maker space. We ask prospective members to come and meet us in person before we allow them to access the signup page. Since, crazy people and potentially dangerous tools don't go together so well.  :-) To answer your question why shouldn't unauthenticated users be able to view the membership page, if they can view it, that means they can use it.
Answers.UserDisplayName: Peter_
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-13T03:11:21.080Z
Answers.Text: Sadly, making "Drupal Account creation" compulsory on the signup page doesn't accomplish the goal, because the anonymous user is already on the sign up page, the thing we don't want to have happen.
Answers.UserDisplayName: Peter_
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-13T08:41:07.040Z
Answers.Text: I realise that, which is why I asked for more information. I would argue that your ultimate goal is not "stop anonymous users from seeing our membership form" but rather "stop unsuitable people from having access to our maker space". You are new to this site, perhaps new to CiviCRM and were possibly seeking a non-code solution. A Drupal/Civicrm site is quite complex and there may have been ways to accomplish your ultimate goal that you had not thought of. Knowing what your ultimate goal was could have made a different approach, such as the one I outlined, a viable alternative.
Answers.UserDisplayName: JoAnne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-12T13:36:14.053Z
Answers.LastActivityDate: 2015-08-13T08:24:39.177Z
Answers.LastEditDate: 2017-04-13T12:53:13.017Z
Answers.UserDisplayName: JoAnne
Answers.Body: <p>I might have misunderstood your question, but I think you are looking for something like the <a href="https://www.drupal.org/project/nodeaccess" rel="nofollow">node access</a> module, which it will allow you to restrict access to a page (ie membership page) based on user roles, ie authenticated users.</p>
  
  <p>I'm not a Drupal user so please correct me if there are better solutions.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-12T23:26:25.227Z
Answers.Text: Civi pages aren't 'drupal nodes' so doubt it can be this simple, especially as civi throws ? in to paths which some drupal path based options don't appreciate'
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-31T15:21:35.297Z
Answers.Text: Drupal considers civicrm pages as non-node callbacks, so none of the node-specific permissions are applicable. Drupal gives primary permissions responsibility to the module that defines the callback (i.e. they are in the same table/code), and so the civicrm drupal module code already has allowed everyone to access any civicrm callback, and then has it's own permissions system (in the xml files). If you really wanted to use a custom Drupal module for this problem, you could use the menu hook and add a menu entry for the contribution pages and give it a custom permissions callback.
Answers.UserDisplayName: Alan Dixon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-12T21:51:00.713Z
Answers.LastActivityDate: 2015-08-12T21:51:00.713Z
Answers.UserDisplayName: Andrei
Answers.Body: <p>A short bit of custom code could take care of this (using the <code>hook_civicrm_preProcess</code> hook I think).  It would need to check if the current page is your "sign-up" contribution page, and if it is, make sure that the user is currently logged in.  If not, it would redirect to wherever you need.</p>
  
  <p>Not positive this code is perfect, but it should get you pretty darn close...</p>
  
  <pre><code>function hook_civicrm_preProcess($formName, &amp;$form) {
  
    $form_id = 7;   // set this to the specific form_id you wish to limit access to
    $redirect_path = 'home';  // set this to the url to redirect to if not logged in
  
    if ($formName == "CRM_Contribute_Form_Contribution_Main" &amp;&amp; $form-&gt;_id == $form_id) {
      if (!user_is_logged_in()) {
        drupal_goto($redirect_path);
      }
    }
  
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-13T02:46:45.247Z
Answers.Text: I think this is the most promising path, but I can't find any example code to work from.  I've installed the civicrm development module and can see this helper info displayed on all contribution pages: hook_civicrm_preProcess called: formName is CRM_Contribute_Form_Contribution_Main.  But I can see nothing distinct about my specific contribution page I want to make private other than the url which has the contribution id.   If the hook just checks for the form name, I'm still in the same boat. All contribution pages are blocked.  I need to be checking for an id to be distinct, right?
Answers.UserDisplayName: Peter_
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-13T21:46:41.687Z
Answers.Text: @Peter_, I have added a code snippet to my original response.
Answers.UserDisplayName: DaveD
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-14T20:00:59.637Z
Answers.Text: Thanks much, I found this is code working, except that for reasons I don't understand, I'm limited to using the function name civicrm_developer_civicrm_preProcess. Then name hook_civicrm_preProcess won't work, or any others I try.  I whittled down the civicrm developer module, that's where that particular function name comes from.
Answers.UserDisplayName: Peter_
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-14T20:15:12.777Z
Answers.Text: You need to create a new drupal module to contain the customization.  then the routine name would drop in place of the "hook".  It's actually quite easy but you should probably create a new question here for it.
Answers.UserDisplayName: DaveD
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-14T20:42:20.650Z
Answers.Text: Ahh, I see. Function names must begin with the module file name.
Answers.UserDisplayName: Peter_
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-14T03:27:56.437Z
Answers.Text: @daved-backoffice-thinking, for some unknown reason, this code is getting triggered on my https://example.org/user/register  url all of a sudden.  It was working great on the contribution page but now users are redirected to the url in this redirect_path variable when they attempt to register for a drupal account.  I've changed that variable and indeed it's this module that's responsible.  Any reason you can think of that would cause this behavior?  Thanks much.
Answers.UserDisplayName: Peter_
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-14T14:23:17.153Z
Answers.Text: @Peter_, do you have any customizations on the register page?  The hook is a CiviCRM hook, so really should only get called by CiviCRM. I can't imagine why it would execute otherwise, and even if it did the `if` statement should prevent it.  Bizarre.
  
  You said this behavior just recently started. Are there any other changes made to your system recently?  Perhaps they are causing the unintended redirect?
  
  It also might be something funky in the cache.  Clear your Drupal (and CiviCRM) caches and see if the issue clears up.
Answers.UserDisplayName: DaveD
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-17T00:20:48.467Z
Answers.Text: It's strange for sure.  I don't have any customizations to the register page.  I cleared the caches first thing....no effect.   If you were going to add a debug message what would be helpful?
Answers.UserDisplayName: Peter_
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-19T04:05:57.627Z
Answers.Text: I realized what happened. In the if statement, I added in some pipes so I could have more than one private contribution page.  But I forgot to parenthesize the form id section.  I imagine that the register page is drupal form id 2.  :P   Thanks
Answers.UserDisplayName: Peter_
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-12T18:21:38.773Z
Answers.LastActivityDate: 2015-08-13T21:45:50.020Z
Answers.LastEditDate: 2015-08-13T21:45:50.020Z
Answers.UserDisplayName: DaveD
Body: <p>We want to restrict our member signup page ( a contribution page ) to people who have registered to our Drupal site.  Also, we'd want to have public contribution pages not associated with membership be accessible without login.  </p>
  
  <p>In Drupal, I could make the permissions for "CiviContribute: make online contributions" be not accessible for unauthenticated users, but then I wouldn't be able to have the public contribution pages accessible.</p>
  
  <p>Is there such thing as a private contribution page?  Or is there some other way of achieving our goal that I don't know about?    </p>
  
  <p>Thanks!</p>
  
Tags: <civicontribute><drupal>
Title: Are private contribution pages a thing?
ThreadText: # Are private contribution pages a thing?
  
  (Asked by: username_0 on 2015-08-11)
  
  We want to restrict our member signup page ( a contribution page ) to people who have registered to our Drupal site. Also, we'd want to have public contribution pages not associated with membership be accessible without login.
  
  In Drupal, I could make the permissions for "CiviContribute: make online contributions" be not accessible for unauthenticated users, but then I wouldn't be able to have the public contribution pages accessible.
  
  Is there such thing as a private contribution page? Or is there some other way of achieving our goal that I don't know about?
  
  Thanks!
  
  **Tags:** civicontribute, drupal
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_5 on 2015-08-12. Score: 7 | Accepted answer
  
  A short bit of custom code could take care of this (using the hook_civicrm_preProcess hook I think).  It would need to check if the current page is your "sign-up" contribution page, and if it is, make sure that the user is currently logged in.  If not, it would redirect to wherever you need.
  Not positive this code is perfect, but it should get you pretty darn close...
  function hook_civicrm_preProcess($formName, &$form) {
  
    $form_id = 7;   // set this to the specific form_id you wish to limit access to
    $redirect_path = 'home';  // set this to the url to redirect to if not logged in
  
    if ($formName == "CRM_Contribute_Form_Contribution_Main" && $form->_id == $form_id) {
      if (!user_is_logged_in()) {
        drupal_goto($redirect_path);
      }
    }
  
  }
  
  > **Comments:**
  > **username_0**: I think this is the most promising path, but I can't find any example code to work from.  I've installed the civicrm development module and can see this helper info displayed on all contribution pages: hook_civicrm_preProcess called: formName is CRM_Contribute_Form_Contribution_Main.  But I can see nothing distinct about my specific contribution page I want to make private other than the url which has the contribution id.   If the hook just checks for the form name, I'm still in the same boat. All contribution pages are blocked.  I need to be checking for an id to be distinct, right?  
  > **username_5**: @username_0, I have added a code snippet to my original response.  
  > **username_0**: Thanks much, I found this is code working, except that for reasons I don't understand, I'm limited to using the function name civicrm_developer_civicrm_preProcess. Then name hook_civicrm_preProcess won't work, or any others I try.  I whittled down the civicrm developer module, that's where that particular function name comes from.  
  > **username_5**: You need to create a new drupal module to contain the customization.  then the routine name would drop in place of the "hook".  It's actually quite easy but you should probably create a new question here for it.  
  > **username_0**: Ahh, I see. Function names must begin with the module file name.  
  > **username_0**: @daved-backoffice-thinking, for some unknown reason, this code is getting triggered on my https://example.org/user/register  url all of a sudden.  It was working great on the contribution page but now users are redirected to the url in this redirect_path variable when they attempt to register for a drupal account.  I've changed that variable and indeed it's this module that's responsible.  Any reason you can think of that would cause this behavior?  Thanks much.  
  > **username_5**: @username_0, do you have any customizations on the register page?  The hook is a CiviCRM hook, so really should only get called by CiviCRM. I can't imagine why it would execute otherwise, and even if it did the `if` statement should prevent it.  Bizarre.  You said this behavior just recently started. Are there any other changes made to your system recently?  Perhaps they are causing the unintended redirect?  It also might be something funky in the cache.  Clear your Drupal (and CiviCRM) caches and see if the issue clears up.  
  > **username_0**: It's strange for sure.  I don't have any customizations to the register page.  I cleared the caches first thing....no effect.   If you were going to add a debug message what would be helpful?  
  > **username_0**: I realized what happened. In the if statement, I added in some pipes so I could have more than one private contribution page.  But I forgot to parenthesize the form id section.  I imagine that the register page is drupal form id 2.  :P   Thanks  
  
  ---
  
  ### Answer by username_1 on 2015-08-19. Score: 6
  
  I've got a custom extension that's designed to designate specific contribution pages as 'admin only', here: <https://github.com/adixon/ca.civicrm.contributextra>
  
  The actual permissions to access 'admin only' contribution pages is just set to being logged in (I just wanted to hide them from anonymous access), so it'll do what you want. It'll also generate an admin link from contact summary pages' contribution tab to the designated admin-only contribution pages.
  
  > **Comments:**
  > **username_0**: Thanks, I'm experimenting with your extension.  I have one problem with it though.   When I set a contribution page to admin-only, it's only viewable to drupal site admins.  I'm not certain how to set it to authenticated users.  Is there a config within civi or should I look at the code?  I did modify the redirect to suit my needs.  Thank you  
  > **username_1**: You don't need to do anything other than mark it as admin-only - the current implementation only limits access to non-anonymous users, i.e. any authenticated user will have access to it. The relevant code is line 176, here: https://github.com/adixon/ca.civicrm.contributextra/blob/master/contributextra.php  
  
  ---
  
  ### Answer by username_2 on 2015-08-12. Score: 1
  
  Please [edit](https://civicrm.stackexchange.com/posts/4637/edit) your question to expand on exactly why your goal is "to restrict our member signup page ... to people who have registered to our Drupal site"?
  
  Is there something "extra special" about the people who have registered on your Drupal site such that they have to be pre-approved before they can register?
  
  Is there any reason why people who haven't registered should not be able to **view** the membership page?
  
  You may be able to accomplish what you need without resorting to code by making "Drupal account creation" compulsory on your signup page (done in "advanced settings" on the profile settings page) and requiring administrator approval for creating a Drupal user account.(Select "Visitors, but administrator approval is required" for **Registration and cancellation** on yoursite/admin/config/people/accounts.)
  
  That way you could vet the "applicants" for membership before their Drupal account is created and refund the membership fees for those who are not acceptable for what ever reason.
  
  > **Comments:**
  > **username_0**: HI username_2, to me it doesn't seem relevant to the question, which I thought was clear.   But if it helps, let me give you some background, which I do not think belongs in the question itself.  We are a maker space. We ask prospective members to come and meet us in person before we allow them to access the signup page. Since, crazy people and potentially dangerous tools don't go together so well.  :-) To answer your question why shouldn't unauthenticated users be able to view the membership page, if they can view it, that means they can use it.  
  > **username_0**: Sadly, making "Drupal Account creation" compulsory on the signup page doesn't accomplish the goal, because the anonymous user is already on the sign up page, the thing we don't want to have happen.  
  > **username_2**: I realise that, which is why I asked for more information. I would argue that your ultimate goal is not "stop anonymous users from seeing our membership form" but rather "stop unsuitable people from having access to our maker space". You are new to this site, perhaps new to CiviCRM and were possibly seeking a non-code solution. A Drupal/Civicrm site is quite complex and there may have been ways to accomplish your ultimate goal that you had not thought of. Knowing what your ultimate goal was could have made a different approach, such as the one I outlined, a viable alternative.  
  
  ---
  
  ### Answer by username_3 on 2015-08-12. Score: -1
  
  I might have misunderstood your question, but I think you are looking for something like the [node access](https://www.drupal.org/project/nodeaccess) module, which it will allow you to restrict access to a page (ie membership page) based on user roles, ie authenticated users.
  
  I'm not a Drupal user so please correct me if there are better solutions.
  
  > **Comments:**
  > **username_4**: Civi pages aren't 'drupal nodes' so doubt it can be this simple, especially as civi throws ? in to paths which some drupal path based options don't appreciate'  
  > **username_1**: Drupal considers civicrm pages as non-node callbacks, so none of the node-specific permissions are applicable. Drupal gives primary permissions responsibility to the module that defines the callback (i.e. they are in the same table/code), and so the civicrm drupal module code already has allowed everyone to access any civicrm callback, and then has it's own permissions system (in the xml files). If you really wanted to use a custom Drupal module for this problem, you could use the menu hook and add a menu entry for the contribution pages and give it a custom permissions callback.  
  
  ---
  
  