loop
This commit is contained in:
parent
65e973c3b0
commit
e933b22397
@ -13,6 +13,7 @@ class Group(models.Model):
|
||||
creator = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
|
||||
users = models.ManyToManyField(User, related_name="user_groups")
|
||||
editors = ArrayField(models.TextField(), default=list)
|
||||
access_token = models.CharField(max_length=30, null=True)
|
||||
|
||||
@property
|
||||
def available_sets(self):
|
||||
|
@ -1,6 +1,7 @@
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from SprintLib.BaseView import BaseView, AccessError
|
||||
from SprintLib.utils import generate_token
|
||||
|
||||
|
||||
class GroupView(BaseView):
|
||||
@ -45,3 +46,16 @@ class GroupView(BaseView):
|
||||
for t in to_delete:
|
||||
self.entities.group.users.remove(t)
|
||||
return "/group?group_id=" + str(self.entities.group.id)
|
||||
|
||||
def link_action(self, value):
|
||||
if not self.owner:
|
||||
raise AccessError()
|
||||
self.entities.group.access_token = value
|
||||
self.entities.group.save()
|
||||
return "/group?group_id=" + str(self.entities.group.id)
|
||||
|
||||
def post_open_link(self):
|
||||
return self.link_action(generate_token())
|
||||
|
||||
def post_close_link(self):
|
||||
return self.link_action(None)
|
||||
|
@ -1,5 +1,6 @@
|
||||
from random import sample
|
||||
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db.models import Count, Max, Q
|
||||
from django.utils import timezone
|
||||
|
||||
@ -62,3 +63,12 @@ class MainView(BaseView):
|
||||
raise AccessError()
|
||||
group = Group.objects.create(name=self.request.POST['name'], creator=self.request.user)
|
||||
return '/group?group_id=' + str(group.id)
|
||||
|
||||
def post_token(self):
|
||||
token = self.request.POST['token']
|
||||
try:
|
||||
group = Group.objects.get(access_token=token)
|
||||
group.users.add(self.request.user)
|
||||
return '/group?group_id=' + str(group.id)
|
||||
except ObjectDoesNotExist:
|
||||
return "/"
|
||||
|
@ -54,7 +54,20 @@
|
||||
<img src="{{ u.userinfo.profile_pic_url }}" width="30px" height="30px" style="border-radius: 50%; margin-right: 10px;"><a href="/account?username={{ u.username }}">{{ u.username }}</a><br><br>
|
||||
{% endfor %}
|
||||
{% if group.creator == user or user.username in group.editors %}
|
||||
<button type="button" class="btn btn-primary" style="margin-top: 20px;" data-toggle="modal" data-target="#exampleU"><i class="fa fa-pencil"></i> Редактировать</button>
|
||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleU"><i class="fa fa-pencil"></i> Редактировать</button>
|
||||
{% if group.access_token %}
|
||||
<button type="submit" form="close_link" class="btn btn-danger"><i class="fa fa-lock"></i> Закрыть доступ по токену</button><input style="width: 300px; margin-left: 10px;" value="{{ group.access_token }}">
|
||||
<form method="POST" id="close_link">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="action" value="close_link">
|
||||
</form>
|
||||
{% else %}
|
||||
<button type="submit" form="open_link" class="btn btn-success"><i class="fa fa-unlock"></i> Открыть доступ по токену</button>
|
||||
<form method="POST" id="open_link">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="action" value="open_link">
|
||||
</form>
|
||||
{% endif %}
|
||||
<div class="modal fade" id="exampleU" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitleU" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<form method="POST">
|
||||
|
@ -8,6 +8,38 @@
|
||||
<td>
|
||||
<h2>Мои группы</h2>
|
||||
</td>
|
||||
<td>
|
||||
<button style="margin-left: 20px;" class="btn btn-primary" data-toggle="modal" data-target="#exampletoken"><i class="fa fa-sign-in"></i></button>
|
||||
<div class="modal fade" id="exampletoken" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitletoken" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<form method="POST">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLongTitletoken">Войти в группу по токену</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
{% csrf_token %}
|
||||
<inout type="hidden" name="action" value="token"></inout>
|
||||
<input type="token" name="name" placeholder="Токен">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-times-circle"></i> Закрыть</button>
|
||||
<button type="submit" class="btn btn-success"><i class="fa fa-sign-in"></i> Войти</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
{% if user.userinfo.can_create %}
|
||||
<td>
|
||||
<button style="margin-left: 20px;" class="btn btn-success" data-toggle="modal" data-target="#example"><i class="fa fa-plus"></i></button>
|
||||
|
Loading…
Reference in New Issue
Block a user