Beispiel #1
0
    def validate_name(self, field):
        if hasattr(self, "group"):
            group = jnt_models.Group.query.filter(
                db.and_(
                    jnt_models.Group.name.like(field.data),
                    db.not_(jnt_models.Group.id == self.group.id)
                )
            ).first()
        else:
            group = jnt_models.Group.query.filter(jnt_models.Group.name.like(field.data)).first()

        if group:
            raise ValidationError(_("This Group name is already taken."))
Beispiel #2
0
    def validate_guest(self, field):
        if hasattr(self, "group"):
            group = jnt_models.Group.query.filter(
                db.and_(
                    jnt_models.Group.guest,
                    db.not_(jnt_models.Group.id == self.group.id)
                )
            ).count()
        else:
            group = jnt_models.Group.query.filter_by(guest=True).count()

        if field.data and group > 0:
            raise ValidationError(_("There is already a Guest group."))
Beispiel #3
0
    def validate_email(self, field):
        if hasattr(self, "user"):
            user = jnt_models.User.query.filter(
                db.and_(
                    jnt_models.User.email.like(field.data),
                    db.not_(User.id == self.user.id)
                )
            ).first()
        else:
            user = jnt_models.User.query.filter(jnt_models.User.email.like(field.data)).first()

        if user:
            raise ValidationError(_("This E-Mail Address is already taken."))
Beispiel #4
0
def edit_user(user_id):
    user = jnt_models.User.query.filter_by(id=user_id).first_or_404()

    if not can_edit_user(current_user):
        flash(_("You are not allowed to edit this user."), "danger")
        return redirect(url_for("management.users"))

    member_group = db.and_(
        *[db.not_(getattr(jnt_models.Group, p)) for p in ["admin", "mod", "super_mod", "banned", "guest"]]
    )

    filt = db.or_(jnt_models.Group.id.in_(g.id for g in user.groups), member_group)

    if any(user.permissions[p] for p in ["super_mod", "admin"]):
        filt = db.or_(filt, jnt_models.Group.mod)

    if user.permissions["admin"]:
        filt = db.or_(filt, jnt_models.Group.admin, jnt_models.Group.super_mod)

    group_query = jnt_models.Group.query.filter(filt)

    form = EditUserForm(user)
    form.primary_group.query = group_query
    form.secondary_groups.query = group_query
    if form.validate_on_submit():
        form.populate_obj(user)
        user.primary_group_id = form.primary_group.data.id

        # Don't override the password
        if form.password.data:
            user.password = form.password.data

        user.save(groups=form.secondary_groups.data)

        flash(_("User successfully updated."), "success")
        return redirect(url_for("management.edit_user", user_id=user.id))

    return render_template("management/user_form.html", form=form, title=_("Edit User"))
Beispiel #5
0
 def validate_email(self, field):
     user = UserMan.query.filter(db.and_(
                              UserMan.email.like(field.data),
                              db.not_(UserMan.id == self.user.id))).first()
     if user:
         raise ValidationError(_("This E-Mail Address is already taken."))