10000 Fixes grants 8 by zoek1 · Pull Request #7962 · gitcoinco/web · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixes grants 8 #7962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions app/assets/v2/js/grants/_detail-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,28 @@ Vue.mixin({
}

},
isTwitterUrl(input) {
const twitter_re = /^https?:\/\/(www\.)?twitter\.com\/(#!\/)?([^/]+)(\/\w+)*$/;
const twitter_match = input.match(twitter_re);

if (twitter_match) {
return twitter_match[3];
}
},
transformTwitterHandle1() {
const match_twitter = this.isTwitterUrl(this.grant.twitter_handle_1);

if (match_twitter) {
this.grant.twitter_handle_1 = match_twitter;
}
},
transformTwitterHandle2() {
const match_twitter = this.isTwitterUrl(this.grant.twitter_handle_2);

if (match_twitter) {
this.grant.twitter_handle_2 = match_twitter;
}
},
tweetVerification() {
let vm = this;
const tweetContent =`https://twitter.com/intent/tweet?text=${encodeURI(vm.verification_tweet)}%20${encodeURI(vm.user_code)}`
Expand All @@ -289,11 +311,11 @@ Vue.mixin({
if (!vm.grant.twitter_handle_1.length) {
vm.$set(vm.errors, 'twitter_handle_1', 'Please enter twitter handle of your project');
}
if (vm.grant.twitter_handle_1 && !(/^@[a-zA-Z0-9_]{1,15}$/).test(vm.grant.twitter_handle_1)) {
vm.$set(vm.errors, 'twitter_handle_1', 'Please enter a valid twitter handle of your project e.g @humanfund');
if (vm.grant.twitter_handle_1 && !(/^@?[a-zA-Z0-9_]{1,15}$/).test(vm.grant.twitter_handle_1)) {
vm.$set(vm.errors, 'twitter_handle_1', 'Please enter a valid twitter handle of your project e.g humanfund');
}
if (vm.grant.twitter_handle_2 && !(/^@[a-zA-Z0-9_]{1,15}$/).test(vm.grant.twitter_handle_2)) {
vm.$set(vm.errors, 'twitter_handle_2', 'Please enter your twitter handle e.g @georgecostanza');
if (vm.grant.twitter_handle_2 && !(/^@?[a-zA-Z0-9_]{1,15}$/).test(vm.grant.twitter_handle_2)) {
vm.$set(vm.errors, 'twitter_handle_2', 'Please enter your twitter handle e.g georgecostanza');
}
if (vm.grant.description_rich.length < 10) {
vm.$set(vm.errors, 'description', 'Please enter description for the grant');
Expand Down
25 changes: 22 additions & 3 deletions app/assets/v2/js/grants/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,29 @@ Vue.component('grant-card', {
return vm.grant.isInCart;
},
checkIsCurator: function() {
if (this.currentUser && this.collection && this.collection.curators.length) {
const curators = this.collection.curators.map(collection => collection.handle);
let vm = this;
let currentUser;
// Validate the user presence and clean current user handle
if (vm.currentUser) {
currentUser = vm.currentUser.replace(/@/, '').replace(/\s/g,'')
} else {
return;
}

// Validate if exists the collection
if (this.collection && this.collection.curators.length) {
this.collection.curators.map(curator => {
let currentCurator;

// Clean curator handle
if (curator && curator.handle) {
currentCurator = curator.handle.replace(/@/, '').replace(/\s/g,'')
}

this.isCurator = curators.indexOf(this.currentUser) !== -1;
if (currentCurator === currentUser) {
vm.isCurator = true;
}
});
}
},
get_clr_prediction: function(indexA, indexB) {
Expand Down
10 changes: 8 additions & 2 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import html
import json
import logging
import re
import time
from copy import deepcopy
from datetime import datetime, timedelta
Expand Down Expand Up @@ -3098,6 +3099,8 @@ def verify_user_twitter(request, handle):
MIN_FOLLOWER_COUNT = 100
MIN_ACCOUNT_AGE_WEEKS = 26 # ~6 months

twitter_re = re.compile(r'^https?://(www\.)?twitter\.com/(#!/)?([^/]+)(/\w+)*$')

is_logged_in_user = request.user.is_authenticated and request.user.username.lower() == handle.lower()
if not is_logged_in_user:
return JsonResponse({
Expand All @@ -3113,14 +3116,17 @@ def verify_user_twitter(request, handle):
})

request_data = json.loads(request.body.decode('utf-8'))
twitter_handle = request_data.get('twitter_handle', '')
twitter_handle = request_data.get('twitter_handle', '').strip('@')
match_twitter_url = twitter_re.match(twitter_handle)

if twitter_handle == '':
if not match_twitter_url or twitter_handle == '':
return JsonResponse({
'ok': False,
'msg': f'Request must include a Twitter handle'
})

twitter_handle = match_twitter_url.group(3)

auth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
auth.set_access_token(TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_SECRET)

Expand Down
4 changes: 2 additions & 2 deletions app/grants/templates/grants/components/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ <h2 class="grant-item__title font-subheader">
<button @click.prevent="addToCart(grant)" :class="{'btn-lg': collection && isCurator}" class="btn btn-gc-blue btn-block font-body font-weight-semibold">
+ Add to Cart
</button>
<button @click.prevent="$emit('collection:remove', {collection, grant})" class="btn btn-block btn-outline-danger font-body font-weight-semibold" v-if="isCurator">
<button @click.prevent="$emit('collection:remove', {collection: collection, grant: grant})" class="btn btn-block btn-outline-danger font-body font-weight-semibold" v-if="isCurator">
- Remove from collection
</button>
</div>
Expand Down Expand Up @@ -264,7 +264,7 @@ <h2 class="font-title font-weight-bold amount pt-1 mb-2">
+ Add to Cart
</button>
</div>
<button @click.prevent="$emit('collection:remove', {collection, grant})" class="btn btn-block btn-outline-danger font-body mt-1 mr-1" v-if="collection && isCurator">
<button @click.prevent="$emit('collection:remove', {collection: collection, grant: grant})" class="btn btn-block btn-outline-danger font-body mt-1 mr-1" v-if="collection && isCurator">
- Remove from collection
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ <h5 class="font-weight-bold mb-3">Verify Grant Ownership with Twitter</h5>
<label class="font-caption letter-spacing text-black-60 text-uppercase" for="twitter_handle_1">Project Twitter Handle</label>
<span class="font-smaller-6 badge badge-greylight text-capitalize ml-2">Required</span>

<input id="twitter_handle_1" v-model.trim="grant.twitter_handle_1" name="twitter_handle_1" class="form__input form__input-lg" maxlength="20" type="text" placeholder="humanfund" required>
<input id="twitter_handle_1" v-model="grant.twitter_handle_1" @change="transformTwitterHandle1" name="twitter_handle_1" class="form__input form__input-lg" type="text" placeholder="humanfund" required>

<div class="text-danger" v-if="errors.twitter_handle_1">
[[errors.twitter_handle_1]]
Expand All @@ -368,7 +368,7 @@ <h5 class="font-weight-bold mb-3">Verify Grant Ownership with Twitter</h5>
<div class="col-12 mb-3">
<label class="font-caption letter-spacing text-black-60 text-uppercase" for="twitter_handle_2">Your Twitter Handle</label>

<input id="twitter_handle_2" v-model.trim="grant.twitter_handle_2" name="twitter_handle_2" class="form__input form__input-lg" maxlength="20" type="text" placeholder="georgecostanza"/>
<input id="twitter_handle_2" v-model="grant.twitter_handle_2" @change="transformTwitterHandle2" name="twitter_handle_2" class="form__input form__input-lg" type="text" placeholder="georgecostanza"/>

<div class="text-danger" v-if="errors.twitter_handle_2">
[[errors.twitter_handle_2]]
Expand Down
0