Пример #1
0
    def getTemplateForUser(self, request, crashEntry):
        if 'template' in request.GET:
            obj = get_object_or_404(BugzillaTemplate,
                                    pk=request.GET['template'])
            template = model_to_dict(obj)
            template["pk"] = obj.pk
        else:
            user = User.get_or_create_restricted(request.user)[0]

            obj = BugzillaTemplate.objects.filter(
                name__contains=crashEntry.tool.name)
            if not obj:
                defaultTemplateId = user.defaultTemplateId
                if not defaultTemplateId:
                    defaultTemplateId = 1

                obj = BugzillaTemplate.objects.filter(pk=defaultTemplateId)

            if not obj:
                template = {}
            else:
                template = model_to_dict(obj[0])
                template["pk"] = obj[0].pk

        return template
Пример #2
0
def createExternalBug(request, crashid):
    entry = get_object_or_404(CrashEntry, pk=crashid)
    check_authorized_for_crash_entry(request, entry)

    if not entry.bucket:
        return renderError(request, "Cannot create an external bug for an issue that is not associated to a bucket/signature")

    if request.method == 'POST':
        provider = get_object_or_404(BugProvider, pk=request.POST['provider'])

        # Let the provider handle the POST request, which will file the bug
        # and return us the external bug ID
        extBugId = provider.getInstance().handlePOSTCreate(request, entry)

        # Now create a bug in our database with that ID and assign it to the bucket
        extBug = Bug(externalId=extBugId, externalType=provider)
        extBug.save()
        entry.bucket.bug = extBug
        entry.bucket.save()

        return redirect('crashmanager:sigview', sigid=entry.bucket.pk)
    elif request.method == 'GET':
        if 'provider' in request.GET:
            provider = get_object_or_404(BugProvider, pk=request.GET['provider'])
        else:
            user = User.get_or_create_restricted(request.user)[0]
            provider = get_object_or_404(BugProvider, pk=user.defaultProviderId)

        return provider.getInstance().renderContextCreate(request, entry)
    else:
        raise SuspiciousOperation
Пример #3
0
def check_authorized_for_crash_entry(request, entry):
    user = User.get_or_create_restricted(request.user)[0]
    if user.restricted:
        defaultToolsFilter = user.defaultToolsFilter.all()
        if not defaultToolsFilter or not entry.tool in defaultToolsFilter:
            raise PermissionDenied({ "message" : "You don't have permission to access this crash entry." })

    return
Пример #4
0
    def process_view(self, request, view_func, view_args, view_kwargs):
        # Get the app name
        app = view_func.__module__.split('.', 1)[0]

        if app == 'server':
            return None

        # If no login is required for this path, we can't check permissions
        if self.exceptions.match(request.path):
            return None

        User.get_or_create_restricted(request.user)  # create a CrashManager user if needed to apply defaults

        if not CheckAppPermission().has_permission(request, view_func):
            raise Http404

        return None
Пример #5
0
def userSettings(request):
    user = User.get_or_create_restricted(request.user)[0]

    def createUserSettingsData(user, msg=None):
        tools = Tool.objects.all()
        currentToolsFilter = user.defaultToolsFilter.all()

        for tool in tools:
            tool.checked = tool in currentToolsFilter

        providers = BugProvider.objects.all()
        provider = providers.filter(pk=user.defaultProviderId)
        templates = None
        if provider:
            provider = provider[0]
            templates = provider.getInstance().getTemplateList()

        return {
            "user": user,
            "tools": tools,
            "providers": providers,
            "templates": templates,
            "defaultProviderId": user.defaultProviderId,
            "defaultTemplateId": user.defaultTemplateId,
            "msg": msg,
        }

    if request.method == 'POST':
        if "changefilter" in request.POST:
            if user.restricted:
                raise PermissionDenied({
                    "message":
                    "You don't have permission to change your tools filter."
                })
            user.defaultToolsFilter.clear()
            user.defaultToolsFilter = [
                Tool.objects.get(name=x.replace("tool_", "", 1))
                for x in request.POST if x.startswith("tool_")
            ]
            data = createUserSettingsData(
                user, msg="Tools filter updated successfully.")
        elif "changetemplate" in request.POST:
            user.defaultProviderId = int(request.POST['defaultProvider'])
            user.defaultTemplateId = int(request.POST['defaultTemplate'])
            user.save()
            data = createUserSettingsData(
                user, msg="Default provider/template updated successfully.")
        else:
            raise SuspiciousOperation

        return render(request, 'usersettings.html', data)
    elif request.method == 'GET':
        return render(request, 'usersettings.html',
                      createUserSettingsData(user))
    else:
        raise SuspiciousOperation
