Пример #1
0
def block(cm_id, caller_id, user_id, wi_data, block):
    """
    @clmview_admin_clm
    @parameter{wi_data,dict} fields: 'site_name'
    @parameter{block,bool} whether to block or unblock.
    """
    user = User.get(user_id)

    if block:
        if user.is_active == user_active_states['ok'] or user.is_active == user_active_states['email_confirmed']:
            user.is_active = user_active_states['blocked']
        else:
            raise CLMException('user_state')
    else:
        if user.is_active == user_active_states['blocked']:
            user.is_active = user_active_states['ok']
        else:
            raise CLMException('user_state')

    try:
        user.save()
    except Exception:
        raise CLMException('user_block' if block else 'user_unblock')

    if settings.MAILER_ACTIVE:
        try:
            mail.send_block_email(user, block, wi_data)
        except Exception, e:
            log.error(caller_id, "Cannot send block/unblock email: %s" % str(e))
Пример #2
0
 def wrap(request, *args, **kwds):
     try:
         return f(request, *args, **kwds)
     except SMTPRecipientsRefused, e:
         error = "%s %s" % (f.__name__, str(e))
         log.error(0, error)
         raise
Пример #3
0
 def wrap(request, *args, **kwds):
     try:
         return f(request, *args, **kwds)
     except SMTPRecipientsRefused, e:
         error = "%s %s" % (f.__name__, str(e))
         log.error(0, error)
         raise
Пример #4
0
def render_from_template_to_string(template_filename, ctx_dict={}):
    """
    @parameter{template_filename,string} path to template of the email
    @parameter{ctx_dict,dict} params to be filled in the email

    Renders strings which can be sent as email contents (basing on template and
    data to be filled in).

    @raises{clm_template_create,CLMException}
    """
    try:
        template = loader.get_template(template_filename)
    except Exception, e:
        log.error(0, "Cannot load template. Error: %s" % str(e))
        raise CLMException('clm_template_create')
Пример #5
0
def render_from_template_to_string(template_filename, ctx_dict={}):
    """
    @parameter{template_filename,string} path to template of the email
    @parameter{ctx_dict,dict} params to be filled in the email

    Renders strings which can be sent as email contents (basing on template and
    data to be filled in).

    @raises{clm_template_create,CLMException}
    """
    try:
        template = loader.get_template(template_filename)
    except Exception, e:
        log.error(0, "Cannot load template. Error: %s" % str(e))
        raise CLMException('clm_template_create')
Пример #6
0
def block(cm_id, caller_id, user_id, wi_data, block):
    """
    Block/unblocks User account. User should not and cannot be deleted. For
    technical and legal reasons in order to restrict its access to CC1 Cloud
    it should only be blocked. That way blocked User's data and activities
    stay stored in database. In case of detection of any suspicious / illegal
    activity performed on blocked User's Virtual Machine or using its
    Public IP, that activity may be associated with User account.

    @clmview_admin_clm
    @param_post{user_id,int}
    @param_post{wi_data,dict} fields: 'site_name'
    @param_post{block,bool} whether to block or unblock.
    """
    user = User.get(user_id)

    if block:
        if user.is_active == user_active_states['ok'] or user.is_active == user_active_states['email_confirmed']:
            user.is_active = user_active_states['blocked']
        else:
            raise CLMException('user_state')
    else:
        if user.is_active == user_active_states['blocked']:
            user.is_active = user_active_states['ok']
        else:
            raise CLMException('user_state')

    try:
        user.save()
    except Exception:
        raise CLMException('user_block' if block else 'user_unblock')

    if settings.MAILER_ACTIVE:
        try:
            mail.send_block_email(user, block, wi_data)
        except Exception, e:
            log.error(caller_id, "Cannot send block/unblock email: %s" % str(e))