Repository: OCHA-DAP/hdx-ckan

Issue:
My Datasets: enable the delete link on each dataset
We originally left this undone because it was going to be a bit more complicated than the edit button and we were pressed for time.  However, it seems to be causing some confusion for users (skype chat with D.C. and J.T.) who think it means they don't have permission to delete.

If it's going to require more than a day's effort to enable, the fall back would be to remove the delete link, leaving only the edit link.



Discussion:
Delete button is working, but redirects to a strange place (see screen cap).  

It would be best if it reloaded /dashboard/datasets

![image](https://cloud.githubusercontent.com/assets/1654485/5394101/571d8bbe-8139-11e4-9aae-6f3e92785f19.png)


Resolving patch:
diff --git a/ckanext-hdx_package/ckanext/hdx_package/controllers/dataset_controller.py b/ckanext-hdx_package/ckanext/hdx_package/controllers/dataset_controller.py
--- a/ckanext-hdx_package/ckanext/hdx_package/controllers/dataset_controller.py
+++ b/ckanext-hdx_package/ckanext/hdx_package/controllers/dataset_controller.py
@@ -728,3 +728,29 @@ def resource_delete(self, id, resource_id):
         except NotFound:
             abort(404, _('Resource not found'))
         return render('package/confirm_delete_resource.html')
+
+
+    def delete(self, id):
+
+        if 'cancel' in request.params:
+            h.redirect_to(controller='package', action='edit', id=id)
+
+        context = {'model': model, 'session': model.Session,
+                   'user': c.user or c.author, 'auth_user_obj': c.userobj}
+
+        try:
+            check_access('package_delete', context, {'id': id})
+        except NotAuthorized:
+            abort(401, _('Unauthorized to delete package %s') % '')
+
+        try:
+            if request.method == 'POST':
+                get_action('package_delete')(context, {'id': id})
+                h.flash_notice(_('Dataset has been deleted.'))
+                h.redirect_to(controller='user', action='dashboard')
+            c.pkg_dict = get_action('package_show')(context, {'id': id})
+        except NotAuthorized:
+            abort(401, _('Unauthorized to delete package %s') % '')
+        except NotFound:
+            abort(404, _('Dataset not found'))
+        return render('package/confirm_delete.html')
diff --git a/ckanext-hdx_users/ckanext/hdx_users/controllers/login_controller.py b/ckanext-hdx_users/ckanext/hdx_users/controllers/login_controller.py
--- a/ckanext-hdx_users/ckanext/hdx_users/controllers/login_controller.py
+++ b/ckanext-hdx_users/ckanext/hdx_users/controllers/login_controller.py
@@ -4,15 +4,57 @@
 import ckan.controllers.user as ckan_user
 import ckan.lib.helpers as h
 import ckan.lib.base as base
+import ckan.lib.mailer as mailer
 from ckan.common import _, c, g, request
 import ckan.logic as logic
 from pylons import config
+import ckan.model as model
 
-get_action = logic.get_action
+render = base.render
 
+get_action = logic.get_action
+NotAuthorized = logic.NotAuthorized
+NotFound = logic.NotFound
+check_access = logic.check_access
 
 class LoginController(ckan_user.UserController):
 
+    def request_reset(self):
+        context = {'model': model, 'session': model.Session, 'user': c.user,
+                   'auth_user_obj': c.userobj}
+        data_dict = {'id': request.params.get('user')}
+        try:
+            check_access('request_reset', context)
+        except NotAuthorized:
+            abort(401, _('Unauthorized to request reset password.'))
+
+        if request.method == 'POST':
+            id = request.params.get('user')
+
+            context = {'model': model,
+                       'user': c.user}
+
+            data_dict = {'id': id}
+            user_obj = None
+            try:
+                user_dict = get_action('user_show')(context, data_dict)
+                user_obj = context['user_obj']
+            except NotFound:
+                h.flash_error(_('No such user: %s') % id)
+
+            print user_obj
+            if user_obj:
+                try:
+                    mailer.send_reset_link(user_obj)
+                    h.flash_success(_('Please check your inbox for '
+                                    'a reset code.'))
+                    h.redirect_to(controller='user',
+                              action='login', came_from=None)
+                except mailer.MailerException, e:
+                    h.flash_error(_('Could not send reset link: %s') %
+                                  unicode(e))
+        return render('user/request_reset.html')
+
     def logged_in(self):
         # redirect if needed
         came_from = request.params.get('came_from', '')
@@ -58,3 +100,4 @@ def contribute(self, error=None):
         self.login(error)
         vars = {'contribute': True}
         return base.render('user/login.html', extra_vars=vars)
+
diff --git a/ckanext-hdx_users/ckanext/hdx_users/plugin.py b/ckanext-hdx_users/ckanext/hdx_users/plugin.py
--- a/ckanext-hdx_users/ckanext/hdx_users/plugin.py
+++ b/ckanext-hdx_users/ckanext/hdx_users/plugin.py
@@ -29,6 +29,7 @@ def before_map(self, map):
                     controller='ckanext.hdx_users.controllers.registration_controller:RequestController',
                     action='register')
         map.connect('/user/logged_in', controller='ckanext.hdx_users.controllers.login_controller:LoginController', action='logged_in')
+        map.connect('/user/reset', controller='ckanext.hdx_users.controllers.login_controller:LoginController', action='request_reset')
         map.connect('/contribute', controller='ckanext.hdx_users.controllers.login_controller:LoginController', action='contribute')
 
         return map


Test patch: