Esempio n. 1
0
 def update(self, new_user):
     self._validate_can_be('updated', new_user)
     try:
         can_have_super_user_access(new_user)
         self.lowercase_user_attributes(new_user)
         self.db.session.merge(new_user)
         self.db.session.commit()
     except IntegrityError as e:
         self.db.session.rollback()
         raise DBIntegrityError(e)
Esempio n. 2
0
 def save(self, user):
     self._validate_can_be('saved', user)
     try:
         can_have_super_user_access(user)
         self.lowercase_user_attributes(user)
         self.db.session.add(user)
         self.db.session.commit()
     except IntegrityError as e:
         self.db.session.rollback()
         raise DBIntegrityError(e)
Esempio n. 3
0
def add_subadmin(user_id=None):
    """Add subadmin flag for user_id."""
    try:
        if user_id:
            user = user_repo.get(user_id)
            if not user:
                return format_error('User not found', 404)

            if not user.enabled:
                markup = Markup('<strong>{}</strong> {} <strong>{}</strong>')
                flash(
                    markup.format(gettext('User account '), user.fullname,
                                  gettext(' is disabled')))
                return redirect(url_for(".subadminusers"))

            if not can_have_super_user_access(user):
                markup = Markup('<strong>{} {}</strong> {} {}')
                flash(
                    markup.format(gettext('Denied subadmin privileges to'),
                                  user.fullname, user.email_addr,
                                  'disqualify for subadmin access.'))
                return redirect_content_type(url_for(".subadminusers"))

            ensure_authorized_to('update', user)
            user.subadmin = True
            user_repo.update(user)
            msg = generate_invitation_email_for_admins_subadmins(
                user, "Subadmin")
            if msg:
                mail_queue.enqueue(send_mail, msg)
            return redirect(url_for(".subadminusers"))

    except Exception as e:  # pragma: no cover
        current_app.logger.error(e)
        return abort(500)