Exemple #1
0
def aerobia(req):
    if not req.user:
        return HttpResponse(status=403)
    conn = User.GetConnectionRecord(req.user, "aerobia")

    config = conn.GetConfiguration()
    gearRules = config["gearRules"] if "gearRules" in config else []
    props = {
        'aerobiaId': conn.ExternalID,
        'userToken': conn.Authorization["OAuthToken"],
        'sportTypes': conn.Service.SupportedActivities,
        'config': {
            'gearRules': gearRules
        }
    }

    if req.method == "POST":
        form = AerobiaConfigForm(req.POST)
        if form.is_valid():
            configRaw = req.POST.get('config')
            config = json.loads(configRaw)
            conn.SetConfiguration(config)
            return redirect("dashboard")

    return render(req, "config/aerobia.html", {'props': props})
Exemple #2
0
def sync_clear_errorgroup(req, service, group):
    if not req.user:
        return HttpResponse(status=401)

    rec = User.GetConnectionRecord(req.user, service)
    if not rec:
        return HttpResponse(status=404)

    # Prevent this becoming a vehicle for rapid synchronization
    to_clear_count = 0
    for x in rec.SyncErrors:
        if "UserException" in x and "ClearGroup" in x["UserException"] and x[
                "UserException"]["ClearGroup"] == group:
            to_clear_count += 1

    if to_clear_count > 0:
        db.connections.update(
            {"_id": rec._id},
            {"$pull": {
                "SyncErrors": {
                    "UserException.ClearGroup": group
                }
            }})
        db.users.update(
            {"_id": req.user["_id"]},
            {'$inc': {
                "BlockingSyncErrorCount": -to_clear_count
            }}
        )  # In the interests of data integrity, update the summary counts immediately as opposed to waiting for a sync to complete.
        Sync.ScheduleImmediateSync(
            req.user, True
        )  # And schedule them for an immediate full resynchronization, so the now-unblocked services can be brought up to speed.            return HttpResponse()
        return HttpResponse()

    return HttpResponse(status=404)
Exemple #3
0
def config_save(req, service):
    if not req.user:
        return HttpResponse(status=403)

    conn = User.GetConnectionRecord(req.user, service)
    if not conn:
        return HttpResponse(status=404)
    conn.SetConfiguration(json.loads(req.POST["config"]))
    return HttpResponse()
def js_bridge(req):
    serviceInfo = {}

    for svc in Service.List():
        if svc.ID in WITHDRAWN_SERVICES:
            continue
        if req.user is not None:
            svcRec = User.GetConnectionRecord(
                req.user,
                svc.ID)  # maybe make the auth handler do this only once?
        else:
            svcRec = None
        info = {
            "DisplayName": svc.DisplayName,
            "DisplayAbbreviation": svc.DisplayAbbreviation,
            "AuthenticationType": svc.AuthenticationType,
            "UsesExtendedAuth": svc.RequiresExtendedAuthorizationDetails,
            "AuthorizationURL": svc.UserAuthorizationURL,
            "NoFrame": svc.AuthenticationNoFrame,
            "ReceivesActivities": svc.ReceivesActivities,
            "Configurable": svc.Configurable,
            "RequiresConfiguration": False  # by default
        }
        if svcRec:
            if svc.Configurable:
                if svc.ID == "dropbox":  # dirty hack alert, but better than dumping the auth details in their entirety
                    info["AccessLevel"] = "full" if svcRec.Authorization[
                        "Full"] else "normal"
                    info["RequiresConfiguration"] = svc.RequiresConfiguration(
                        svcRec)
            info["Config"] = svcRec.GetConfiguration()
            info["HasExtendedAuth"] = svcRec.HasExtendedAuthorizationDetails()
            info[
                "PersistedExtendedAuth"] = svcRec.HasExtendedAuthorizationDetails(
                    persisted_only=True)
            info["ExternalID"] = svcRec.ExternalID
        info["BlockFlowTo"] = []
        info["Connected"] = svcRec is not None
        serviceInfo[svc.ID] = info
    if req.user is not None:
        flowExc = User.GetFlowExceptions(req.user)
        for exc in flowExc:
            if exc["Source"]["Service"] not in serviceInfo or exc["Target"][
                    "Service"] not in serviceInfo:
                continue  # Withdrawn services
            if "ExternalID" in serviceInfo[exc["Source"][
                    "Service"]] and exc["Source"]["ExternalID"] != serviceInfo[
                        exc["Source"]["Service"]]["ExternalID"]:
                continue  # this is an old exception for a different connection
            if "ExternalID" in serviceInfo[exc["Target"][
                    "Service"]] and exc["Target"]["ExternalID"] != serviceInfo[
                        exc["Target"]["Service"]]["ExternalID"]:
                continue  # same as above
            serviceInfo[exc["Source"]["Service"]]["BlockFlowTo"].append(
                exc["Target"]["Service"])
    return {"js_bridge_serviceinfo": json.dumps(serviceInfo)}
