Пример #1
0
def update_site(site_id):
    new_site = request.json
    # Verify incoming site. It must exist, groups must exist, plans must exist.
    site = sites.find_one({'id': site_id})
    if not site:
        return jsonify(success=False, reason='no-such-site')
    site['groups'] = _find_groups_for_site(site['url'])
    for group in new_site.get('groups', []):
        if not _check_group_exists(group):
            return jsonify(success=False, reason='unknown-group')
    for plan_name in new_site.get('plans', []):
        if not _check_plan_exists(plan_name):
            return jsonify(success=False, reason='unknown-plan')
    if 'groups' in new_site:
        # Add new groups
        for group_name in new_site.get('groups', []):
            if group_name not in site['groups']:
                groups.update({'name':group_name},{'$addToSet': {'sites': site['url']}})
        # Remove old groups
        for group_name in site['groups']:
            if group_name not in new_site.get('groups', []):
                groups.update({'name':group_name},{'$pull': {'sites': site['url']}})
    if 'plans' in new_site:
        # Update the site. At this point we can only update plans.
        sites.update({'id': site_id}, {'$set': {'plans': new_site.get('plans')}})
    # Return the updated site
    site = sites.find_one({'id': site_id})
    if not site:
        return jsonify(success=False, reason='no-such-site')
    site['groups'] = _find_groups_for_site(site['url'])
    return jsonify(success=True, site=sanitize_site(site))
Пример #2
0
def update_site(site_id):
    new_site = request.json
    # Verify incoming site. It must exist, groups must exist, plans must exist.
    site = sites.find_one({"id": site_id})
    if not site:
        return jsonify(success=False, reason="no-such-site")
    site["groups"] = _find_groups_for_site(site["url"])
    for group in new_site.get("groups", []):
        if not _check_group_exists(group):
            return jsonify(success=False, reason="unknown-group")
    for plan_name in new_site.get("plans", []):
        if not _check_plan_exists(plan_name):
            return jsonify(success=False, reason="unknown-plan")
    if "groups" in new_site:
        # Add new groups
        for group_name in new_site.get("groups", []):
            if group_name not in site["groups"]:
                groups.update({"name": group_name}, {"$addToSet": {"sites": site["url"]}})
        # Remove old groups
        for group_name in site["groups"]:
            if group_name not in new_site.get("groups", []):
                groups.update({"name": group_name}, {"$pull": {"sites": site["url"]}})
    if "plans" in new_site:
        # Update the site. At this point we can only update plans.
        sites.update({"id": site_id}, {"$set": {"plans": new_site.get("plans")}})
    # Return the updated site
    site = sites.find_one({"id": site_id})
    if not site:
        return jsonify(success=False, reason="no-such-site")
    site["groups"] = _find_groups_for_site(site["url"])
    return jsonify(success=True, site=sanitize_site(site))
def update_site(site_id):
    new_site = request.json
    # Verify incoming site. It must exist, groups must exist, plans must exist.
    site = sites.find_one({'id': site_id})
    if not site:
        return jsonify(success=False, reason='no-such-site')
    site['groups'] = _find_groups_for_site(site['url'])
    for group in new_site.get('groups', []):
        if not _check_group_exists(group):
            return jsonify(success=False, reason='unknown-group')
    for plan_name in new_site.get('plans', []):
        if not _check_plan_exists(plan_name):
            return jsonify(success=False, reason='unknown-plan')
    if 'groups' in new_site:
        # Add new groups
        for group_name in new_site.get('groups', []):
            if group_name not in site['groups']:
                groups.update({'name': group_name},
                              {'$addToSet': {
                                  'sites': site['url']
                              }})
        # Remove old groups
        for group_name in site['groups']:
            if group_name not in new_site.get('groups', []):
                groups.update({'name': group_name},
                              {'$pull': {
                                  'sites': site['url']
                              }})

    if 'plans' in new_site:
        # Update the site. At this point we can only update plans.
        sites.update({'id': site_id},
                     {'$set': {
                         'plans': new_site.get('plans')
                     }})

    new_verification = new_site['verification']
    old_verification = site.get('verification')
    # if site doesn't have 'verification', do us a favor, update the document as it is outdated!
    if not old_verification or old_verification['enabled'] != new_verification[
            'enabled']:
        # to make logic simpler, even if the new request wants to
        # disable verification, generate a new value anyway.
        sites.update({'id': site_id}, {
            '$set': {
                'verification': {
                    'enabled': new_verification['enabled'],
                    'value': str(uuid.uuid4())
                }
            }
        })

    # Return the updated site
    site = sites.find_one({'id': site_id})
    if not site:
        return jsonify(success=False, reason='no-such-site')
    site['groups'] = _find_groups_for_site(site['url'])
    return jsonify(success=True, site=sanitize_site(site))
Пример #4
0
def delete_invite(id):
    invitation = invites.find_one({'id': id})
    if not invitation:
        return jsonify(success=False, reason='no-such-invitation')
    # do not delete users that are not invite pending (bug #123)
    email = invitation['recipient']
    user = users.find_one({'email': email})
    if user and user.get('status') == "invited":
        users.remove(user)
        # bug #133 delete user associations
        for group_name in _find_groups_for_user(email):
            groups.update({'name':group_name}, {'$pull': {'users': email}})
        for site in _find_sites_for_user(email):
            sites.update({'url':site}, {'$pull': {'users': email}})
    invites.remove({'id': id})
    return jsonify(success=True)
Пример #5
0
def update_site(site_id):
    new_site = request.json
    # Verify incoming site. It must exist, groups must exist, plans must exist.
    site = sites.find_one({'id': site_id})
    if not site:
        return jsonify(success=False, reason='no-such-site')
    site['groups'] = _find_groups_for_site(site['url'])
    for group in new_site.get('groups', []):
        if not _check_group_exists(group):
            return jsonify(success=False, reason='unknown-group')
    for plan_name in new_site.get('plans', []):
        if not _check_plan_exists(plan_name):
            return jsonify(success=False, reason='unknown-plan')
    if 'groups' in new_site:
        # Add new groups
        for group_name in new_site.get('groups', []):
            if group_name not in site['groups']:
                groups.update({'name':group_name},{'$addToSet': {'sites': site['url']}})
        # Remove old groups
        for group_name in site['groups']:
            if group_name not in new_site.get('groups', []):
                groups.update({'name':group_name},{'$pull': {'sites': site['url']}})

    if 'plans' in new_site:
        # Update the site. At this point we can only update plans.
        sites.update({'id': site_id}, {'$set': {'plans': new_site.get('plans')}})

    new_verification = new_site['verification']
    old_verification = site.get('verification')
    # if site doesn't have 'verification', do us a favor, update the document as it is outdated!
    if not old_verification or old_verification['enabled'] != new_verification['enabled']:
        # to make logic simpler, even if the new request wants to
        # disable verification, generate a new value anyway.
        sites.update({'id': site_id},
            {'$set': {
                 'verification': {
                    'enabled': new_verification['enabled'],
                    'value': str(uuid.uuid4())}}})

    # Return the updated site
    site = sites.find_one({'id': site_id})
    if not site:
        return jsonify(success=False, reason='no-such-site')
    site['groups'] = _find_groups_for_site(site['url'])
    return jsonify(success=True, site=sanitize_site(site))