Ejemplo n.º 1
0
def dismiss_notification(nid):
    n = Notification.get(Notification.id == nid)
    if g.team != n.team:
        code, message = NOTIFICATION_NOT_YOURS
    else:
        Notification.delete().where(Notification.id == nid).execute()
        code, message = SUCCESS
    return jsonify(dict(code=code, message=message))
Ejemplo n.º 2
0
def dismiss_notification(nid):
    n = Notification.get(Notification.id == nid)
    if g.team != n.team:
        code, message = NOTIFICATION_NOT_YOURS
    else:
        Notification.delete().where(Notification.id == nid).execute()
        code, message = SUCCESS
    return jsonify(dict(code=code, message=message))
Ejemplo n.º 3
0
def notify(msg, room_id, site) -> str:
    chat_host = msg.room._client.host
    user_id = msg.owner.id

    Notification.create(chat_site_url=chat_host,
                        chat_user_id=user_id,
                        room_id=room_id,
                        site_url=site)

    return "You will now be notified of reports on `{}`, in room {} on chat.{}.".format(
        site, room_id, chat_host)
Ejemplo n.º 4
0
def new_notification(body):
    """ Sends a new notification to a user """
    noti = Notification()
    noti.user_id = body['user_id']

    try:
        sent_on = parser.isoparse(body['sent_on'])

        if sent_on > datetime.datetime.now():
            return make_error("Invalid sent_on date"), 400

        noti.sent_on = parser.isoparse(body['sent_on'])
    except ValueError:
        return make_error("Invalid sent_on date"), 400

    if 'read_on' in body:
        try:
            read_on = parser.isoparse(body['read_on'])

            if read_on > datetime.datetime.now() or read_on < noti.sent_on:
                return make_error("Invalid read_on date"), 400

            noti.read_on = read_on
        except ValueError:
            return make_error("Invalid read_on date"), 400

    noti.content = body['content']

    db.session.add(noti)
    db.session.commit()

    return noti.serialize(), 201
Ejemplo n.º 5
0
def scoreboard_variables():
    var = dict(config=config)
    if "team_id" in session:
        var["logged_in"] = True
        var["team"] = g.team
        var["notifications"] = Notification.select().where(Notification.team == g.team)
    else:
        var["logged_in"] = False
        var["notifications"] = []

    return var
Ejemplo n.º 6
0
def scoreboard_variables():
    var = dict(config=config)
    if "team_id" in session:
        var["logged_in"] = True
        var["team"] = g.team
        var["notifications"] = Notification.select().where(
            Notification.team == g.team)
    else:
        var["logged_in"] = False
        var["notifications"] = []

    return var
Ejemplo n.º 7
0
def scoreboard_variables():
    var = dict(config=config)
    var["user_teamed"] = False     #user_teamed用户属于某个队伍
    var["user_requested"] = False   #user_requested用户申请加入某个队伍
    var["team_requested"] = False   #team_requested用户申请创建某个队伍
    if "user_id" in session:
        var["logged_in"] = True
        var["user"] = g.user
        try:
            if (TeamMember.get(TeamMember.member == g.user.id).member_confirmed):
                var["user_teamed"] = True
        except:
            var["user_teamed"] = False
        try:
            if (not TeamMember.get(TeamMember.member == g.user.id).member_confirmed):
                var["user_requested"] = True
        except:
            var["user_requested"] = False
        try:
            if (not Team.get(Team.team_leader == g.user.id).team_confirmed):
                var["team_requested"] = True
        except:
            var["team_requested"] = False
    else:
        var["logged_in"] = False
        var["notifications"] = []

    if "team_id" in session:
        g.team = Team.get(Team.id == session["team_id"])
        var["team"] = g.team
        if (g.user.id == g.team.team_leader.id):
            var["user_leader"] = True        #用户是队长
        else:
            var["user_leader"] = False
        var["notifications"] = Notification.select().where(Notification.team == g.team)
    else:
        var["notifications"] = []
    return var
Ejemplo n.º 8
0
def admin_ticket_comment(ticket):
    ticket = TroubleTicket.get(TroubleTicket.id == ticket)
    if request.form["comment"]:
        TicketComment.create(ticket=ticket, comment_by=session["admin"], comment=request.form["comment"], time=datetime.now())
        Notification.create(team=ticket.team, notification="A response has been added for {}.".format(make_link("ticket #{}".format(ticket.id), url_for("team_ticket_detail", ticket=ticket.id))))
        flash("Comment added.")

    if ticket.active and "resolved" in request.form:
        ticket.active = False
        ticket.save()
        Notification.create(team=ticket.team, notification="{} has been marked resolved.".format(make_link("Ticket #{}".format(ticket.id), url_for("team_ticket_detail", ticket=ticket.id))))
        flash("Ticket closed.")

    elif not ticket.active and "resolved" not in request.form:
        ticket.active = True
        ticket.save()
        Notification.create(team=ticket.team, notification="{} has been reopened.".format(make_link("Ticket #{}".format(ticket.id), url_for("team_ticket_detail", ticket=ticket.id))))
        flash("Ticket reopened.")

    return redirect(url_for(".admin_ticket_detail", ticket=ticket.id))