Example #1
0
    def submit(self):
        token = token_generation()
        orgname = self.data["orgname"]
        orgurl = self.data["orgurl"]
        # why are those two fields not in 'cleaned data'?
        status = self.cleaned_data["status"]
        domain = self.data["orgdomain"]
        url = f"{settings.INSTANCE}api/4/organisations"
        headers = {
            "Authorization": f"Bearer {token}",
            "Accept": "application/json",
            "Content-Type": "application/json",
        }
        payload = json.dumps(
            {
                "name": orgname,
                "status": status,
                "url": orgurl
            }
        )  # we are using dumps here because endpoint only accepts strings in json in double quotes
        response = requests.post(url, headers=headers, data=payload)

        if response.status_code == 200 or response.status_code == 201:
            result = response.json()
            result["success"] = True
            result["message"] = "New Org Created"

            orgid = result["orgid"]
            url = f"{settings.INSTANCE}api/4/domains?orgid={orgid}"
            token2 = token_generation()
            headers = {
                "Authorization": f"Bearer {token}",
                "Accept": "application/json",
                "Content-Type": "application/json",
            }
            payload = json.dumps({"url": domain, "status": "active"})
            response = requests.post(url, headers=headers, data=payload)

            if response.status_code == 200 or response.status_code == 201:
                result["domainresult"] = response.json()
                result["message"] = "New Org And Domain Created"

            else:
                result["success"] = False
                result[
                    "message"] = "Created the domain but failed to create an org"

        else:
            result = {}
            result["success"] = False
            result["message"] = "Failed to create an Org"

        return result
Example #2
0
    def send(self):
        token = token_generation()
        email_message = self.cleaned_data["email_message"]
        user_id = self.cleaned_data["user_id"]
        site_id = self.cleaned_data["site_id"]
        url = f"{settings.INSTANCE}api/3/sites/{site_id}/users/email"
        headers = {
            "Authorization": f"Bearer {token}",
            "Content-Type": "application/xml",
            "Accept": "application/json",
        }
        payload = (
            # For some reason this endpoint doesnt accept json
            """<?xml version="1.0" encoding="UTF-8" standalone="no" ?><emailusers><emailsubject>"""
            f""""Message From HighQ Sys Admin App</emailsubject><messagebody><![CDATA[{email_message}]]>"""
            f"""</messagebody><transactionids><transactionid>{user_id}</transactionid></transactionids>"""
            """</emailusers>"""
        )
        response = requests.put(url, headers=headers, data=payload)

        result = response.json()
        result["success"] = True
        result["message"] = result["transaction"][0]["reason"]
        result["apistatuscode"] = result["transaction"][0]["statuscode"]

        return result
Example #3
0
    def get(self, request):
        token = token_generation()
        user_id = request.GET.get("user_id", "")
        site_id = request.GET.get("site_id", "")
        user_id = int(user_id)
        url = f"{settings.INSTANCE}api/3/sites/{site_id}/users/invitation"
        headers = {
            "Authorization": f"Bearer {token}",
            "Content-Type": "application/xml",
            "Accept": "application/json",
        }
        payload = (
            # another endpoint not accpeting json
            """<?xml version="1.0" encoding="UTF-8" standalone="no" ?><invitations><messagebody>"""
            """<![CDATA[Site Invite Via HighQ Sys Admin App]]></messagebody><transactionids>"""
            f"""<transactionid>{user_id}</transactionid></transactionids></invitations>"""
        )
        response = requests.put(url, headers=headers, data=payload)

        result = response.json()
        result["success"] = True
        result["message"] = result["transaction"][0]["reason"]
        result["apistatuscode"] = result["transaction"][0]["statuscode"]

        return JsonResponse(result)
Example #4
0
 def get(self, request, pk, post):
     token = token_generation()
     site_id = request.GET.get("siteid", "")
     url = f"{settings.INSTANCE}api/3/tasks/lists?siteid={site_id}"
     headers = {
         "Authorization": f"Bearer {token}",
         "Accept": "application/json",
     }
     response = requests.get(url, headers=headers)
     if response.status_code == 200:
         result = response.json()
         return JsonResponse(result)
Example #5
0
def get_sites_with_tasks():
    token = token_generation()
    url = f"{settings.INSTANCE}api/4/sites?"
    headers = {
        "Authorization": f"Bearer {token}",
        "Accept": "application/json",
    }
    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        result = response.json()
        # make result a list of tuples
        result = result["site"]
        list = [("", "")]
        for i in result:
            if i["module"]["task"]["enable"] == "1":
                list.append((i["id"], i["sitename"]))
        return list
Example #6
0
    def search(self):
        token = token_generation()
        try:
            orgname = self.data["orgname"]
        except MultiValueDictKeyError:
            orgname = None
        try:
            domainname = self.data["domainname"]
        except MultiValueDictKeyError:
            domainname = None
            pass
        # why are those two fields not in 'cleaned data'?
        status = self.cleaned_data["status"]
        if not orgname:
            url = f"{settings.INSTANCE}api/4/organisations?domain={domainname}&status={status}"
        elif not domainname:
            url = f"{settings.INSTANCE}api/4/organisations?searchTxt={orgname}&status={status}"
        else:
            url = f"{settings.INSTANCE}api/4/organisations?searchTxt={orgname}&domain={domainname}&status={status}"

        headers = {
            "Authorization": f"Bearer {token}",
            "Accept": "application/json",
        }
        response = requests.get(url, headers=headers)

        if response.status_code == 200:
            result = response.json()
            result["success"] = True
            empty_check = result["organisation"]

            if is_empty(empty_check):
                result[
                    "message"] = "No orgs returned for any of the search criteria"
                result["empty_check"] = True
            else:
                result["empty_check"] = False

        else:
            result = {}
            result["success"] = False
            result[
                "message"] = "The Config of this App or the API it consumes, currently has an issue."

        return result