Exemple #5
0
def config_save(req, service):
    if not req.user:
        return HttpResponse(status=403)

    conn = User.GetConnectionRecord(req.user, service)
    if not conn:
        return HttpResponse(status=404)
    conn.SetConfiguration(json.loads(req.POST["config"]))
    Sync.SetNextSyncIsExhaustive(req.user, True) # e.g. if they opted to sync private activities.
    return HttpResponse()
Exemple #6
0
def dropbox(req):
    if not req.user:
        return HttpResponse(status=403)
    conn = User.GetConnectionRecord(req.user, "dropbox")
    if req.method == "POST":
        form = DropboxConfigForm(req.POST)
        if form.is_valid():
            conn.SetConfiguration({"SyncRoot": form.cleaned_data['path'], "UploadUntagged": form.cleaned_data['syncUntagged']})
            return redirect("dashboard")
    else:
        conf = conn.GetConfiguration()
        form = DropboxConfigForm({"path": conf["SyncRoot"], "syncUntagged": conf["UploadUntagged"]})
    return render(req, "config/dropbox.html", {"form": form})
Exemple #7
0
def browse(req, path="/"):

    if req.user is None:
        return HttpResponse(status=403)
    svcRec = User.GetConnectionRecord(req.user, "dropbox")
    dbSvc = Service.FromID("dropbox")
    dbCl = dbSvc._getClient(svcRec)
    metadata = dbCl.metadata(path)
    folders = []
    for item in metadata["contents"]:
        if item["is_dir"] is False:
            continue
        folders.append(item["path"])
    return HttpResponse(json.dumps(folders), content_type='application/json')
Exemple #8
0
 def Execute(self):
     logger.info("Starting rollback %s" % self._id)
     deletion_status = {}
     user = User.Get(self.UserID)
     for svc_id, upload_ids in self.PendingDeletions.items():
         svcrec = User.GetConnectionRecord(user, svc_id)
         deletion_status[svc_id] = {}
         if not svcrec.Service.SupportsActivityDeletion:
             continue
         for upload_id in upload_ids:
             logger.info("Deleting activity %s on %s" % (upload_id, svc_id))
             try:
                 svcrec.Service.DeleteActivity(svcrec, upload_id)
             except Exception as e:
                 deletion_status[svc_id][str(upload_id)] = False
                 logger.exception("Deletion failed - %s" % e)
             else:
                 deletion_status[svc_id][str(upload_id)] = True
             db.rollback_tasks.update_one({"_id": self._id}, {"$set": {"DeletionStatus": deletion_status}})
     logger.info("Finished rollback %s" % self._id)
Exemple #9
0
def browse(req, path="/"):
    if req.user is None:
        return HttpResponse(status=403)
    if path == "/":
        path = ""
    svcRec = User.GetConnectionRecord(req.user, "dropbox")
    dbSvc = Service.FromID("dropbox")
    dbCl = dbSvc._getClient(svcRec)

    folders = []
    result = dbCl.files_list_folder(path)
    while True:
        # There's no actual way to filter for folders only :|
        folders += [x.path_lower for x in result.entries if not hasattr(x, "rev")]
        if result.has_more:
            result = dbCl.files_list_folder_continue(result.cursor)
        else:
            break

    return HttpResponse(json.dumps(folders), content_type='application/json')