def custom_jwt_payload_handler(user): payload = default_jwt_payload_handler(user) payload['is_domainreviewer'] = is_domainreviewer(user) payload['is_qualityreviewer'] = is_qualityreviewer(user) return payload
def has_object_permission(self, request, view, obj): user = request.user if (user.is_anonymous()): return False return is_domainreviewer(user) or is_qualityreviewer( user) or obj.user == user
def has_object_permission(self, request, view, obj): user = obj.user if (user.is_anonymous() or obj.script_details.script.status): return False if ('done' in request.data.keys()): return is_domainreviewer(user) or is_qualityreviewer( user) or obj.user == user return request.user == obj.user
def remove_video_entry(request, tdid, lgid): if (not is_administrator(request.user)) and (not is_qualityreviewer( request.user)): raise PermissionDenied() try: tr_rec = TutorialResource.objects.get(tutorial_detail_id=tdid, language_id=lgid) if tr_rec.video_id: flow, credential = get_storage_flow_secret('manage') if credential is None or credential.invalid == True: flow.params['state'] = xsrfutil.generate_token( settings.SECRET_KEY, scope_users['manage']) authorize_url = flow.step1_get_authorize_url() return HttpResponseRedirect(authorize_url) http = httplib2.Http() http = credential.authorize(http) service = build(settings.YOUTUBE_API_SERVICE_NAME, settings.YOUTUBE_API_VERSION, http=http) result = delete_video(service, tr_rec.video_id) if result: tr_rec.video_id = None if tr_rec.playlist_item_id: delete_playlistitem(service, tr_rec.playlist_item_id) video_path, file_extension = os.path.splitext(tr_rec.video) video_path = settings.MEDIA_ROOT + 'videos/' + str( tr_rec.tutorial_detail.foss_id) + '/' + str( tr_rec.tutorial_detail_id ) + '/' + video_path + '.mp4' if os.path.isfile(video_path): os.remove(video_path) try: playlist_item = PlaylistItem.objects.get( item_id=tr_rec.playlist_item_id) playlist_item.delete() tr_rec.playlist_item_id = None except: pass tr_rec.save() messages.success( request, tr_rec.tutorial_detail.foss.foss + ': ' + tr_rec.tutorial_detail.tutorial + ' - ' + tr_rec.language.name + ' <b>video removed from youtube ...</b>') else: messages.success( request, 'Something went wrong, please contact site administrator.') else: messages.error('Video ID missing!') except: messages.error(request, 'Invalid tutorial id ...') return HttpResponseRedirect('/youtube/remove-youtube-video/')
def remove_video_entry(request, tdid, lgid): if (not is_administrator(request.user)) and (not is_qualityreviewer( request.user)): raise PermissionDenied() try: tr_rec = TutorialResource.objects.get(tutorial_detail_id=tdid, language_id=lgid) if tr_rec.video_id: service = get_youtube_credential() if service is None: messages.error( "Youtube auth token expired! We've sent an email with URL to update auth token." ) return HttpResponseRedirect('/youtube/remove-youtube-video/') result = delete_video(service, tr_rec.video_id) if result: tr_rec.video_id = None if tr_rec.playlist_item_id: delete_playlistitem(service, tr_rec.playlist_item_id) video_path, file_extension = os.path.splitext(tr_rec.video) video_path = settings.MEDIA_ROOT + 'videos/' + str( tr_rec.tutorial_detail.foss_id) + '/' + str( tr_rec.tutorial_detail_id ) + '/' + video_path + '.mp4' if os.path.isfile(video_path): os.remove(video_path) try: playlist_item = PlaylistItem.objects.get( item_id=tr_rec.playlist_item_id) playlist_item.delete() tr_rec.playlist_item_id = None except: pass tr_rec.save() messages.success( request, tr_rec.tutorial_detail.foss.foss + ': ' + tr_rec.tutorial_detail.tutorial + ' - ' + tr_rec.language.name + ' <b>video removed from youtube ...</b>') else: messages.success( request, 'Something went wrong, please contact site administrator.') else: messages.error('Video ID missing!') except: messages.error(request, 'Invalid tutorial id ...') return HttpResponseRedirect('/youtube/remove-youtube-video/')
def remove_youtube_video(request): if (not is_administrator(request.user)) and (not is_qualityreviewer(request.user)): raise PermissionDenied() form = YoutubeVideoSelectForm() if request.method == 'POST': form = YoutubeVideoSelectForm(request.POST) if form.is_valid(): tdid = request.POST.get('tutorial_name', 0) lgid = request.POST.get('language', 0) if tdid and lgid: return HttpResponseRedirect('/youtube/remove-video-entry/' + str(tdid) + '/' + str(lgid) + '/') else: messages.error('Something went wrong!') context = { 'form' : form, } return render(request, 'youtube/templates/remove_youtube_video.html', context)
def remove_youtube_video(request): if (not is_administrator(request.user)) and (not is_qualityreviewer(request.user)): raise PermissionDenied() form = YoutubeVideoSelectForm() if request.method == 'POST': form = YoutubeVideoSelectForm(request.POST) if form.is_valid(): tdid = request.POST.get('tutorial_name', 0) lgid = request.POST.get('language', 0) if tdid and lgid: return HttpResponseRedirect('/youtube/remove-video-entry/' + str(tdid) + '/' + str(lgid) + '/') else: messages.error('Something went wrong!') context = { 'form': form, } return render(request, 'youtube/templates/remove_youtube_video.html', context)
def remove_video_entry(request, tdid, lgid): if (not is_administrator(request.user)) and (not is_qualityreviewer(request.user)): raise PermissionDenied() try: tr_rec = TutorialResource.objects.get(tutorial_detail_id = tdid, language_id = lgid) if tr_rec.video_id: flow, credential = get_storage_flow_secret('manage') if credential is None or credential.invalid == True: flow.params['state'] = xsrfutil.generate_token(settings.SECRET_KEY, scope_users['manage']) authorize_url = flow.step1_get_authorize_url() return HttpResponseRedirect(authorize_url) http = httplib2.Http() http = credential.authorize(http) service = build(settings.YOUTUBE_API_SERVICE_NAME, settings.YOUTUBE_API_VERSION, http = http) result = delete_video(service, tr_rec.video_id) if result: tr_rec.video_id = None if tr_rec.playlist_item_id: delete_playlistitem(service, tr_rec.playlist_item_id) video_path, file_extension = os.path.splitext(tr_rec.video) video_path = settings.MEDIA_ROOT + 'videos/' + str(tr_rec.tutorial_detail.foss_id) + '/' + str(tr_rec.tutorial_detail_id) + '/' + video_path + '.mp4' if os.path.isfile(video_path): os.remove(video_path) try: playlist_item = PlaylistItem.objects.get(item_id = tr_rec.playlist_item_id) playlist_item.delete() tr_rec.playlist_item_id = None except: pass tr_rec.save() messages.success( request, tr_rec.tutorial_detail.foss.foss + ': ' + tr_rec.tutorial_detail.tutorial + ' - ' + tr_rec.language.name + ' <b>video removed from youtube ...</b>' ) else: messages.success(request, 'Something went wrong, please contact site administrator.') else: messages.error('Video ID missing!') except: messages.error(request, 'Invalid tutorial id ...') return HttpResponseRedirect('/youtube/remove-youtube-video/')
def remove_video_entry(request, tdid, lgid): if (not is_administrator(request.user)) and (not is_qualityreviewer(request.user)): raise PermissionDenied() try: tr_rec = TutorialResource.objects.get(tutorial_detail_id=tdid, language_id=lgid) if tr_rec.video_id: service = get_youtube_credential() if service is None: messages.error( "Youtube auth token expired! We've sent an email with URL to update auth token.") return HttpResponseRedirect('/youtube/remove-youtube-video/') result = delete_video(service, tr_rec.video_id) if result: tr_rec.video_id = None if tr_rec.playlist_item_id: delete_playlistitem(service, tr_rec.playlist_item_id) video_path, file_extension = os.path.splitext(tr_rec.video) video_path = settings.MEDIA_ROOT + 'videos/' + str(tr_rec.tutorial_detail.foss_id) + '/' + str(tr_rec.tutorial_detail_id) + '/' + video_path + '.mp4' if os.path.isfile(video_path): os.remove(video_path) try: playlist_item = PlaylistItem.objects.get(item_id=tr_rec.playlist_item_id) playlist_item.delete() tr_rec.playlist_item_id = None except: pass tr_rec.save() messages.success( request, tr_rec.tutorial_detail.foss.foss + ': ' + tr_rec.tutorial_detail.tutorial + ' - ' + tr_rec.language.name + ' <b>video removed from youtube ...</b>' ) else: messages.success(request, 'Something went wrong, please contact site administrator.') else: messages.error('Video ID missing!') except: messages.error(request, 'Invalid tutorial id ...') return HttpResponseRedirect('/youtube/remove-youtube-video/')
def get_queryset(self): try: tutorial = TutorialDetail.objects.get(pk=int(self.kwargs['tid'])) language = Language.objects.get(pk=int(self.kwargs['lid'])) script = Script.objects.get(tutorial=tutorial, language=language) user = self.request.user if is_domainreviewer(user) or is_qualityreviewer( user) or is_videoreviewer( user) or script.user == user or script.status == True: script_details = ScriptDetail.objects.filter(script=script) ordering = script.ordering if (len(ordering) != 0): ordering = ordering.split(',') ordering = list(map(int, ordering)) script_details = sorted(script_details, key=lambda s: ordering.index(s.pk)) return script_details except: return None