Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
opened registrations for all requesters
Browse files Browse the repository at this point in the history
closes #1023
  • Loading branch information
dmorina committed Dec 5, 2017
1 parent a238bec commit f679b35
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 10 deletions.
9 changes: 6 additions & 3 deletions crowdsourcing/middleware/requirement.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.http import JsonResponse

from crowdsourcing.utils import get_worker_cache


Expand All @@ -8,9 +9,11 @@ def __init__(self, get_response=None):

@staticmethod
def process_view(request, view_func, view_args, view_kwargs):
if request.path.startswith('/api/auth') or request.path.startswith('/api/profile/'):
return None
if not request.user.is_anonymous() and request.path.startswith('/api'):
allowed_paths = ['/api/auth', '/api/profile/', '/api/user/is-whitelisted']
for path in allowed_paths:
if request.path.startswith(path):
return None
if not request.user.is_anonymous() and (request.path.startswith('/api') or request.path.startswith('/v1')):
worker_cache = get_worker_cache(request.user.id)
if not (int(worker_cache.get('is_worker', 0)) or int(worker_cache.get('is_requester', 0))):
return JsonResponse(data={'type': 'error', 'message': 'MISSING_USER_INFORMATION', 'code': 'D-000'},
Expand Down
6 changes: 3 additions & 3 deletions crowdsourcing/permissions/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def has_object_permission(self, request, view, object):

class CanCreateAccount(permissions.BasePermission):
def has_permission(self, request, view):
user_email = request.data.get('email')
users = RegistrationWhitelist.objects.filter(email=user_email).count()
if view.action == 'create' and not (request.user.is_staff or settings.REGISTRATION_ALLOWED) and users == 0:
# user_email = request.data.get('email')
# users = RegistrationWhitelist.objects.filter(email=user_email).count()
if view.action == 'create' and not (request.user.is_staff or settings.REGISTRATION_ALLOWED):
raise PermissionDenied(detail='We are currently in closed beta. '
'If you\'d like an account, email [email protected] '
'with a short description of what you\'d like to use Daemo for.')
Expand Down
14 changes: 13 additions & 1 deletion crowdsourcing/viewsets/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from crowdsourcing import constants
from crowdsourcing import models
from crowdsourcing.exceptions import daemo_error
from crowdsourcing.models import RegistrationWhitelist
from crowdsourcing.payment import Stripe
from crowdsourcing.permissions.user import CanCreateAccount
from crowdsourcing.redis import RedisProvider
Expand All @@ -36,6 +37,14 @@ class UserViewSet(mixins.RetrieveModelMixin, mixins.CreateModelMixin, mixins.Upd
lookup_field = 'username'
permission_classes = [CanCreateAccount]

@staticmethod
def is_whitelisted(user):
return RegistrationWhitelist.objects.filter(email=user.email).count() > 0

@list_route(methods=['get'], permission_classes=[IsAuthenticated], url_path='is-whitelisted')
def is_whitelisted_route(self, request, *args, **kwargs):
return Response({"result": self.is_whitelisted(request.user)})

@list_route(methods=['get'], permission_classes=[IsAuthenticated], url_path='available-workers')
def available_workers(self, request, *args, **kwargs):
workers = models.TaskWorker.objects.values('worker').filter(
Expand Down Expand Up @@ -309,7 +318,10 @@ def stripe(self, request, *args, **kwargs):
raise serializers.ValidationError(detail=card_serializer.errors)
credit_card = request.data.get('credit_card')
if is_worker:
# TODO add support for other countries
if not UserViewSet.is_whitelisted(request.user):
raise serializers.ValidationError(
detail=daemo_error("You are not allowed to sign up as a worker at this time."))
# TODO add support for other countries
bank_data = request.data.get('bank', {})
bank_data.update({'currency': 'usd'})
bank_data.update({'country': 'US'})
Expand Down
14 changes: 14 additions & 0 deletions static/js/user/controllers/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
vm.updatePartial = updatePartial;
vm.savePaymentInfo = savePaymentInfo;
vm.saveInitialData = saveInitialData;
vm.isWhitelisted = false;
self.financial_data = null;
vm.use_for = null;
vm.payment = {
Expand Down Expand Up @@ -133,6 +134,7 @@
// });

getProfile();
isWhitelisted()
}

function addressSearch(address) {
Expand Down Expand Up @@ -254,6 +256,18 @@
});
}

function isWhitelisted() {
User.isWhitelisted().then(
function success(response) {
vm.isWhitelisted = response[0].result;
},
function error(response) {
}
).finally(function () {

});
}

function jobTitleSearch(query) {
return query ? _.filter(vm.job_titles, function (job_title) {
return (angular.lowercase(job_title).indexOf(angular.lowercase(query)) !== -1)
Expand Down
11 changes: 10 additions & 1 deletion static/js/user/services/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
getNotifications: getNotifications,
isHandleUnique: isHandleUnique,
updateHandle: updateHandle,
getAvailableWorkerCount: getAvailableWorkerCount
getAvailableWorkerCount: getAvailableWorkerCount,
isWhitelisted: isWhitelisted
};


Expand Down Expand Up @@ -326,6 +327,14 @@
return HttpService.doRequest(settings);
}

function isWhitelisted() {
var settings = {
url: '/api/user/is-whitelisted/',
method: 'GET'
};
return HttpService.doRequest(settings);
}

}

})();
7 changes: 5 additions & 2 deletions static/templates/user/getting-started.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,12 @@
<md-radio-button value="is_requester">I am a requester: I will pay people to complete my
tasks
</md-radio-button>
<md-radio-button value="is_worker">I am a worker: I will get paid for completing tasks
<md-radio-button value="is_worker" ng-disabled="{{ !user.isWhitelisted }}">I am a worker: I
will get paid for completing tasks
</md-radio-button>
<md-radio-button value="is_both" ng-disabled="{{ !user.isWhitelisted }}">I am both a worker
and a requester
</md-radio-button>
<md-radio-button value="is_both">I am both a worker and a requester</md-radio-button>
</md-radio-group>
</div>
<div style="padding-bottom: 8px">
Expand Down

0 comments on commit f679b35

Please sign in to comment.