From 70a323e086b5b32354298e049f34f8b2130759d7 Mon Sep 17 00:00:00 2001 From: Changaco <changaco@changaco.net> Date: Wed, 4 Dec 2013 17:51:53 +0100 Subject: [PATCH 01/11] implement option to hide total receiving from others --- gittip/models/participant.py | 4 ++-- gittip/testing/__init__.py | 4 ++++ gittip/utils/__init__.py | 12 +++++------ gittip/utils/fake_data.py | 6 ++++-- js/gittip/profile.js | 25 +++++++++++++++++++-- schema.sql | 9 ++++++++ templates/participant.html | 31 +++++++++++++++----------- templates/profile-edit.html | 9 ++++++-- tests/test_anonymous_json.py | 37 +++++++++++++++++++++----------- tests/test_pages.py | 13 ++++++++++- tests/test_public_json.py | 15 +++++++++++-- www/%username/anonymous.json.spt | 20 +++++++++++------ www/%username/public.json.spt | 18 +++++++++++++--- www/about/privacy/index.html.spt | 2 +- www/for/%slug/index.html.spt | 22 ++++++++++++++----- www/index.html.spt | 14 +++++++++++- 16 files changed, 182 insertions(+), 59 deletions(-) diff --git a/gittip/models/participant.py b/gittip/models/participant.py index 4677c087ca..e01a7e825b 100644 --- a/gittip/models/participant.py +++ b/gittip/models/participant.py @@ -674,9 +674,9 @@ def get_og_title(self): out = self.username receiving = self.get_dollars_receiving() giving = self.get_dollars_giving() - if (giving > receiving) and not self.anonymous: + if (giving > receiving) and not self.anonymous_giving: out += " gives $%.2f/wk" % giving - elif receiving > 0: + elif receiving > 0 and not self.anonymous_receiving: out += " receives $%.2f/wk" % receiving else: out += " is" diff --git a/gittip/testing/__init__.py b/gittip/testing/__init__.py index 099aa3d929..779f70b126 100644 --- a/gittip/testing/__init__.py +++ b/gittip/testing/__init__.py @@ -152,8 +152,12 @@ def make_participant(self, username, **kw): participant = Participant.with_random_username() participant.change_username(username) + return self.update_participant(participant, **kw) + + def update_participant(self, participant, **kw): if 'elsewhere' in kw or 'claimed_time' in kw: + username = participant.username platform = kw.pop('elsewhere', 'github') user_info = dict(login=username) self.seq += 1 diff --git a/gittip/utils/__init__.py b/gittip/utils/__init__.py index cfddc565f0..1ea281a918 100644 --- a/gittip/utils/__init__.py +++ b/gittip/utils/__init__.py @@ -365,8 +365,8 @@ def update_homepage_queries_once(db): cursor.execute("DELETE FROM homepage_top_givers") cursor.execute(""" - INSERT INTO homepage_top_givers - SELECT tipper AS username, anonymous, sum(amount) AS amount + INSERT INTO homepage_top_givers (username, anonymous, amount) + SELECT tipper, anonymous_giving, sum(amount) AS amount FROM ( SELECT DISTINCT ON (tipper, tippee) amount , tipper @@ -382,7 +382,7 @@ def update_homepage_queries_once(db): ) AS foo JOIN participants p ON p.username = tipper WHERE is_suspicious IS NOT true - GROUP BY tipper, anonymous + GROUP BY tipper, anonymous_giving ORDER BY amount DESC; """.strip()) @@ -408,8 +408,8 @@ def update_homepage_queries_once(db): cursor.execute("DELETE FROM homepage_top_receivers") cursor.execute(""" - INSERT INTO homepage_top_receivers - SELECT tippee AS username, claimed_time, sum(amount) AS amount + INSERT INTO homepage_top_receivers (username, anonymous, amount, claimed_time) + SELECT tippee, anonymous_receiving, sum(amount) AS amount, claimed_time FROM ( SELECT DISTINCT ON (tipper, tippee) amount , tippee @@ -424,7 +424,7 @@ def update_homepage_queries_once(db): ) AS foo JOIN participants p ON p.username = tippee WHERE is_suspicious IS NOT true - GROUP BY tippee, claimed_time + GROUP BY tippee, anonymous_receiving, claimed_time ORDER BY amount DESC; """.strip()) diff --git a/gittip/utils/fake_data.py b/gittip/utils/fake_data.py index 7fd8e499d1..6e135df312 100644 --- a/gittip/utils/fake_data.py +++ b/gittip/utils/fake_data.py @@ -57,7 +57,8 @@ def fake_sentence(start=1, stop=100): return faker.sentence(random.randrange(start,stop)) -def fake_participant(db, number="singular", is_admin=False, anonymous=False): +def fake_participant(db, number="singular", is_admin=False, + anonymous_giving=False, anonymous_receiving=False): """Create a fake User. """ username = faker.first_name() + fake_text_id(3) @@ -70,7 +71,8 @@ def fake_participant(db, number="singular", is_admin=False, anonymous=False): , ctime=faker.date_time_this_year() , is_admin=is_admin , balance=fake_balance() - , anonymous=anonymous + , anonymous_giving=anonymous_giving + , anonymous_receiving=anonymous_receiving , goal=fake_balance() , balanced_account_uri=faker.uri() , last_ach_result='' diff --git a/js/gittip/profile.js b/js/gittip/profile.js index a46ba6bfa2..da95f89f31 100644 --- a/js/gittip/profile.js +++ b/js/gittip/profile.js @@ -215,13 +215,34 @@ Gittip.profile.init = function() { // Wire up aggregate giving knob. // ============================== - $('.anonymous input').click(function() { + $('.anonymous-giving input').click(function() { jQuery.ajax( { url: 'anonymous.json' , type: 'POST' + , data: {toggle: 'giving'} , dataType: 'json' , success: function(data) { - $('.anonymous input').attr('checked', data.anonymous); + $('.anonymous-giving input').attr('checked', data.giving); + } + , error: function() { + alert("Failed to change your anonymity preference. Please try again."); + } + } + ); + }); + + + // Wire up aggregate receiving knob. + // ============================== + + $('.anonymous-receiving input').click(function() { + jQuery.ajax( + { url: 'anonymous.json' + , type: 'POST' + , data: {toggle: 'receiving'} + , dataType: 'json' + , success: function(data) { + $('.anonymous-receiving input').attr('checked', data.receiving); } , error: function() { alert("Failed to change your anonymity preference. Please try again."); diff --git a/schema.sql b/schema.sql index eff4b9158e..652f6bd667 100644 --- a/schema.sql +++ b/schema.sql @@ -949,3 +949,12 @@ ALTER TABLE homepage_top_givers ADD COLUMN twitter_pic text; -- https://github.com/gittip/www.gittip.com/pull/1610 DROP TABLE homepage_new_participants; + + +------------------------------------------------------------------------------- +-- https://github.com/gittip/www.gittip.com/issues/1683 + +ALTER TABLE participants RENAME COLUMN anonymous TO anonymous_giving; +ALTER TABLE participants DROP COLUMN anonymous; +ALTER TABLE participants ADD COLUMN anonymous_receiving bool NOT NULL DEFAULT FALSE; +ALTER TABLE homepage_top_receivers ADD COLUMN anonymous boolean; diff --git a/templates/participant.html b/templates/participant.html index b3812ab0e8..a923b3a31b 100644 --- a/templates/participant.html +++ b/templates/participant.html @@ -11,7 +11,10 @@ {% set giving = participant.get_dollars_giving() %} {% set receiving = participant.get_dollars_receiving() %} - {% if giving > receiving and not participant.anonymous %} + {% if participant.anonymous_giving and participant.anonymous_receiving %} + <h2 class="pad-sign">{{ participant.username }}</h2> + <div class="unit pad-sign">gives and receives anonymously</div> + {% elif g > r and not participant.anonymous_giving %} <h2 class="pad-sign">{{ participant.username }} gives</h2> <div class="number"> {% if user.participant == participant %} @@ -20,21 +23,25 @@ <h2 class="pad-sign">{{ participant.username }} gives</h2> ${{ giving }} {% endif %} </div> - <div class="unit pad-sign">per - week{% if receiving > 0 %}, and receives $<span class="total-receiving">{{ receiving }}</span>{% endif %} + <div class="unit pad-sign">per week + {% if r > 0 %}, and receives + {% if participant.anonymous_receiving %} + anonymously + {% else %} + ${{ receiving }} + {% endif %} + {% endif %} </div> {% elif receiving > 0 %} <h2 class="pad-sign">{{ participant.username }} receives</h2> <div class="number">$<span class="total-receiving">{{ receiving }}</span></div> - <div class="unit pad-sign">per - week{% if giving > 0 %}, and gives - {% if participant.anonymous %} - anonymously - {% elif user.participant == participant %} - $<span class="total-giving">{{ giving }}</span> - {% else %} - ${{ giving }} - {% endif %} + <div class="unit pad-sign">per week + {% if g > 0 %}, and gives + {% if participant.anonymous_giving %} + anonymously + {% else %} + ${{ giving }} + {% endif %} {% endif %} </div> {% else %} diff --git a/templates/profile-edit.html b/templates/profile-edit.html index fb1f521a82..85be01afe8 100644 --- a/templates/profile-edit.html +++ b/templates/profile-edit.html @@ -16,11 +16,16 @@ <h2 class="warning">Have you linked to your Gittip profile from other </form> <p> - <label tabindex="104" class="anonymous"> + <label tabindex="104" class="anonymous-giving"> <input type="checkbox" - {% if participant.anonymous %}checked="true"{% endif %} /> + {% if participant.anonymous_giving %}checked="true"{% endif %} /> Hide total giving from others. </label> + <label tabindex="105" class="anonymous-receiving"> + <input type="checkbox" + {% if participant.anonymous_receiving %}checked="true"{% endif %} /> + Hide total receiving from others. + </label> </p> diff --git a/tests/test_anonymous_json.py b/tests/test_anonymous_json.py index f3eb2e7c5d..2cc986c80b 100644 --- a/tests/test_anonymous_json.py +++ b/tests/test_anonymous_json.py @@ -10,25 +10,36 @@ def setUp(self): Harness.setUp(self) self.make_participant('alice') - def hit_anonymous(self, method='GET', expected_code=200): - response = self.client.hit(method, "/alice/anonymous.json", auth_as='alice') + def hit_anonymous(self, method='GET', expected_code=200, **kw): + response = self.client.hit(method, "/alice/anonymous.json", auth_as='alice', **kw) if response.code != expected_code: print(response.body) return response - def test_participant_can_get_their_anonymity_setting(self): + def test_participant_can_get_their_anonymity_settings(self): response = self.hit_anonymous('GET') - actual = json.loads(response.body)['anonymous'] + actual = json.loads(response.body) + assert actual == {'giving': False, 'receiving': False} + + def test_participant_can_toggle_anonymous_giving(self): + response = self.hit_anonymous('POST', data={'toggle': 'giving'}) + actual = json.loads(response.body) + assert actual['giving'] is True + + def test_participant_can_toggle_anonymous_receiving(self): + response = self.hit_anonymous('POST', data={'toggle': 'receiving'}) + actual = json.loads(response.body) + assert actual['receiving'] is True + + def test_participant_can_toggle_anonymous_giving_back(self): + response = self.hit_anonymous('POST', data={'toggle': 'giving'}) + response = self.hit_anonymous('POST', data={'toggle': 'giving'}) + actual = json.loads(response.body)['giving'] assert actual is False - def test_participant_can_toggle_their_anonymity_setting(self): - response = self.hit_anonymous('POST') - actual = json.loads(response.body)['anonymous'] - assert actual is True - - def test_participant_can_toggle_their_anonymity_setting_back(self): - response = self.hit_anonymous('POST') - response = self.hit_anonymous('POST') - actual = json.loads(response.body)['anonymous'] + def test_participant_can_toggle_anonymous_receiving_back(self): + response = self.hit_anonymous('POST', data={'toggle': 'receiving'}) + response = self.hit_anonymous('POST', data={'toggle': 'receiving'}) + actual = json.loads(response.body)['receiving'] assert actual is False diff --git a/tests/test_pages.py b/tests/test_pages.py index a4b8e27e78..480d6bf817 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -15,7 +15,18 @@ def test_homepage(self): def test_homepage_with_anonymous_giver(self): TwitterAccount(self.db, "bob", {}).opt_in("bob") - alice = self.make_participant('alice', anonymous=True, last_bill_result='') + alice = self.make_participant('alice', anonymous_giving=True, last_bill_result='') + alice.set_tip_to('bob', 1) + update_homepage_queries_once(self.db) + + actual = self.client.GET('/').body + expected = "Anonymous" + assert expected in actual + + def test_homepage_with_anonymous_receiver(self): + bob, _ = TwitterAccount(self.db, "bob", {}).opt_in("bob") + self.update_participant(bob.participant, anonymous_receiving=True, last_bill_result='') + alice = self.make_participant('alice', last_bill_result='', claimed_time='now') alice.set_tip_to('bob', 1) update_homepage_queries_once(self.db) diff --git a/tests/test_public_json.py b/tests/test_public_json.py index 29a094bbf8..83e69e7ce6 100644 --- a/tests/test_public_json.py +++ b/tests/test_public_json.py @@ -46,14 +46,25 @@ def test_anonymous_gets_giving(self): def test_anonymous_gets_null_giving_if_user_anonymous(self): alice = self.make_participant( 'alice' , last_bill_result='' - , anonymous=True - ) + , anonymous_giving=True + ) self.make_participant('bob') alice.set_tip_to('bob', '1.00') data = json.loads(self.client.GET('/alice/public.json').body) assert data['giving'] == None + def test_anonymous_gets_null_receiving_if_user_anonymous(self): + alice = self.make_participant( 'alice' + , last_bill_result='' + , anonymous_receiving=True + ) + self.make_participant('bob') + alice.set_tip_to('bob', '1.00') + data = json.loads(self.client.GET('/alice/public.json').body) + + assert data['receiving'] == None + def test_anonymous_does_not_get_goal_if_user_regifts(self): self.make_participant('alice', last_bill_result='', goal=0) data = json.loads(self.client.GET('/alice/public.json').body) diff --git a/www/%username/anonymous.json.spt b/www/%username/anonymous.json.spt index aafd884605..b1666a6ce2 100644 --- a/www/%username/anonymous.json.spt +++ b/www/%username/anonymous.json.spt @@ -4,19 +4,25 @@ if user.ANON: raise Response(404) request.allow("GET", "POST") if POST: + field = body.get("toggle", "giving") + if field not in ["giving", "receiving"]: + raise Response(400) rec = website.db.one(""" UPDATE participants - SET anonymous=not anonymous + SET anonymous_{0}=not anonymous_{0} WHERE username=%s - RETURNING anonymous + RETURNING anonymous_{0} - """, (user.participant.username,)) + """.format(field), (user.participant.username,)) + assert rec is not None + response.body = {field: rec} else: rec = website.db.one(""" - SELECT anonymous FROM participants WHERE username=%s + SELECT anonymous_giving AS giving, anonymous_receiving AS receiving + FROM participants WHERE username=%s - """, (user.participant.username,)) -assert rec is not None -response.body = {"anonymous": rec} + """, (user.participant.username,), back_as=dict) + assert rec is not None + response.body = rec diff --git a/www/%username/public.json.spt b/www/%username/public.json.spt index f40e292d17..0ba6bff1d1 100644 --- a/www/%username/public.json.spt +++ b/www/%username/public.json.spt @@ -12,11 +12,9 @@ callback_pattern = re.compile(r'^[_A-Za-z0-9.]+$') [-----------------------------------------------------------------------------] participant = get_participant(request, restrict=False) -receiving = participant.get_dollars_receiving() output = { "id": participant.id , "username": participant.username - , "receiving": str(receiving) , "avatar": participant.get_img_src() , "number": participant.number } @@ -38,6 +36,20 @@ if participant.goal != 0: output["goal"] = goal +# Generate receiving key +# =================== +# Display values: +# +# null - user is receiving anonymously +# 3.00 - user receives this amount in tips + +if not participant.anonymous_receiving: + receiving = str(participant.get_dollars_receiving()) +else: + receiving = None +output["receiving"] = receiving + + # Generate giving key # =================== # Display values: @@ -45,7 +57,7 @@ if participant.goal != 0: # null - user is giving anonymously # 3.00 - user gives this amount in tips -if not participant.anonymous: +if not participant.anonymous_giving: giving = str(participant.get_dollars_giving()) else: giving = None diff --git a/www/about/privacy/index.html.spt b/www/about/privacy/index.html.spt index 33fb964ab6..ad1aae1911 100644 --- a/www/about/privacy/index.html.spt +++ b/www/about/privacy/index.html.spt @@ -92,7 +92,7 @@ we may use personal information to:</p> <p>Gittip makes reasonable efforts not to share your personal information with the recipients of your gifts, so that particular gifts are anonymous. We do publicly share aggregated information about your giving and receiving. You may -opt out of publicly sharing your aggregate giving.</p> +opt out of publicly sharing your aggregate giving and/or receiving.</p> <p>We also share your personal information with these third party vendors who work on our behalf:</p> diff --git a/www/for/%slug/index.html.spt b/www/for/%slug/index.html.spt index 4629d675d4..ef4bd2b82d 100644 --- a/www/for/%slug/index.html.spt +++ b/www/for/%slug/index.html.spt @@ -124,7 +124,7 @@ if community.nmembers >= website.NMEMBERS_THRESHOLD: givers = utter_hack(website.db, query_cache.all(""" -- top givers on community page - SELECT tipper AS username, anonymous, sum(amount) AS amount + SELECT tipper AS username, anonymous_giving, sum(amount) AS amount FROM ( SELECT DISTINCT ON (tipper, tippee) amount , tipper @@ -142,7 +142,7 @@ if community.nmembers >= website.NMEMBERS_THRESHOLD: ) AS foo JOIN participants p ON p.username = tipper WHERE is_suspicious IS NOT true - GROUP BY tipper, anonymous + GROUP BY tipper, anonymous_giving ORDER BY amount DESC LIMIT %s OFFSET %s @@ -155,7 +155,7 @@ if community.nmembers >= website.NMEMBERS_THRESHOLD: receivers = utter_hack(website.db, query_cache.all(""" -- top receivers on community page - SELECT tippee AS username, claimed_time, sum(amount) AS amount + SELECT tippee AS username, anonymous_receiving, claimed_time, sum(amount) AS amount FROM ( SELECT DISTINCT ON (tipper, tippee) amount , tippee @@ -172,7 +172,7 @@ if community.nmembers >= website.NMEMBERS_THRESHOLD: ) AS foo JOIN participants p ON p.username = tippee WHERE is_suspicious IS NOT true - GROUP BY tippee, claimed_time + GROUP BY tippee, claimed_time, anonymous_receiving ORDER BY amount DESC LIMIT %s OFFSET %s @@ -317,7 +317,18 @@ $(document).ready(function() { <ul class="group"> {% for i, receiver in enumerate(receivers, start=1) %} <li{% if i > LUXURY %} class="luxury"{% endif %}> - <a href="/{{ receiver.username }}/" class="mini-user"> + {% if receiver.anonymous and not user.ADMIN %} + <span class="mini-user"> + <span class="inner"> + <span class="avatar"> + </span> + <span class="money">${{ receiver.amount }}</span> + <span class="name">???</span> + </span> + </span> + {% else %} + <a href="/{{ receiver.username }}/" + class="mini-user{{ ' anonymous' if giver.anonymous else '' }}"> <span class="inner"> <span class="avatar" style="background-image: url('{{ receiver.get_img_src() }}')"> @@ -326,6 +337,7 @@ $(document).ready(function() { <span class="name">{{ receiver.username }}</span> </span> </a> + {% endif %} </li> {% endfor %} </ul> diff --git a/www/index.html.spt b/www/index.html.spt index 74801aed11..e31f8e789d 100644 --- a/www/index.html.spt +++ b/www/index.html.spt @@ -176,7 +176,18 @@ receivers = utter_hack(website.db, website.db.all(""" <ul class="group"> {% for i, receiver in enumerate(receivers, start=1) %} <li{% if i > LUXURY %} class="luxury"{% endif %}> - <a href="/{{ receiver.username }}/" class="mini-user"> + {% if receiver.anonymous and not user.ADMIN %} + <span class="mini-user"> + <span class="inner"> + <span class="avatar"> + </span> + <span class="money">${{ receiver.amount }}</span> + <span class="name">Anonymous</span> + </span> + </span> + {% else %} + <a href="/{{ receiver.username }}/" + class="mini-user{{ ' anonymous' if giver.anonymous else '' }}"> <span class="inner"> <span class="avatar" style="background-image: url('{{ _get_img_src(receiver) }}')"> @@ -185,6 +196,7 @@ receivers = utter_hack(website.db, website.db.all(""" <span class="name">{{ receiver.username }}</span> </span> </a> + {% endif %} </li> {% endfor %} </ul> From a8daabbea5b845fcde1e19b46ddaddd1a81cd97d Mon Sep 17 00:00:00 2001 From: Changaco <changaco@changaco.net> Date: Wed, 4 Dec 2013 19:37:22 +0100 Subject: [PATCH 02/11] add line break --- templates/profile-edit.html | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/profile-edit.html b/templates/profile-edit.html index 85be01afe8..3c5b7c0848 100644 --- a/templates/profile-edit.html +++ b/templates/profile-edit.html @@ -21,6 +21,7 @@ <h2 class="warning">Have you linked to your Gittip profile from other {% if participant.anonymous_giving %}checked="true"{% endif %} /> Hide total giving from others. </label> + <br /> <label tabindex="105" class="anonymous-receiving"> <input type="checkbox" {% if participant.anonymous_receiving %}checked="true"{% endif %} /> From 178a2049ecd5adc2a356bb573e29e74a7e80083a Mon Sep 17 00:00:00 2001 From: Changaco <changaco@changaco.net> Date: Fri, 6 Dec 2013 10:29:03 +0100 Subject: [PATCH 03/11] fix community pages --- www/for/%slug/index.html.spt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/for/%slug/index.html.spt b/www/for/%slug/index.html.spt index ef4bd2b82d..b55a37e7ca 100644 --- a/www/for/%slug/index.html.spt +++ b/www/for/%slug/index.html.spt @@ -124,7 +124,7 @@ if community.nmembers >= website.NMEMBERS_THRESHOLD: givers = utter_hack(website.db, query_cache.all(""" -- top givers on community page - SELECT tipper AS username, anonymous_giving, sum(amount) AS amount + SELECT tipper AS username, anonymous_giving AS anonymous, sum(amount) AS amount FROM ( SELECT DISTINCT ON (tipper, tippee) amount , tipper @@ -155,7 +155,7 @@ if community.nmembers >= website.NMEMBERS_THRESHOLD: receivers = utter_hack(website.db, query_cache.all(""" -- top receivers on community page - SELECT tippee AS username, anonymous_receiving, claimed_time, sum(amount) AS amount + SELECT tippee AS username, anonymous_receiving AS anonymous, claimed_time, sum(amount) AS amount FROM ( SELECT DISTINCT ON (tipper, tippee) amount , tippee From 1f44c829d651f5089a5b39d4319f8cd70b33517c Mon Sep 17 00:00:00 2001 From: Changaco <changaco@changaco.net> Date: Fri, 6 Dec 2013 10:29:32 +0100 Subject: [PATCH 04/11] replace "???" by "Anonymous" --- www/for/%slug/index.html.spt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/for/%slug/index.html.spt b/www/for/%slug/index.html.spt index b55a37e7ca..f716184f09 100644 --- a/www/for/%slug/index.html.spt +++ b/www/for/%slug/index.html.spt @@ -293,7 +293,7 @@ $(document).ready(function() { <span class="avatar"> </span> <span class="money">${{ giver.amount }}</span> - <span class="name">???</span> + <span class="name">Anonymous</span> </span> </span> {% else %} @@ -323,7 +323,7 @@ $(document).ready(function() { <span class="avatar"> </span> <span class="money">${{ receiver.amount }}</span> - <span class="name">???</span> + <span class="name">Anonymous</span> </span> </span> {% else %} From 7ac15414b7f567614d0b5951d3dc5f196e568f7c Mon Sep 17 00:00:00 2001 From: Changaco <changaco@changaco.net> Date: Fri, 6 Dec 2013 10:38:29 +0100 Subject: [PATCH 05/11] move SQL changes to branch.sql --- branch.sql | 7 +++++++ schema.sql | 9 --------- 2 files changed, 7 insertions(+), 9 deletions(-) create mode 100644 branch.sql diff --git a/branch.sql b/branch.sql new file mode 100644 index 0000000000..75749acf99 --- /dev/null +++ b/branch.sql @@ -0,0 +1,7 @@ +------------------------------------------------------------------------------- +-- https://github.com/gittip/www.gittip.com/issues/1683 + +ALTER TABLE participants RENAME COLUMN anonymous TO anonymous_giving; +ALTER TABLE participants DROP COLUMN anonymous; +ALTER TABLE participants ADD COLUMN anonymous_receiving bool NOT NULL DEFAULT FALSE; +ALTER TABLE homepage_top_receivers ADD COLUMN anonymous boolean; diff --git a/schema.sql b/schema.sql index 652f6bd667..eff4b9158e 100644 --- a/schema.sql +++ b/schema.sql @@ -949,12 +949,3 @@ ALTER TABLE homepage_top_givers ADD COLUMN twitter_pic text; -- https://github.com/gittip/www.gittip.com/pull/1610 DROP TABLE homepage_new_participants; - - -------------------------------------------------------------------------------- --- https://github.com/gittip/www.gittip.com/issues/1683 - -ALTER TABLE participants RENAME COLUMN anonymous TO anonymous_giving; -ALTER TABLE participants DROP COLUMN anonymous; -ALTER TABLE participants ADD COLUMN anonymous_receiving bool NOT NULL DEFAULT FALSE; -ALTER TABLE homepage_top_receivers ADD COLUMN anonymous boolean; From a4b0766c21dc35b5af4da0b913a6748cf0e8b4a4 Mon Sep 17 00:00:00 2001 From: Changaco <changaco@changaco.net> Date: Fri, 6 Dec 2013 19:49:41 +0100 Subject: [PATCH 06/11] fix receiving amount leak --- js/gittip/tips.js | 4 +-- templates/participant.html | 51 +++++++++++------------------ www/%username/giving/index.html.spt | 2 +- www/for/%slug/index.html.spt | 4 +-- www/for/index.html.spt | 4 +-- 5 files changed, 25 insertions(+), 40 deletions(-) diff --git a/js/gittip/tips.js b/js/gittip/tips.js index 877dbb02dd..4c49b6b0bf 100644 --- a/js/gittip/tips.js +++ b/js/gittip/tips.js @@ -85,11 +85,11 @@ Gittip.tips.init = function() { $myTip.change(); // update display - $('.total-giving').text(data.total_giving); + $('.my-total-giving').text('$'+data.total_giving); $('.total-receiving').text( // check and see if we are on our giving page or not new RegExp('/' + tippee + '/').test(window.location.href) ? - data.total_receiving_tippee : data.total_receiving); + '$'+data.total_receiving_tippee : '$'+data.total_receiving); // Increment an elsewhere receiver's "people ready to give" if(!oldAmount) diff --git a/templates/participant.html b/templates/participant.html index a923b3a31b..c47faa2297 100644 --- a/templates/participant.html +++ b/templates/participant.html @@ -2,54 +2,43 @@ {% block box %} +{% set prefix = user.participant == participant and "my-" or "" %} +{% set anon_giving = participant.anonymous_giving %} +{% set g = participant.get_dollars_giving() %} +{% set giving = anon_giving and "anonymously" or "$"+str(g) %} +{% set anon_receiving = participant.anonymous_receiving %} +{% set r = participant.get_dollars_receiving() %} +{% set receiving = anon_receiving and "anonymously" or "$"+str(r) %} + <table class="on-profile{% if participant.is_suspicious %} is-suspicious{% endif %}"> <tr> <td class="picture"> <a href="/{{ participant.username }}/"><img src="{{ participant.get_img_src(128) }}" /></a> </td> <td class="giving-receiving"> - {% set giving = participant.get_dollars_giving() %} - {% set receiving = participant.get_dollars_receiving() %} - - {% if participant.anonymous_giving and participant.anonymous_receiving %} + {% if anon_giving and anon_receiving %} <h2 class="pad-sign">{{ participant.username }}</h2> <div class="unit pad-sign">gives and receives anonymously</div> - {% elif g > r and not participant.anonymous_giving %} + {% elif not anon_giving and g > 0 and (g > r or anon_receiving) %} <h2 class="pad-sign">{{ participant.username }} gives</h2> <div class="number"> - {% if user.participant == participant %} - $<span class="total-giving">{{ giving }}</span> - {% else %} - ${{ giving }} - {% endif %} + <span class="{{prefix}}total-giving">{{ giving }}</span> </div> - <div class="unit pad-sign">per week - {% if r > 0 %}, and receives - {% if participant.anonymous_receiving %} - anonymously - {% else %} - ${{ receiving }} - {% endif %} - {% endif %} + <div class="unit pad-sign"> + per week{% if r > 0 %}, and receives {{ receiving }}{% endif %} </div> - {% elif receiving > 0 %} + {% elif not anon_receiving and r > 0 and (r >= g or anon_giving) %} <h2 class="pad-sign">{{ participant.username }} receives</h2> - <div class="number">$<span class="total-receiving">{{ receiving }}</span></div> - <div class="unit pad-sign">per week - {% if g > 0 %}, and gives - {% if participant.anonymous_giving %} - anonymously - {% else %} - ${{ giving }} - {% endif %} - {% endif %} + <div class="number"> + <span class="total-receiving">{{ receiving }}</span> + </div> + <div class="unit pad-sign"> + per week{% if g > 0 %}, and gives {{ giving }}{% endif %} </div> {% else %} {% set age = participant.get_age_in_seconds() %} <h2>{{ participant.username }} - {% if giving > 0 %} - gives anonymously - {% elif age < 60 %} + {% if age < 60 %} just joined Gittip! :D {% elif age < (60 * 60 * 24 * 7) %} joined recently diff --git a/www/%username/giving/index.html.spt b/www/%username/giving/index.html.spt index 9502cc81d6..c097e1f247 100644 --- a/www/%username/giving/index.html.spt +++ b/www/%username/giving/index.html.spt @@ -64,7 +64,7 @@ first_time = qs.get('first_time') == '1' {% endif %} {% if participant == user %} - <h2>You give $<span class="total-giving">{{ total }}</span> per + <h2>You give <span class="my-total-giving">${{ total }}</span> per week</h2> {% else %} <h2>{{ participant.username }} gives ${{ total }} per week</h2> diff --git a/www/for/%slug/index.html.spt b/www/for/%slug/index.html.spt index f716184f09..8612cc2cf5 100644 --- a/www/for/%slug/index.html.spt +++ b/www/for/%slug/index.html.spt @@ -187,9 +187,7 @@ if community.nmembers >= website.NMEMBERS_THRESHOLD: {% block box %} <div class="on-community"> <h2 class="pad-sign">{{ community.name }}</h2> - <div class="number"> - <span class="total-giving">{{ community.nmembers }}</span> - </div> + <div class="number">{{ community.nmembers }}</div> <div class="unit pad-sign">member{{ '' if community.nmembers == 1 else 's' }}</div> </div> <div class="nav level-1"> diff --git a/www/for/index.html.spt b/www/for/index.html.spt index 2adc54d299..262237cb4a 100644 --- a/www/for/index.html.spt +++ b/www/for/index.html.spt @@ -31,9 +31,7 @@ members get their own page on Gittip.</p> {% block box %} <div class="on-community"> <h2 class="pad-sign">There are</h2> - <div class="number"> - <span class="total-giving">{{ ncommunities }}</span> - </div> + <div class="number">{{ ncommunities }}</div> <div class="unit pad-sign"> communit{{ plural(ncommunities, 'y', 'ies') }} on Gittip. </div> From 1b327e67a2f516c9c9d7e4c3a1e9852fa909f283 Mon Sep 17 00:00:00 2001 From: Changaco <changaco@changaco.net> Date: Fri, 6 Dec 2013 20:59:20 +0100 Subject: [PATCH 07/11] fake_data: randomize anonymous_giving and anonymous_receiving --- gittip/utils/fake_data.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gittip/utils/fake_data.py b/gittip/utils/fake_data.py index 6e135df312..299698c3a4 100644 --- a/gittip/utils/fake_data.py +++ b/gittip/utils/fake_data.py @@ -57,8 +57,7 @@ def fake_sentence(start=1, stop=100): return faker.sentence(random.randrange(start,stop)) -def fake_participant(db, number="singular", is_admin=False, - anonymous_giving=False, anonymous_receiving=False): +def fake_participant(db, number="singular", is_admin=False): """Create a fake User. """ username = faker.first_name() + fake_text_id(3) @@ -71,8 +70,8 @@ def fake_participant(db, number="singular", is_admin=False, , ctime=faker.date_time_this_year() , is_admin=is_admin , balance=fake_balance() - , anonymous_giving=anonymous_giving - , anonymous_receiving=anonymous_receiving + , anonymous_giving=(random.randrange(5) == 0) + , anonymous_receiving=(random.randrange(5) == 0) , goal=fake_balance() , balanced_account_uri=faker.uri() , last_ach_result='' From b97f47a751c8bf6ee38528bd1f3e0987613f0792 Mon Sep 17 00:00:00 2001 From: Changaco <changaco@changaco.net> Date: Fri, 6 Dec 2013 21:56:15 +0100 Subject: [PATCH 08/11] put the SQL schema changes in a transaction --- branch.sql | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/branch.sql b/branch.sql index 75749acf99..f8c05fab14 100644 --- a/branch.sql +++ b/branch.sql @@ -1,7 +1,8 @@ ------------------------------------------------------------------------------- -- https://github.com/gittip/www.gittip.com/issues/1683 -ALTER TABLE participants RENAME COLUMN anonymous TO anonymous_giving; -ALTER TABLE participants DROP COLUMN anonymous; -ALTER TABLE participants ADD COLUMN anonymous_receiving bool NOT NULL DEFAULT FALSE; -ALTER TABLE homepage_top_receivers ADD COLUMN anonymous boolean; +BEGIN; + ALTER TABLE participants RENAME COLUMN anonymous TO anonymous_giving; + ALTER TABLE participants ADD COLUMN anonymous_receiving bool NOT NULL DEFAULT FALSE; + ALTER TABLE homepage_top_receivers ADD COLUMN anonymous boolean; +END; From dfaa94d997d87496c6d1fd0568b8e4a9a70bee75 Mon Sep 17 00:00:00 2001 From: Changaco <changaco@changaco.net> Date: Sat, 7 Dec 2013 09:32:58 +0100 Subject: [PATCH 09/11] add missing <span>s with class="(my-)total-giving" --- templates/base.html | 5 ++++- templates/participant.html | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/templates/base.html b/templates/base.html index e10c2e1c8e..2db7768780 100644 --- a/templates/base.html +++ b/templates/base.html @@ -50,7 +50,10 @@ <h1> <a href="/{{ user.participant.username }}/">{{ user.participant.username }}</a> – <a id="sign-out" href="/sign-out.html">sign out</a> <div class="quick-stats"> - Giving: <a href="/{{ user.participant.username }}/giving/">${{ user.participant.get_dollars_giving() }}/wk</a><br /> + Giving: <a href="/{{ user.participant.username }}/giving/"> + <span class="my-total-giving">${{ user.participant.get_dollars_giving() }}<span>/wk + </a> + <br /> Receiving: <b>${{ user.participant.get_dollars_receiving() }}/wk</b> </div> </div> diff --git a/templates/participant.html b/templates/participant.html index c47faa2297..a2b1c0b958 100644 --- a/templates/participant.html +++ b/templates/participant.html @@ -33,7 +33,9 @@ <h2 class="pad-sign">{{ participant.username }} receives</h2> <span class="total-receiving">{{ receiving }}</span> </div> <div class="unit pad-sign"> - per week{% if g > 0 %}, and gives {{ giving }}{% endif %} + per week{% if g > 0 %}, and gives + <span class="{{prefix}}total-giving">{{ giving }}</span> + {% endif %} </div> {% else %} {% set age = participant.get_age_in_seconds() %} From 7024bc1943821f80c08cb37794ba0f75b6ce31c6 Mon Sep 17 00:00:00 2001 From: Changaco <changaco@changaco.net> Date: Sat, 7 Dec 2013 12:34:26 +0100 Subject: [PATCH 10/11] fix an {% if %} condition --- www/%username/giving/index.html.spt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/%username/giving/index.html.spt b/www/%username/giving/index.html.spt index c097e1f247..4e3a0527dc 100644 --- a/www/%username/giving/index.html.spt +++ b/www/%username/giving/index.html.spt @@ -63,7 +63,7 @@ first_time = qs.get('first_time') == '1' </ol> {% endif %} - {% if participant == user %} + {% if participant == user.participant %} <h2>You give <span class="my-total-giving">${{ total }}</span> per week</h2> {% else %} From dd43702d501a07c0d916ed80dd692cd70ea349a7 Mon Sep 17 00:00:00 2001 From: Changaco <changaco@changaco.net> Date: Thu, 9 Jan 2014 17:59:22 +0100 Subject: [PATCH 11/11] fix NameError --- www/index.html.spt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/index.html.spt b/www/index.html.spt index e31f8e789d..04306442bf 100644 --- a/www/index.html.spt +++ b/www/index.html.spt @@ -187,7 +187,7 @@ receivers = utter_hack(website.db, website.db.all(""" </span> {% else %} <a href="/{{ receiver.username }}/" - class="mini-user{{ ' anonymous' if giver.anonymous else '' }}"> + class="mini-user{{ ' anonymous' if receiver.anonymous else '' }}"> <span class="inner"> <span class="avatar" style="background-image: url('{{ _get_img_src(receiver) }}')">