Repository: OCHA-DAP/hdx-ckan

Issue:
New Organization flow: Request membership&new org
According to new workflow and wireframes from https://drive.google.com/?tab=co&authuser=0#folders/0B4J8rDnUw80gdWUxRUtpeXg1TGs. The task here would be:
1. Using the controller defined in #550 create the page request_membership_or_org.html as you can see here: https://docs.google.com/file/d/0B4J8rDnUw80gcGpLSDVqQ2RraXc/edit. Create page (snippet) for requesting membership or requesting a new org.
   - when click on requesting membership -> user will be redirected to the page with the organizations list (/organization)
   - when click on "request a new org" user will be redirected to a page created in #549. See wireframe ( https://docs.google.com/file/d/0B4J8rDnUw80geUdyVmZKM1dpaU0/edit )
2. After the user login  he should go directly to the My Organization tab (not the current behaviour)
3. Remove the new user notice ( see issue description )
4. In case the user is not member of any organization (there are no organizations in My Organization tab) -> the  snippet created at task 1 will be showed in the "My Organization" tab. In this case the upper part with "Thanks for contributing...." will not appear!



Discussion:

Resolving patch:
diff --git a/ckanext-metadata_fields/ckanext/metadata_fields/dataset_controller.py b/ckanext-metadata_fields/ckanext/metadata_fields/dataset_controller.py
--- a/ckanext-metadata_fields/ckanext/metadata_fields/dataset_controller.py
+++ b/ckanext-metadata_fields/ckanext/metadata_fields/dataset_controller.py
@@ -3,6 +3,8 @@
 import datetime
 import cgi
 
+import helpers
+
 from pylons import config
 from genshi.template import MarkupTemplate
 from genshi.template.text import NewTextTemplate
@@ -164,6 +166,9 @@ def _save_new(self, context, package_type=None):
 			return self.new(data_dict, errors, error_summary)
 
 	def new(self, data=None, errors=None, error_summary=None):
+		#Is the user a member of any orgs? If not make them join one first
+		if helpers.hdx_user_org_num(c.userobj.id) == 0:
+			return render('organization/request_mem_or_org.html')
 		package_type = self._guess_package_type(True)
 
 		context = {'model': model, 'session': model.Session,
diff --git a/ckanext-metadata_fields/ckanext/metadata_fields/helpers.py b/ckanext-metadata_fields/ckanext/metadata_fields/helpers.py
new file mode 100644
--- /dev/null
+++ b/ckanext-metadata_fields/ckanext/metadata_fields/helpers.py
@@ -0,0 +1,30 @@
+import ckan.lib.helpers as h
+from ckan.common import (
+     c, request
+)
+import sqlalchemy
+import ckan.model as model
+import ckan.lib.base as base
+import ckan.logic as logic
+import datetime
+import json
+import logging
+import ckan.plugins.toolkit as tk
+import re
+
+import ckanext.hdx_theme.counting_actions as counting
+
+from webhelpers.html import escape, HTML, literal, url_escape
+from ckan.common import _
+
+log = logging.getLogger(__name__)
+
+def hdx_user_org_num(user_id):
+    context = {'model': model, 'session': model.Session,
+                   'user': c.user or c.author}
+    try:
+        user    = tk.get_action('organization_list_for_user')(context,{'id':user_id})
+    except logic.NotAuthorized:
+            base.abort(401, _('Unauthorized to see organization member list'))    
+        
+    return len(user)
\ No newline at end of file


Test patch: