From 2cd93f1dedd8d6025284a38251dc6961f589ba9a Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Fri, 16 May 2014 01:42:44 -0400 Subject: [PATCH] Rough in UI for account cancelation; #54 Now that the three scripts involved in account cancelation have been moved to (tested) methods on Participant, we're ready to wire up the UI. This commit rebases the original work we did on the UI on top of the separate line of development we ended up pursuing for the Participant methods. --- bin/deactivate.py | 84 ---------------------------- bin/final-gift.py | 41 -------------- bin/untip.py | 19 ------- js/gittip/account.js | 10 ++++ js/gittip/cancel.js | 4 ++ scss/buttons-knobs.scss | 3 +- scss/layout.scss | 12 +++- www/%username/account/cancel.spt | 57 +++++++++++++++++++ www/%username/account/index.html.spt | 11 ++++ 9 files changed, 95 insertions(+), 146 deletions(-) delete mode 100644 bin/deactivate.py delete mode 100644 bin/final-gift.py delete mode 100644 bin/untip.py create mode 100644 js/gittip/cancel.js create mode 100644 www/%username/account/cancel.spt diff --git a/bin/deactivate.py b/bin/deactivate.py deleted file mode 100644 index fb1e5aea12..0000000000 --- a/bin/deactivate.py +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/env python -"""The final rename and clear step for canceling an account. - -If the account has a balance or is involved in active tips, -this script will report the problem and abort without making any update. - -If the first eight digits of the account's API key are not given or do not match, -this script will report the problem and abort without making any update. - -Usage: - - [gittip] $ heroku config -s -a gittip | foreman run -e /dev/stdin ./env/bin/python ./bin/deactivate.py "username" [first-eight-of-api-key] - -""" -from __future__ import print_function - -import sys - -from gittip import wireup -from gittip.models.participant import Participant - - -username = sys.argv[1] # will fail with KeyError if missing -if len(sys.argv) < 3: - first_eight = "unknown!" -else: - first_eight = sys.argv[2] - -db = wireup.db(wireup.env()) - - -# Ensure that balance and tips have been dealt with. -# ================================================== - -target = Participant.from_username(username) - -INCOMING = """ - SELECT count(*) - FROM current_tips - WHERE tippee = %s - AND amount > 0 -""" - -FIELDS = """ - SELECT username, username_lower, api_key, claimed_time - FROM participants - WHERE username = %s -""" - -incoming = db.one(INCOMING, (username,)) -fields = db.one(FIELDS, (username,)) - -print("Current balance ", target.balance) -print("Incoming tip count ", incoming) -print(fields) - -assert target.balance == 0 -assert incoming == 0 -if fields.api_key == None: - assert first_eight == "None" -else: - assert fields.api_key[0:8] == first_eight - - -# Archive the participant record. -# =============================== - -deactivated_name = "deactivated-" + username -print("Renaming " + username + " to " + deactivated_name) - -RENAME = """ - UPDATE participants - SET claimed_time = null - , session_token = null - , username = %s - , username_lower = %s - WHERE username = %s -""" - -print(RENAME % (deactivated_name, deactivated_name.lower(), username)) - -db.run(RENAME, (deactivated_name, deactivated_name.lower(), username)) - -print("All done.") diff --git a/bin/final-gift.py b/bin/final-gift.py deleted file mode 100644 index c73af66397..0000000000 --- a/bin/final-gift.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python -"""Distribute a balance as a final gift. This addresses part of #54. - -Usage: - - [gittip] $ heroku config -s -a gittip | foreman run -e /dev/stdin ./env/bin/python ./bin/final-gift.py "username" [first-eight-of-api-key] - -""" -from __future__ import print_function - -import sys - -from gittip import wireup -from gittip.models.participant import Participant - -db = wireup.db(wireup.env()) - -username = sys.argv[1] # will fail with KeyError if missing -tipper = Participant.from_username(username) -if len(sys.argv) < 3: - first_eight = "unknown!" -else: - first_eight = sys.argv[2] - -# Ensure user is legit -FIELDS = """ - SELECT username, username_lower, api_key, claimed_time - FROM participants - WHERE username = %s -""" - -fields = db.one(FIELDS, (username,)) -print(fields) - -if fields.api_key == None: - assert first_eight == "None" -else: - assert fields.api_key[0:8] == first_eight - -print("Distributing {} from {}.".format(tipper.balance, tipper.username)) -tipper.distribute_balance_as_final_gift() diff --git a/bin/untip.py b/bin/untip.py deleted file mode 100644 index 17bf953043..0000000000 --- a/bin/untip.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python -"""Zero out tips to a given user. This is a workaround for #1469. - -Usage: - - [gittip] $ heroku config -s -a gittip | foreman run -e /dev/stdin ./env/bin/python ./scripts/untip.py "username" - -""" -from __future__ import print_function - -import sys - -from gittip import wireup -from gittip.models.participant import Participant - - -tippee = sys.argv[1] # will fail with KeyError if missing -db = wireup.db(wireup.env()) -Participant.from_username(tippee).clear_tips_receiving() diff --git a/js/gittip/account.js b/js/gittip/account.js index 52da2336a8..2fffa5572d 100644 --- a/js/gittip/account.js +++ b/js/gittip/account.js @@ -163,4 +163,14 @@ Gittip.account.init = function() { return false; }); + + // Wire up cancel knob. + // ==================== + + $('.cancel form').submit(function(e) { + e.stopPropagation(); + e.preventDefault(); + if (confirm("Really cancel account!? This can't be undone!")) + window.location.href = './cancel'; + }); }; diff --git a/js/gittip/cancel.js b/js/gittip/cancel.js new file mode 100644 index 0000000000..52c14c619a --- /dev/null +++ b/js/gittip/cancel.js @@ -0,0 +1,4 @@ +Gittip.cancel = {}; + +Gittip.cancel.init = function() { +} diff --git a/scss/buttons-knobs.scss b/scss/buttons-knobs.scss index d7a9a8283c..4b3fe7262d 100644 --- a/scss/buttons-knobs.scss +++ b/scss/buttons-knobs.scss @@ -48,7 +48,8 @@ button.selected:hover, button.selected.drag, } button.join-leave[data-is-member="true"], -.button.join-leave[data-is-member="true"] { +.button.join-leave[data-is-member="true"], +button.cancel-account { font-weight: normal; background: none; color: $red; diff --git a/scss/layout.scss b/scss/layout.scss index c76e9571c5..d6f3450df4 100644 --- a/scss/layout.scss +++ b/scss/layout.scss @@ -420,7 +420,14 @@ padding: 0; text-transform: uppercase; } - input { + input[type="radio"] + label { + display: inline; + margin: 0; + } + input[type="radio"]:disabled + label { + color: #888; + } + input:not([type]), input[type="text"] { font: normal 11pt/14pt $Helvetica; width: 292px; margin: 0; @@ -431,6 +438,9 @@ input.disabled { color: $light-brown; } + input[type="radio"] { + vertical-align: middle; + } .half input { width: 137px; diff --git a/www/%username/account/cancel.spt b/www/%username/account/cancel.spt new file mode 100644 index 0000000000..53fd49a307 --- /dev/null +++ b/www/%username/account/cancel.spt @@ -0,0 +1,57 @@ +from gittip.utils import get_participant +[---] +participant = get_participant(request, restrict=True) +hero = "Cancel Account" +title = participant.username # used in the title tag +username = participant.username # used in footer shared with on/$platform/ + # pages + +can_upstream = participant.get_dollars_receiving() > 0 +can_downstream = participant.get_dollars_giving() > 0 + +if POST: + final_disbursement_option = request.body['final_disbursement_option'] + participant.cancel(final_disbursement_option) + request.redirect('/') +[---] text/html +{% extends "templates/base.html" %} + +{% block heading %} +

Cancel Account

+{% endblock %} + +{% block box %} +
+
+
+ {% if participant.balance > 0 %} +

You have a balance of ${{ participant.balance }}. + What should we do with it?

+ +
    +
  • +
  • +
  • +
  • +
  • +
  • +
+ {% endif %} +

Here's what we'll do when you cancel your account:

+
    +
  • Turn off all tips you are currently receiving.
  • +
  • Zero out all tips you are currently receiving.
  • +
  • Make it so there are no more you are currently receiving.
  • +
+
+ +
+
+{% endblock %} diff --git a/www/%username/account/index.html.spt b/www/%username/account/index.html.spt index 58a470e428..4d0bebce0b 100644 --- a/www/%username/account/index.html.spt +++ b/www/%username/account/index.html.spt @@ -184,6 +184,17 @@ locked = False + + +
+

Cancel

+
+
+ +
+
+
+ {% endblock %}