Пример #6
0
def index(request):
    user = User.get_or_create_restricted(request.user)[0]
    # return crashmanager, covmanager, or ec2spotmanager, as allowed, in that order.
    # if no permission to view any apps, then use crashmanager and let that fail
    if not user.user.has_perm('crashmanager.view_crashmanager'):
        if user.user.has_perm('crashmanager.view_covmanager'):
            return redirect('covmanager:index')
        elif user.user.has_perm('crashmanager.view_ec2spotmanager'):
            return redirect('ec2spotmanager:index')
    return redirect('crashmanager:index')
Пример #7
0
def _create_user(username, email="*****@*****.**", password="******", has_permission=True):
    user = User.objects.create_user(username, email, password)
    user.user_permissions.clear()
    if has_permission:
        content_type = ContentType.objects.get_for_model(cmUser)
        perm = Permission.objects.get(content_type=content_type, codename='view_ec2spotmanager')
        user.user_permissions.add(perm)
    (user, _) = cmUser.get_or_create_restricted(user)
    user.save()
    return user
Пример #8
0
    def process_view(self, request, view_func, view_args, view_kwargs):
        # Get the app name
        app = view_func.__module__.split('.', 1)[0]

        if app == 'server':
            return None

        # If no login is required for this path, we can't check permissions
        if self.exceptions.match(request.path):
            return None

        User.get_or_create_restricted(
            request.user
        )  # create a CrashManager user if needed to apply defaults

        if not CheckAppPermission().has_permission(request, view_func):
            return HttpResponseForbidden()

        return None
Пример #9
0
def index(request):
    user = User.get_or_create_restricted(request.user)[0]
    # return crashmanager, covmanager, or ec2spotmanager, as allowed, in that order.
    # if no permission to view any apps, then use crashmanager and let that fail
    if not user.user.has_perm('crashmanager.view_crashmanager'):
        if user.user.has_perm('crashmanager.view_covmanager'):
            return redirect('covmanager:index')
        elif user.user.has_perm('crashmanager.view_ec2spotmanager'):
            return redirect('ec2spotmanager:index')
    return redirect('crashmanager:index')
Пример #10
0
def check_authorized_for_signature(request, signature):
    user = User.get_or_create_restricted(request.user)[0]
    if user.restricted:
        defaultToolsFilter = user.defaultToolsFilter.all()
        if not defaultToolsFilter:
            raise PermissionDenied({ "message" : "You don't have permission to access this signature." })

        entries = CrashEntry.objects.filter(bucket=signature).filter(reduce(operator.or_, [Q(("tool", x)) for x in defaultToolsFilter]))
        if not entries:
            raise PermissionDenied({ "message" : "You don't have permission to access this signature." })

    return
Пример #11
0
def filter_signatures_by_toolfilter(request, signatures, restricted_only=False):
    user = User.get_or_create_restricted(request.user)[0]

    if restricted_only and not user.restricted:
        return signatures

    defaultToolsFilter = user.defaultToolsFilter.all()
    if defaultToolsFilter:
        return signatures.filter(crashentry__tool__in=defaultToolsFilter).distinct()
    elif user.restricted:
        return Bucket.objects.none()

    return signatures
Пример #12
0
def filter_crash_entries_by_toolfilter(request, entries, restricted_only=False):
    user = User.get_or_create_restricted(request.user)[0]

    if restricted_only and not user.restricted:
        return entries

    defaultToolsFilter = user.defaultToolsFilter.all()
    if defaultToolsFilter:
        return entries.filter(reduce(operator.or_, [Q(("tool", x)) for x in defaultToolsFilter]))
    elif user.restricted:
        return CrashEntry.objects.none()

    return entries
