Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_user_form(request, project, verbose=False, form_class=UserManageForm):
"""Check project permission and UserManageForm.
This is simple helper to perform needed validation for all
user management views.
"""
obj = get_project(request, project)
if (not request.user.has_perm('project.permissions', obj)
or obj.access_control == obj.ACCESS_CUSTOM):
raise PermissionDenied()
form = form_class(request.POST)
if form.is_valid():
return obj, form
if verbose:
show_form_errors(request, form)
return obj, None
def download_project(request, project):
obj = get_project(request, project)
obj.commit_pending("download", None)
return download_multi(
Translation.objects.filter(component__project=obj), request.GET.get("format")
)
def data_project(request, project):
obj = get_project(request, project)
return render(
request,
'data.html',
{
'object': obj,
'components': obj.component_set.order(),
'project': obj,
}
def reset_project(request, project):
obj = get_project(request, project)
if not request.user.has_perm('vcs.reset', obj):
raise PermissionDenied()
return perform_reset(request, obj)
def download_dictionary(request, project, lang):
"""Export dictionary into various formats."""
prj = get_project(request, project)
lang = get_object_or_404(Language, code=lang)
# Parse parameters
export_format = None
if 'format' in request.GET:
export_format = request.GET['format']
if export_format not in ('csv', 'po', 'tbx', 'xliff'):
export_format = 'csv'
# Grab all words
words = Dictionary.objects.filter(
project=prj,
language=lang
).order()
# Translate toolkit based export
def show_engage(request, project, lang=None):
# Get project object, skipping ACL
obj = get_project(request, project, skip_acl=True)
# Handle language parameter
if lang is not None:
language = get_object_or_404(Language, code=lang)
else:
language = None
full_stats = obj.stats
if language:
try_set_language(lang)
stats_obj = full_stats.get_single_language_stats(language)
else:
stats_obj = full_stats
return render(
request,
'engage.html',
def mute_project(request, project):
obj = get_project(request, project)
mute_real(request.user, scope=SCOPE_PROJECT, component=None, project=obj)
return redirect(
'{}?notify_project={}#notifications'.format(reverse('profile'), obj.pk)
)
def get_object(self, request, project):
return get_project(request, project)
def change_access(request, project):
obj = get_project(request, project)
if not request.user.has_perm('billing:project.permissions', obj):
raise PermissionDenied()
form = ProjectAccessForm(request.POST, instance=obj)
if not form.is_valid():
for error in form.errors:
for message in form.errors[error]:
messages.error(request, message)
else:
form.save()
Change.objects.create(
project=obj,
action=Change.ACTION_ACCESS_EDIT,
user=request.user,
def parse_url(request, project, component=None, lang=None):
context = {}
if component is None:
obj = get_project(request, project)
unit_set = Unit.objects.filter(translation__component__project=obj)
context['project'] = obj
elif lang is None:
obj = get_component(request, project, component)
unit_set = Unit.objects.filter(translation__component=obj)
context['component'] = obj
context['project'] = obj.project
else:
obj = get_translation(request, project, component, lang)
unit_set = obj.unit_set.all()
context['translation'] = obj
context['component'] = obj.component
context['project'] = obj.component.project
if not request.user.has_perm('unit.edit', obj):
raise PermissionDenied()