Skip to content
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

Create groups for ptokens #7944

Merged
merged 4 commits into from
Jan 14, 2021
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
1 change: 1 addition & 0 deletions app/dashboard/templates/board/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
{% endif %}
<script src="{% static "v2/js/vue-components.js" %}"></script>
<script>
document.has_ptoken_auth = {{ has_ptoken_auth|yesno:"true,false"}};
document.user_has_token = {{ ptoken|yesno:"true,false" }};
{% if ptoken %}
document.ptoken = {
Expand Down
75 changes: 37 additions & 38 deletions app/dashboard/templates/board/ptokens.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,47 +55,46 @@
</div>
</div>
</div>
</header>

<section class="container">
<div class="row">
<div class="col-12">
<div class="bg-white rounded border my-4">
<div class="d-flex justify-content-between align-items-center p-4 border-bottom">
<template v-if="!user_has_token">
<div>
Create a personal token to get paid today for work tomorrow <a href="{% url 'ptoken_quickstart' %}" class="underline">Learn more</a>
</div>
<div id="showCreationSuccessModal" hidden data-toggle="modal" data-target="#createTokenSuccessModal"></div>
<button class="btn btn-sm btn-outline-gc-blue m-2" data-toggle="modal" data-target="#createTokenModal">
Create
</button>
</template>
<template v-else-if="pToken.tx_status === 'pending'">
<div>Please wait for your transaction to be confirmed</div>
<button class="btn btn-sm m-2" type="button" disabled>
<span class="spinner-border btn-gc-green spinner-border-sm" role="status" aria-hidden="true"></span>
Mining...
</button>
</template>
<template v-else-if="pToken.tx_status === 'success'">
<div>Modify your Personal Token</div>
<button class="btn btn-sm btn-outline-gc-blue m-2" data-toggle="modal" data-target="#editpTokenModal">
Edit
</button>
</template>
<template v-else>
<div>An error occurred trying to create your pToken</div>
<button class="btn btn-sm btn-gc-outline-red m-2" data-toggle="modal" data-target="#createTokenModal">
Please try again or contact [email protected]
</button>
</template>

</div>
</div>
</header>
<section v-if="has_ptoken_auth" class="container">
<div class="row">
<div class="col-12">
<div class="bg-white rounded border my-4">
<div class="d-flex justify-content-between align-items-center p-4 border-bottom">
<template v-if="!user_has_token">
<div>
Create a personal token to get paid today for work tomorrow <a href="{% url 'ptoken_quickstart' %}" class="underline">Learn more</a>
</div>
<div id="showCreationSuccessModal" hidden data-toggle="modal" data-target="#createTokenSuccessModal"></div>
<button class="btn btn-sm btn-outline-gc-blue m-2" data-toggle="modal" data-target="#createTokenModal">
Create
</button>
</template>
<template v-else-if="pToken.tx_status === 'pending'">
<div>Please wait for your transaction to be confirmed</div>
<button class="btn btn-sm m-2" type="button" disabled>
<span class="spinner-border btn-gc-green spinner-border-sm" role="status" aria-hidden="true"></span>
Mining...
</button>
</template>
<template v-else-if="pToken.tx_status === 'success'">
<div>Modify your Personal Token</div>
<button class="btn btn-sm btn-outline-gc-blue m-2" data-toggle="modal" data-target="#editpTokenModal">
Edit
</button>
</template>
<template v-else>
<div>An error occurred trying to create your pToken</div>
<button class="btn btn-sm btn-gc-outline-red m-2" data-toggle="modal" data-target="#createTokenModal">
Please try again or contact [email protected]
</button>
</template>
</div>
</div>
</div>
</section>
</div>
</section>

<section class="container">
<div class="row">
Expand Down
2 changes: 2 additions & 0 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4979,6 +4979,7 @@ def board(request):
"""Handle the board view."""

user = request.user if request.user.is_authenticated else None
has_ptoken_auth = user.has_perm('auth.user.add_pToken_auth')
keywords = user.profile.keywords
ptoken = PersonalToken.objects.filter(token_owner_profile=user.profile).first()

Expand All @@ -4991,6 +4992,7 @@ def board(request):
'avatar_url': static('v2/images/helmet.png'),
'keywords': keywords,
'ptoken': ptoken,
'has_ptoken_auth': has_ptoken_auth,
}
return TemplateResponse(request, 'board/index.html', context)

Expand Down
37 changes: 37 additions & 0 deletions app/ptokens/management/commands/setup_ptoken_launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'''
Copyright (C) 2020 Gitcoin Core
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
from django.contrib.auth.models import Group, Permission, User
from django.contrib.contenttypes.models import ContentType
from django.core.management.base import BaseCommand
from django.db.models import Q


class Command(BaseCommand):
help = "Setup pToken Permissions"

def handle(self, *args, **options):
pToken_group_name = "pToken-Seed-Round"
pToken_group = Group.objects.get_or_create(name=pToken_group_name)[0]
ct = ContentType.objects.get_for_model(model=User)
add_pToken_auth = Permission.objects.get_or_create(name="Add pToken", codename="add_pToken_auth", content_type=ct)[0]
pToken_group.permissions.add(add_pToken_auth)

print('Adding seeded users to pToken Group')

# TODO: How else will we determine which users should be added to the group
valid_users = User.objects.filter(~Q(groups__name__in=[pToken_group_name]), profile__trust_profile=True)
Copy link
Contributor Author

@corydickson corydickson Nov 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just need clarity on the identifier to seed the initial user base. Email / ids ? @thelostone-mc

for user in valid_users:
user.groups.add(pToken_group)

print('Valid users added to pToken group')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we run this just once and be done with it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, unless you had another way in mind. Let me know how seeding is determined and I can open another PR and add it to this command

6 changes: 6 additions & 0 deletions app/ptokens/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ def ptoken(request, token_id='me'):
return JsonResponse(
{'error': _('You must be authenticated via github to use this feature!')},
status=401)

if not user.has_perm('auth.user.add_pToken_auth'):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mds1 Brought up the good point that a user would be able to abuse Vue here and possibly open the modal; this ensures that they cannot make the request given their creds

return JsonResponse(
{'error': _('You are not allowed to use this feature!')},
status=403)

event_name = request.POST.get('event_name')
if user.profile != ptoken.token_owner_profile:
return JsonResponse(
Expand Down