Пример #13
0
def userSettings(request):
    user = User.get_or_create_restricted(request.user)[0]

    def createUserSettingsData(user, msg=None):
        tools = Tool.objects.all()
        currentToolsFilter = user.defaultToolsFilter.all()

        for tool in tools:
            tool.checked = tool in currentToolsFilter

        providers = BugProvider.objects.all()
        provider = providers.filter(pk=user.defaultProviderId)
        templates = None
        if provider:
            provider = provider[0]
            templates = provider.getInstance().getTemplateList()

        return {
                "user" : user,
                "tools" : tools,
                "providers" : providers,
                "templates" : templates,
                "defaultProviderId" : user.defaultProviderId,
                "defaultTemplateId" : user.defaultTemplateId,
                "msg" : msg,
                }

    if request.method == 'POST':
        if "changefilter" in request.POST:
            if user.restricted:
                raise PermissionDenied({ "message" : "You don't have permission to change your tools filter." })
            user.defaultToolsFilter.clear()
            user.defaultToolsFilter = [Tool.objects.get(name=x.replace("tool_", "", 1)) for x in request.POST if x.startswith("tool_")]
            data = createUserSettingsData(user, msg="Tools filter updated successfully.")
        elif "changetemplate" in request.POST:
            user.defaultProviderId = int(request.POST['defaultProvider'])
            user.defaultTemplateId = int(request.POST['defaultTemplate'])
            user.save()
            data = createUserSettingsData(user, msg="Default provider/template updated successfully.")
        else:
            raise SuspiciousOperation

        return render(request, 'usersettings.html', data)
    elif request.method == 'GET':
        return render(request, 'usersettings.html', createUserSettingsData(user))
    else:
        raise SuspiciousOperation
Пример #14
0
def createExternalBugComment(request, crashid):
    entry = get_object_or_404(CrashEntry, pk=crashid)
    check_authorized_for_crash_entry(request, entry)

    if request.method == 'POST':
        provider = get_object_or_404(BugProvider, pk=request.POST['provider'])
        provider.getInstance().handlePOSTComment(request, entry)
        return redirect('crashmanager:crashview', crashid=crashid)
    elif request.method == 'GET':
        if 'provider' in request.GET:
            provider = get_object_or_404(BugProvider, pk=request.GET['provider'])
        else:
            user = User.get_or_create_restricted(request.user)[0]
            provider = get_object_or_404(BugProvider, pk=user.defaultProviderId)

        return provider.getInstance().renderContextComment(request, entry)
    else:
        raise SuspiciousOperation
Пример #15
0
def filter_signatures_by_toolfilter(request,
                                    signatures,
                                    restricted_only=False):
    user = User.get_or_create_restricted(request.user)[0]

    if restricted_only and not user.restricted:
        return signatures

    # If the user is unrestricted and all=1 is set, do not apply any filters
    if not user.restricted and "all" in request.GET and request.GET["all"]:
        return signatures

    defaultToolsFilter = user.defaultToolsFilter.all()
    if defaultToolsFilter:
        return signatures.filter(
            crashentry__tool__in=defaultToolsFilter).distinct()
    elif user.restricted:
        return Bucket.objects.none()

    return signatures
Пример #16
0
    def getTemplateForUser(self, request, crashEntry):
        if 'template' in request.GET:
            obj = get_object_or_404(BugzillaTemplate, pk=request.GET['template'])
            template = model_to_dict(obj)
            template["pk"] = obj.pk
        else:
            user = User.get_or_create_restricted(request.user)[0]

            obj = BugzillaTemplate.objects.filter(name__contains=crashEntry.tool.name)
            if not obj:
                defaultTemplateId = user.defaultTemplateId
                if not defaultTemplateId:
                    defaultTemplateId = 1

                obj = BugzillaTemplate.objects.filter(pk=defaultTemplateId)

            if not obj:
                template = {}
            else:
                template = model_to_dict(obj[0])
                template["pk"] = obj[0].pk

        return template
Пример #17
0
def deny_restricted_users(request):
    user = User.get_or_create_restricted(request.user)[0]
    if user.restricted:
        raise PermissionDenied({ "message" : "Restricted users cannot use this feature." })
Пример #18
0
 def decorator(request, *args, **kwargs):
     user = User.get_or_create_restricted(request.user)[0]
     if user.restricted:
         raise PermissionDenied({"message": "You don't have permission to access this view."})
     return wrapped(request, *args, **kwargs)
Пример #19
0
 def decorator(request, *args, **kwargs):
     user = User.get_or_create_restricted(request.user)[0]
     if user.restricted:
         raise PermissionDenied({"message": "You don't have permission to access this view."})
     return wrapped(request, *args, **kwargs)