Example #7
0
    def search(self):
        token = token_generation()
        email = self.cleaned_data["email"]
        url = f"{settings.INSTANCE}api/6/users/{email}?type=email"
        headers = {
            "Authorization": f"Bearer {token}",
            "Accept": "application/json",
        }
        response = requests.get(url, headers=headers)

        if response.status_code == 200:
            result = response.json()
            result["success"] = True

        if response.status_code == 403:
            result = response.json()
            result["success"] = False

        return result
Example #8
0
    def post(self, request, pk, post):

        task = get_object_or_404(Task, pk=pk)
        form = TaskCollabPushForm(request.POST)

        def get_context_data(self, **kwargs):
            context = super().get_context_data(**kwargs)
            context["nav"] = "tasks"
            return context

        if form:
            task_list_id = form.data["task_list"]
            site_id = form.data["site"]
            url = f"{settings.INSTANCE}api/3/tasks?tasklistid={task_list_id}"

            payload = json.dumps(
                {
                    "title": task.subject,
                    "description": task.body,
                    "priority": {"priorityid": 1},
                    "status": {"statusid": get_task_status(site_id)},
                    "startdate": task.created.__str__(),
                    "tags": {"tag": [{"tagname": "Pushed From HighQSysAdminApp"}]},
                }
            )
            # we create the token later
            token = token_generation()
            headers = {
                "Authorization": f"Bearer {token}",
                "Accept": "application/json",
                "Content-Type": "application/json",
            }
            response = requests.post(url, headers=headers, data=payload)

            if response.status_code == 200 or response.status_code == 201:
                task.ispushed = True
                task.save()
                create_action(request.user, "just pushed a task to collaborate:", task)
                messages.success(request, "Task Successfully Pushed To Collaborate")
                return redirect("tasks:task_list")
            else:
                messages.error(request, "Task Successfully Pushed To Collaborate")
                return redirect("tasks:task_list")
Example #9
0
def get_task_status(site_id):

    token = token_generation()
    siteid = site_id
    url = f"{settings.INSTANCE}api/3/tasks/status?siteid={siteid}"
    headers = {
        "Authorization": f"Bearer {token}",
        "Accept": "application/json",
        "Content-Type": "application/json",
    }

    response = requests.get(url, headers=headers)

    if response.status_code == 200:
        result = response.json()
        status = result["status"][0]["statusid"]
        return status
    else:
        return siteid
Example #10
0
    def search(self):
        token = token_generation()
        sitename = self.cleaned_data["sitename"]
        url = f"{settings.INSTANCE}api/6/sites/?name={sitename}"
        headers = {
            "Authorization": f"Bearer {token}",
            "Accept": "application/json",
        }
        response = requests.get(url, headers=headers)

        if response.status_code == 200:
            result = response.json()
            result["success"] = True
            empty_check = result["site"]

            # calculate the percentage of the site size taken up by deleted items
            for i in result["site"]:
                if i["rawsitesize"]["totalsize"] > 0:
                    deleteddoc = i["rawsitesize"]["deleteddocumentsize"]
                    total = i["rawsitesize"]["totalsize"]
                    # work out how to deal with 0 division.
                    percentage_deleted = (deleteddoc / total) * 100
                    percentage_deleted = round(percentage_deleted, 2)
                    i["percentage_deleted"] = percentage_deleted
                else:
                    i["percentage_deleted"] = 0.00

            if is_empty(empty_check):
                result["message"] = "No sites returned for %s" % sitename
                result["empty_check"] = True
            else:
                result["empty_check"] = False

        else:
            result = {}
            result["success"] = False
            result[
                "message"
            ] = "The Config of this App or the API it consumes, currently has an issue."

        return result
Example #11
0
    def get(self, request):
        token = token_generation()
        user_id = request.GET.get("user_id", "")
        site_id = request.GET.get("site_id", "")
        user_id = int(user_id)
        url = f"{settings.INSTANCE}api/3/sites/{site_id}/users"
        headers = {
            "Authorization": f"Bearer {token}",
            "Content-Type": "application/xml",
            "Accept": "application/json",
        }
        payload = (
            # for some reason this endpoint wasnt accpeting json at the time of coding
            """<?xml version="1.0" encoding="UTF-8" standalone="no" ?><transactionids><transactionid>"""
            f"""{user_id}</transactionid></transactionids>"""
        )
        response = requests.delete(url, headers=headers, data=payload)

        result = response.json()
        result["success"] = True
        result["message"] = result["transaction"][0]["reason"]
        result["apistatuscode"] = result["transaction"][0]["statuscode"]

        return JsonResponse(result)