示例#1
0
    def post(self, request, *args, **kwargs):
        try:
            jira_auth = get_jira_auth_from_request(request)
        except (ApiError, JiraTenant.DoesNotExist):
            self.get_response("error.html")

        if request.user.is_anonymous():
            return self.get_response("signin.html")

        orgs = self.request.user.get_orgs()

        form = JiraConfigForm([(o.id, o.name) for o in orgs], self.request.POST)

        if form.is_valid():
            try:
                org = orgs.get(id=form.cleaned_data["organization"])
            except Organization.DoesNotExist:
                errors = form._errors.setdefault("organization", ErrorList())
                errors.append("Invalid organization")
            else:
                jira_auth.update(organization=org)

        context = self.get_context()
        context.update({"is_configured": jira_auth.is_configured(), "form": form})

        return self.get_response("config.html", context)
示例#2
0
    def post(self, request: Request, *args: Any,
             **kwargs: Any) -> HttpResponse:
        try:
            jira_auth = self.get_jira_auth()
        except CATCHABLE_AUTH_ERRORS:
            return self.get_response("error.html")

        if request.user.is_anonymous:
            return self.get_response("signin.html")

        orgs = self.request.user.get_orgs()

        form = JiraConfigForm([(o.id, o.name) for o in orgs],
                              self.request.POST)

        if form.is_valid():
            try:
                org = orgs.get(id=form.cleaned_data["organization"])
            except Organization.DoesNotExist:
                errors = form._errors.setdefault("organization", ErrorList())
                errors.append("Invalid organization")
            else:
                jira_auth.update(organization=org)
                bind_organization_context(org)

        context = self.get_context()
        context.update({
            "is_configured": jira_auth.is_configured(),
            "form": form
        })

        return self.get_response("config.html", context)
示例#3
0
    def post(self, request, *args, **kwargs):
        try:
            jira_auth = get_jira_auth_from_request(request)
        except (ApiError, JiraTenant.DoesNotExist):
            self.get_response('error.html')

        if request.user.is_anonymous():
            return self.get_response('signin.html')

        orgs = self.request.user.get_orgs()

        form = JiraConfigForm([(o.id, o.name) for o in orgs], self.request.POST)

        if form.is_valid():
            try:
                org = orgs.get(id=form.cleaned_data['organization'])
            except Organization.DoesNotExist:
                errors = form._errors.setdefault('organization', ErrorList())
                errors.append('Invalid organization')
            else:
                jira_auth.update(organization=org)

        context = self.get_context()
        context.update({'is_configured': jira_auth.is_configured(), 'form': form})

        return self.get_response('config.html', context)
示例#4
0
    def post(self, request, *args, **kwargs):
        try:
            jira_auth = get_jira_auth_from_request(request)
        except (JIRAError, JiraTenant.DoesNotExist):
            self.get_response('error.html')

        if request.user.is_anonymous():
            return self.get_response('signin.html')

        orgs = self.request.user.get_orgs()

        form = JiraConfigForm([(o.id, o.name) for o in orgs],
                              self.request.POST)

        if form.is_valid():
            try:
                org = orgs.get(id=form.cleaned_data['organization'])
            except Organization.DoesNotExist:
                errors = form._errors.setdefault('organization', ErrorList())
                errors.append('Invalid organization')
            else:
                jira_auth.update(organization=org)

        context = self.get_context()
        context.update({
            'is_configured': jira_auth.is_configured(),
            'form': form
        })

        return self.get_response('config.html', context)