예제 #1
0
    def import_status(self, taskid):
        "import status"
        result = AsyncResult(taskid)
        if result is None or taskid not in session['taskids']:
            msg = _('The task status requested has expired or does not exist')
            flash(msg)
            log.info(msg)
            redirect(url(controller='accounts', action='index'))

        if result.ready():
            finished = True
            flash.pop_messages()
            if isinstance(result.result, Exception):
                if c.user.is_superadmin:
                    msg = _('Error occured in processing %s') % result.result
                    flash_alert(msg)
                    log.info(msg)
                else:
                    flash_alert(_('Backend error occured during processing.'))
                redirect(url(controller='accounts'))
            backend_user_update(None, True)
            audit_log(c.user.username,
                    3, unicode(auditmsgs.ACCOUNTIMPORT_MSG),
                    request.host,
                    request.remote_addr,
                    arrow.utcnow().datetime)
        else:
            session['acimport-count'] += 1
            if (session['acimport-count'] >= 10 and
                result.state in ['PENDING', 'RETRY', 'FAILURE']):
                result.revoke()
                try:
                    os.unlink(session['acimport-file'])
                except OSError:
                    pass
                del session['acimport-count']
                session.save()
                msg = _('The import could not be processed,'
                        ' try again later')
                flash_alert(msg)
                log.info(msg)
                redirect(url(controller='accounts'))
            finished = False

        c.finished = finished
        c.results = result.result
        c.success = result.successful()
        return self.render('/accounts/importstatus.html')
예제 #2
0
    def import_status(self, taskid):
        "import status"
        result = AsyncResult(taskid)
        if result is None or taskid not in session['taskids']:
            msg = _('The task status requested has expired or does not exist')
            flash(msg)
            log.info(msg)
            redirect(url(controller='accounts', action='index'))

        if result.ready():
            finished = True
            flash.pop_messages()
            if isinstance(result.result, Exception):
                if c.user.is_superadmin:
                    msg = _('Error occured in processing %s') % result.result
                    flash_alert(msg)
                    log.info(msg)
                else:
                    flash_alert(_('Backend error occured during processing.'))
                redirect(url(controller='accounts'))
            backend_user_update(None, True)
            audit_log(c.user.username, 3, unicode(auditmsgs.ACCOUNTIMPORT_MSG),
                      request.host, request.remote_addr,
                      arrow.utcnow().datetime)
        else:
            session['acimport-count'] += 1
            if (session['acimport-count'] >= 10
                    and result.state in ['PENDING', 'RETRY', 'FAILURE']):
                result.revoke()
                try:
                    os.unlink(session['acimport-file'])
                except OSError:
                    pass
                del session['acimport-count']
                session.save()
                msg = _('The import could not be processed,'
                        ' try again later')
                flash_alert(msg)
                log.info(msg)
                redirect(url(controller='accounts'))
            finished = False

        c.finished = finished
        c.results = result.result
        c.success = result.successful()
        return self.render('/accounts/importstatus.html')
예제 #3
0
    def confirm_delete(self):
        "Confirm mass delete"
        accountids = session.get('bulk_account_delete', [])
        if not accountids:
            redirect(url(controller='accounts', action='index'))

        num_items = 10
        if len(accountids) > num_items and len(accountids) <= 20:
            num_items = 20
        if len(accountids) > num_items and len(accountids) <= 50:
            num_items = 50
        if len(accountids) > num_items and len(accountids) <= 100:
            num_items = 100

        users = Session.query(User).filter(User.id.in_(accountids))
        usrcount = Session.query(User.id)

        if c.user.is_domain_admin and usrcount:
            users = users.join(domain_users, (dom_owns,
                    domain_users.c.domain_id == dom_owns.c.domain_id),
                    (oas, dom_owns.c.organization_id == oas.c.organization_id))\
                    .filter(oas.c.user_id == c.user.id)
            usrcount = usrcount.join(domain_users, (dom_owns,
                        domain_users.c.domain_id == dom_owns.c.domain_id),
                        (oas, dom_owns.c.organization_id ==
                        oas.c.organization_id))\
                        .filter(oas.c.user_id == c.user.id)

        if request.method == 'POST':
            tasks = []
            # try:
            for account in users.all():
                info = auditmsgs.DELETEACCOUNT_MSG % dict(u=account.username)
                Session.delete(account)
                tasks.append([
                    c.user.username, 4,
                    unicode(info), request.host, request.remote_addr,
                    arrow.utcnow().datetime
                ])
            Session.commit()
            del session['bulk_account_delete']
            session.save()
            backend_user_update(None, True)
            for task in tasks:
                audit_log(*task)
            flash(_('The accounts have been deleted'))
            redirect(url(controller='accounts'))
        else:
            flash(
                _('The following accounts are about to be deleted,'
                  ' this action is not reversible, Do you wish to '
                  'continue ?'))

        try:
            c.page = paginate.Page(users,
                                   page=1,
                                   items_per_page=num_items,
                                   item_count=usrcount.count())
        except DataError:
            msg = _('An error occured try again')
            flash_alert(msg)
            log.info(msg)
            redirect(url(controller='accounts', action='index'))
        return self.render('/accounts/confirmbulkdel.html')
예제 #4
0
    def confirm_delete(self):
        "Confirm mass delete"
        accountids = session.get('bulk_account_delete', [])
        if not accountids:
            redirect(url(controller='accounts', action='index'))

        num_items = 10
        if len(accountids) > num_items and len(accountids) <= 20:
            num_items = 20
        if len(accountids) > num_items and len(accountids) <= 50:
            num_items = 50
        if len(accountids) > num_items and len(accountids) <= 100:
            num_items = 100

        users = Session.query(User).filter(User.id.in_(accountids))
        usrcount = Session.query(User.id)

        if c.user.is_domain_admin and usrcount:
            users = users.join(domain_users, (dom_owns,
                    domain_users.c.domain_id == dom_owns.c.domain_id),
                    (oas, dom_owns.c.organization_id == oas.c.organization_id))\
                    .filter(oas.c.user_id == c.user.id)
            usrcount = usrcount.join(domain_users, (dom_owns,
                        domain_users.c.domain_id == dom_owns.c.domain_id),
                        (oas, dom_owns.c.organization_id ==
                        oas.c.organization_id))\
                        .filter(oas.c.user_id == c.user.id)

        if request.method == 'POST':
            tasks = []
            # try:
            for account in users.all():
                info = auditmsgs.DELETEACCOUNT_MSG % dict(u=account.username)
                Session.delete(account)
                tasks.append([c.user.username,
                            4,
                            unicode(info),
                            request.host,
                            request.remote_addr,
                            arrow.utcnow().datetime])
            Session.commit()
            del session['bulk_account_delete']
            session.save()
            backend_user_update(None, True)
            for task in tasks:
                audit_log(*task)
            flash(_('The accounts have been deleted'))
            redirect(url(controller='accounts'))
        else:
            flash(_('The following accounts are about to be deleted,'
                    ' this action is not reversible, Do you wish to '
                    'continue ?'))

        try:
            c.page = paginate.Page(users, page=1,
                                    items_per_page=num_items,
                                    item_count=usrcount.count())
        except DataError:
            msg = _('An error occured try again')
            flash_alert(msg)
            log.info(msg)
            redirect(url(controller='accounts', action='index'))
        return self.render('/accounts/confirmbulkdel.html')