Terrrydactyl has uploaded a new change for review. https://gerrit.wikimedia.org/r/119343
Change subject: WIP Removing cohorts from database ...................................................................... WIP Removing cohorts from database Change-Id: I431cad933d5b888f10fe5533b75e7b1776649ab3 --- M tests/test_controllers/test_cohorts.py M wikimetrics/controllers/cohorts.py M wikimetrics/templates/cohorts.html 3 files changed, 34 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/analytics/wikimetrics refs/changes/43/119343/1 diff --git a/tests/test_controllers/test_cohorts.py b/tests/test_controllers/test_cohorts.py index 0396bd3..84b8893 100644 --- a/tests/test_controllers/test_cohorts.py +++ b/tests/test_controllers/test_cohorts.py @@ -147,6 +147,10 @@ .filter(CohortUser.cohort_id == self.cohort.id) \ .first() assert_equal(cu, None) + cohort_database = self.session.query(Cohort) \ + .filter(Cohort.id == self.cohort.id) \ + .first + assert_equal(cohort_database, None) def test_delete_unauthorized_cohort(self): self.session.query(CohortUser).delete() diff --git a/wikimetrics/controllers/cohorts.py b/wikimetrics/controllers/cohorts.py index ab139a0..7211802 100644 --- a/wikimetrics/controllers/cohorts.py +++ b/wikimetrics/controllers/cohorts.py @@ -233,14 +233,31 @@ """ session = db.get_session() try: - result = session.query(CohortUser) \ + role = session.query(CohortUser) \ .filter(CohortUser.cohort_id == cohort_id) \ .filter(CohortUser.user_id == current_user.id) \ - .delete() - session.commit() - if result > 0: - return json_redirect(url_for('cohorts_index')) - else: - return json_error('This Cohort can not be deleted') + .first() + if role and role.role == "OWNER": + delete_cohort_wiki_user = session.query(CohortWikiUser) \ + .filter(CohortWikiUser.cohort_id == cohort_id) \ + .delete() + delete_cohort_user = session.query(CohortUser) \ + .filter(CohortUser.cohort_id == cohort_id) \ + .filter(CohortUser.user_id == current_user.id) \ + .filter(CohortUser.role == 'OWNER') \ + .delete() + delete_wiki_user = session.query(WikiUser) \ + .filter(WikiUser.validating_cohort == cohort_id) \ + .delete() + delete_cohort = session.query(Cohort) \ + .filter(Cohort.id == cohort_id) \ + .delete() + session.commit() + if delete_cohort_wiki_user > 0 and delete_cohort_user > 0 and delete_wiki_user > 0 and delete_cohort > 0: + return json_redirect(url_for('cohorts_index')) + else: + return json_error('This Cohort can not be deleted') + elif role: # user wants to delete from list but not from database + pass finally: session.close() diff --git a/wikimetrics/templates/cohorts.html b/wikimetrics/templates/cohorts.html index acf4834..5e74871 100644 --- a/wikimetrics/templates/cohorts.html +++ b/wikimetrics/templates/cohorts.html @@ -24,6 +24,9 @@ <div data-bind="if: validated() && valid_count() > 0"> <a data-bind="attr:{href:'{{url_for('reports_request')}}#'+id}" class="btn btn-primary">Create Report</a> + <a data-bind="click: $root.deleteCohort" + class="btn btn-danger" + title="remove this cohort from your list?">Remove Cohort</a> </div> <div data-bind="if: validated_count() === total_count() && !validated()"> <hr/> @@ -44,12 +47,12 @@ <div data-bind="if: valid_count() < total_count()"> <hr/> <p> - <a data-bind="click: $root.deleteCohort" - class="btn btn-danger" - title="remove this cohort from your list">Remove Cohort</a> <a data-bind="click: $root.validateWikiusers" class="btn btn-primary" title="cancel and restart validation for this cohort">Validate Again</a> + <a data-bind="click: $root.deleteCohort" + class="btn btn-danger" + title="remove this cohort from your list?">Remove Cohort</a> </p> </div> </div> -- To view, visit https://gerrit.wikimedia.org/r/119343 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I431cad933d5b888f10fe5533b75e7b1776649ab3 Gerrit-PatchSet: 1 Gerrit-Project: analytics/wikimetrics Gerrit-Branch: master Gerrit-Owner: Terrrydactyl <tcho...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits