Skip to content

Commit

Permalink
Merge pull request #629 from srahulbadami/MobileApp_UserView
Browse files Browse the repository at this point in the history
Minor Changes in the Model.Views for Issue Updates for the Mobile App
  • Loading branch information
souravbadami authored Jul 18, 2018
2 parents 9e9fa9c + ade5b46 commit 4deafce
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
4 changes: 3 additions & 1 deletion bugheist/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^domain_check/$', website.views.domain_check),
url(r'^api/v1/', include(router.urls)),
url(r'^api/v1/userscore$', website.views.get_score),
url(r'^api/v1/userscore/$', website.views.get_score),
url(r'^authenticate/', CustomObtainAuthToken.as_view()),
url(r'^api/v1/create_tokens/$', website.views.create_tokens),
url(r'^api/v1/count/$', website.views.issue_count),
url(r'^api/v1/createissues/$', csrf_exempt(IssueCreate.as_view()), name="issuecreate"),
url(r'^api/v1/delete_issue/(?P<id>\w+)/$', csrf_exempt(website.views.delete_issue)),
url(r'^api/v1/issue/update/$', csrf_exempt(website.views.UpdateIssue)),
]

if settings.DEBUG:
Expand Down
12 changes: 12 additions & 0 deletions website/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class IssueViewSet(viewsets.ModelViewSet):
filter_backends = (filters.SearchFilter,)
search_fields = ('url', 'description', 'user__id')

class UserIssueViewSet(viewsets.ModelViewSet):
queryset = Issue.objects.all()
serializer_class = IssueSerializer
filter_backends = (filters.SearchFilter,)
search_fields = ('user__username', 'user__id')

class UserProfileSerializer(serializers.ModelSerializer):
user = UserSerializer(read_only=True)
class Meta:
Expand All @@ -43,7 +49,13 @@ class DomainViewSet(viewsets.ModelViewSet):
filter_backends = (filters.SearchFilter,)
search_fields = ('url', 'name')

class ScoreBoardViewSet(viewsets.ModelViewSet):
serializer_class = DomainSerializer
queryset = Domain.objects.all().order_by('-modified')

router = routers.DefaultRouter()
router.register(r'issues', IssueViewSet, base_name="issues")
router.register(r'userissues', UserIssueViewSet, base_name="userissues")
router.register(r'profile', UserProfileViewSet, base_name="profile")
router.register(r'domain', DomainViewSet, base_name="domain")
router.register(r'scoreboard', ScoreBoardViewSet, base_name="scoreboard")
24 changes: 19 additions & 5 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,22 @@ def post(self, request, *args, **kwargs):
form.save()
return redirect(reverse('profile', kwargs={'slug': kwargs.get('slug')}))


def delete_issue(request, id):
try:
for token in Token.objects.all():
if request.POST['token'] == token.key:
request.user = User.objects.get(id = token.user_id)
tokenauth = True
except:
tokenauth = False
issue = Issue.objects.get(id=id)
if request.user.is_superuser or request.user == issue.user:
issue.delete()
messages.success(request, 'Issue deleted')
return redirect('/')

if tokenauth == True :
return JsonResponse("Deleted", safe=False)
else :
return redirect('/')

class DomainDetailView(ListView):
template_name = "domain.html"
Expand Down Expand Up @@ -695,7 +703,6 @@ def get_context_data(self, *args, **kwargs):
scoreboard_paginated = paginator.page(1)
except EmptyPage:
scoreboard_paginated = paginator.page(paginator.num_pages)

context['scoreboard'] = scoreboard_paginated
context['user'] = self.request.GET.get('user')
return context
Expand Down Expand Up @@ -905,11 +912,18 @@ def post(self, request, *args, **kwargs):


def UpdateIssue(request):
print(request.POST.get('action'))
try:
issue = Issue.objects.get(id=request.POST.get('issue_pk'))
except Issue.DoesNoTExist:
raise Http404("issue not found")

try:
for token in Token.objects.all():
if request.POST['token'] == token.key:
request.user = User.objects.get(id = token.user_id)
tokenauth = True
except:
tokenauth = False
if request.method == "POST" and request.user.is_superuser or (issue is not None and request.user == issue.user):
if request.POST.get('action') == "close":
issue.status = "closed"
Expand Down

0 comments on commit 4deafce

Please sign in to comment.