示例#1
0
def admin_edit_group_feed_submit(feed_id):
    """ Submit edit feed form """
    if "cancel" in request.form:
        flash("Edit cancelled!")
        return redirect(url_for("admin_feeds"))

    name = request.form.get('name', '')
    title = request.form.get('title', '')
    script = request.form.get('script', '')
    envvar = request.form.get('envvar', '')
    comments = request.form.get('comments', '')
    freq = int(request.form.get('freq', 1))
    active = request.form.get('active', 'inactive') == 'active'

    if feed_id == 0:  # It's a new one being created
        feed = Feeds.Feed(
            f_id=0,
            name=name,
            title=title,
            script=script,
            envvar=envvar,
            comments=comments,
            freq=freq,
            active=active
        )
    else:
        try:
            feed = Feeds.Feed(f_id=feed_id)
        except KeyError:
            return abort(404)

    feed.id = feed_id
    feed.name = name
    feed.title = title
    feed.script = script
    feed.envvar = envvar
    feed.comments = comments
    feed.freq = freq
    feed.active = active

    if name == "":
        flash("Can't Save: Name must be supplied")
        return render_template(
            "admin_edit_group_feed.html",
            feed=feed
        )

    try:
        feed.save()
    except ValueError as err:  # Probably a duplicate or something
        flash("Can't Save: %s" % err)
        return render_template(
            "admin_edit_group_feed.html",
            feed=feed
        )
    flash("Changes saved", category='success')
    return redirect(url_for("admin_feeds"))
示例#2
0
def group_test_feed_output(group_id):
    """ Run the feed script for the group and return the output or error message.
    """
    error = None
    output = ""
    group = None
    try:
        group = Groups.Group(g_id=group_id)
    except KeyError:
        abort(401)
    if not group.source == "feed":
        abort(401)

    feed = Feeds.Feed(f_id=group.feed)
    period = Periods.Period(p_id=group.period)
    scriptrun = ' '.join([feed.script, group.feedargs, period.code])
    try:
        output = External.feeds_run_group_script(feed.script, args=[group.feedargs, period.code])
    except BaseException as err:
        error = err

    return render_template(
        "admin_test_group_feed.html",
        output=output,
        error=error,
        scriptrun=scriptrun
    )
示例#3
0
def admin_feeds():
    """ Present menu page of enrolment related options """

    feeds = Feeds.all_list()
    return render_template(
        "admin_group_feeds.html",
        feeds=feeds
    )
示例#4
0
def admin_feeds():
    """ Present menu page of enrolment related options """

    feeds = Feeds.all_list()
    return render_template(
        "admin_group_feeds.html",
        feeds=feeds
    )
示例#5
0
def admin_add_group():
    """ Present page to add a group to the system """
    feeds = Feeds.all_list()
    periods = Periods.all_list()
    gtypes = Groups.all_gtypes()
    return render_template(
        "admin_editgroup.html",
        feeds=feeds,
        periods=periods,
        group=Groups.Group(gtype=1),
        gtypes=gtypes
    )
示例#6
0
def admin_add_group():
    """ Present page to add a group to the system """
    feeds = Feeds.all_list()
    periods = Periods.all_list()
    gtypes = Groups.all_gtypes()
    return render_template(
        "admin_editgroup.html",
        feeds=feeds,
        periods=periods,
        group=Groups.Group(gtype=1),
        gtypes=gtypes
    )
示例#7
0
def admin_edit_feed(feed_id):
    """ Present page to edit a feed in the system """
    try:
        feed = Feeds.Feed(f_id=feed_id)
    except KeyError:
        return abort(404)
    try:
        scripts = External.feeds_available_group_scripts()
    except OSError as err:
        flash(err)
        scripts = []
    return render_template(
        "admin_edit_group_feed.html",
        feed=feed,
        scripts=scripts
    )
示例#8
0
def group_update_from_feed(group_id, refresh_users=False):
    """ Update group membership from it's feed
        Returns (added, removed, unknown) with usernames of users
    """
    group = Groups.Group(g_id=group_id)
    if not group.source == 'feed':
        return

    feed = Feeds.Feed(f_id=group.feed)
    scriptrun = ' '.join([feed.script, group.feedargs])
    try:
        output = feeds_run_group_script(feed.script, args=[group.feedargs, ])
    except BaseException as err:
        L.error("Exception in group feed '%s': %s" % (scriptrun, err))
        raise

    removed = []
    added = []
    unknown = []
    old_members = group.member_unames()
    new_members = output.split()[1:]
    for uname in new_members:
        uid = Users2.uid_by_uname(uname)
        if not uid:
            users_update_from_feed([uname, ])
            L.info("Group feed contained unknown user account %s" % uname)
            unknown.append(uname)
            continue
        if uname not in old_members:
            group.add_member(uid)
            added.append(uname)

    for uname in old_members:
        if uname not in new_members:
            uid = Users2.uid_by_uname(uname)
            group.remove_member(uid)
            removed.append(uname)

    if refresh_users:
        for uname in group.member_unames():
            uid = Users2.uid_by_uname(uname)
            user_update_details_from_feed(uid, uname)

    return added, removed, unknown