当前位置: 首页>>代码示例>>Python>>正文


Python Auth.assert_is_role方法代码示例

本文整理汇总了Python中Auth.assert_is_role方法的典型用法代码示例。如果您正苦于以下问题:Python Auth.assert_is_role方法的具体用法?Python Auth.assert_is_role怎么用?Python Auth.assert_is_role使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Auth的用法示例。


在下文中一共展示了Auth.assert_is_role方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: default_admin

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def default_admin (message = None, assets = None):
    not_admin    = Auth.assert_is_role (Role.ROLE_ADMIN)
    if not_admin:
        return not_admin

    # Render
    page = Page.Default()
    page += CTK.RawHTML ("<h1>%s: Permisos</h1>" % ADMIN_LINK)
    contents = get_admin_contents()

    main = CTK.Container()
    if len(contents):
        main += Paginate(contents, DefaultWidget)
    else:
        main += CTK.RawHTML ("<h2>No hay activos.</h2>")

    if assets != None:
        page += CTK.RawHTML ("<h2>Activos buscados</h2>")
        page += acl_get_custom (assets)

    tabs = CTK.Tab()
    tabs.Add ('Activos',  main)
    tabs.Add ('Búsqueda', WidgetLookup.get_fields_form(ACL_ADMIN_LOOKUP))
    page += tabs

    if message:
        page += Message(message)
    return page.Render()
开发者ID:manolodd,项目名称:activae,代码行数:30,代码来源:PageACL.py

示例2: publish_asset

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def publish_asset (perform = None):
    # Authentication
    fail = Auth.assert_is_role (Role.ROLE_PUBLISHER)
    if fail: return fail

    lookup = OpLookup()
    search = {'published_flag': 0, '__order__': 'type'}
    try:
        result = lookup(search)
    except:
        result = []
    acl    = ACL()
    result = acl.filter_assets ("ad" , result)

    contents = [(Asset, x) for x in result]

    page = Page.Default()
    page += CTK.RawHTML ("<h1>%s: Publicar activos</h1>" %(MENU_LINK))

    pending = CTK.Container()
    if len(contents) == 0:
        pending += CTK.RawHTML ("<h2>No hay activos pendientes de publicación</h2>")
    else:
        pending += Paginate(contents, PublishWidget)

    if perform or perform == []:
        page += CTK.RawHTML ("<h2>Activos buscados</h2>")
        page += publish_get_custom (perform)

    tabs = CTK.Tab()
    tabs.Add ('Pendientes',  pending)
    tabs.Add ('Búsqueda',    WidgetLookup.get_fields_form(PUBLISH_LOOKUP))
    page += tabs

    return page.Render()
开发者ID:manolodd,项目名称:activae,代码行数:37,代码来源:PageAsset.py

示例3: del_license

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def del_license():
    # Authentication
    fail = Auth.assert_is_role (Role.ROLE_ADMIN)
    if fail: return fail

    # Target license
    license_id = CTK.request.url.split('/')[-1]

    # Check whether it can be deleted
    q = "SELECT COUNT(*) as total FROM assets WHERE licenses_id = %(license_id)s;" %(locals())
    re = Query(q)

    usage = re['total'][0]
    if usage != 0:
        subs = Util.get_es_substitutions (usage)
        msg  = ("Imposible realizar la operación. La licencia está "
                "siendo usada por %(num)d activo%(s)s" % subs)
        return default (msg)

    # Delete
    q = "DELETE FROM licenses WHERE id = %(license_id)s;" %(locals())
    ok = query_check_success (q)
    if not ok:
        return default ('No se pudo eliminar la licencia.')
    return default ()
开发者ID:manolodd,项目名称:activae,代码行数:27,代码来源:PageAdminLicenses.py

示例4: publish_asset_apply

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def publish_asset_apply ():
    # Authentication
    fail = Auth.assert_is_role (Role.ROLE_PUBLISHER)
    if fail: return fail

    acl = ACL()
    ret = []
    for key in CTK.post:
        if not key.startswith('published_'):
            continue
        flag     = int(CTK.post[key])
        asset_id = key[len('published_'):]
        asset    = Asset(asset_id)

        if asset['published_flag'] == flag:
            continue

        asset['published_flag'] = flag
        asset['publisher_id']   = Auth.get_user_id()
        asset['date_available'] = "CURRENT_TIMESTAMP()"
        op = OpAsset(asset)
        ret.append(op.update())

        if ret[-1] == False:
            break

        if asset['published_flag']:
            acl.set_published_asset_acl(asset, True)
        else:
            acl.set_published_asset_acl(asset, False)

    if False in ret:
        return {'ret': "error"}

    return {'ret': "ok"}
开发者ID:manolodd,项目名称:activae,代码行数:37,代码来源:PageAsset.py

示例5: page_forbidden

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def page_forbidden (limiter):
    # Authentication
    fail = Auth.assert_is_role (Role.ROLE_UPLOADER)
    if fail: return fail

    for key,value in limiter.limits.items():
        if value==0:
            limiter.limits[key] = NO_LIMIT

    rows = [('Número de archivos',       limiter.usage['files'], limiter.limits['files']),
            ('Total del sistema',        limiter.usage['total'], limiter.limits['total']),
            ('Tamaño máximo de archivo', limiter.usage['size'],  limiter.limits['size'])]

    header = ['Restricción', 'Uso', 'Límite']
    table = CTK.Table()
    table[(1,1)] = [CTK.RawHTML(x) for x in header]
    table.set_header (row=True, num=1)

    for x in range(len(rows)):
        table[(x+2,1)] = [CTK.RawHTML (str(column)) for column in rows[x]]

    page  = Page.Default()
    page += CTK.RawHTML ("<h1>%s: Subir ficheros</h1>" %(MENU_LINK))
    page += CTK.RawHTML ("<h2>Se han excedido los límites</h2>")
    page += table

    return page.Render()
开发者ID:manolodd,项目名称:activae,代码行数:29,代码来源:PageUpload.py

示例6: edit_profile

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def edit_profile():
    # Authentication
    fail = Auth.assert_is_role (Role.ROLE_ADMIN)
    if fail: return fail

    # Table
    profile_id = CTK.request.url.split('/')[3]
    q = ("SELECT *, GROUP_CONCAT(roles_id) " +
         "  FROM profiles, profiles_has_roles " +
         "  WHERE profiles.id = %(profile_id)s AND " +
         "        profiles_has_roles.profiles_id = %(profile_id)s " +
         "  GROUP by profiles.id;") %(locals())

    p = Query(q)
    profile_roles = [int(x) for x in p['GROUP_CONCAT(roles_id)'][0].split(',')]

    table = CTK.PropsAuto ('/admin/profile/apply')
    table.AddConstant ('profile_id', profile_id)
    table.Add ('Nombre',              CTK.TextField ({'name': "name",        'value': p['name'][0]}),        "Nombre del profile")
    table.Add ('Description',         CTK.TextField ({'name': "description", 'value': p['description'][0]}), "Descripcion del profile")
    table.Add ('Role: Administrador', CTK.Checkbox  ({'name': "role_"+str(Role.ROLE_ADMIN),     'checked': '01'[Role.ROLE_ADMIN     in profile_roles]}), "Tiene permisos de administrador")
    table.Add ('Role: Ingestador',    CTK.Checkbox  ({'name': "role_"+str(Role.ROLE_UPLOADER),  'checked': '01'[Role.ROLE_UPLOADER  in profile_roles]}), "Puede dar de alta nuevos activos en el sistema")
    table.Add ('Role: Editor',        CTK.Checkbox  ({'name': "role_"+str(Role.ROLE_EDITOR),    'checked': '01'[Role.ROLE_EDITOR    in profile_roles]}), "Puede editar los activos que ya existen en el sistema")
    table.Add ('Role: Publicador',    CTK.Checkbox  ({'name': "role_"+str(Role.ROLE_PUBLISHER), 'checked': '01'[Role.ROLE_PUBLISHER in profile_roles]}), "Puede publicar activos")
    table.Add ('Role: Consumidor',    CTK.Checkbox  ({'name': "role_"+str(Role.ROLE_CONSUMER),  'checked': '01'[Role.ROLE_CONSUMER  in profile_roles]}), "El usuario puede consumir, ver, y descargar activos")

    page = Page.Default()
    page += CTK.RawHTML ("<h1>%s: Edici&oacute;n profile</h1>" %(PROFILES_PREFIX))
    page += table
    return page.Render()
开发者ID:manolodd,项目名称:activae,代码行数:32,代码来源:PageAdminProfiles.py

示例7: new_user_apply

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def new_user_apply():
    # Authentication
    fail = Auth.assert_is_role (Role.ROLE_ADMIN)
    if fail: return fail

    # Update the database
    fields = []
    values = []
    for key in ['username','forename', 'surname1', 'surname2', 'email']:
        if key in CTK.post:
            fields.append (key)
            values.append ("'%s'"%(CTK.post[key]))

    if 'password' in CTK.post:
        fields.append ('password')
        values.append ("'%s'"%(md5(CTK.post['password']).hexdigest()))

    for key in ['profile_id']:
        if key in CTK.post:
            fields.append (key)
            values.append ("%s" %(CTK.post[key]))

    q = "INSERT INTO users (%s) VALUES (%s);" %(", ".join(fields), ", ".join(values))
    if not query_check_success (q):
        return {'ret': "error"}

    return {'ret':      "ok",
            'redirect': "/admin/user"}
开发者ID:manolodd,项目名称:activae,代码行数:30,代码来源:PageAdminUsers.py

示例8: del_asset

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def del_asset():
    """Delete asset"""

    # Target asset
    asset_id = CTK.request.url.split('/')[-1]
    try:
        asset_id = __check_asset_id(asset_id)
        asset    = Asset (asset_id)
        if not asset['id']:
            return CTK.HTTP_Redir('/')
    except:
            return CTK.HTTP_Redir('/')

    # Authentication
    fail_admin = Auth.assert_is_role (Role.ROLE_ADMIN)
    user_id    = Auth.get_user_id()
    is_creator = (asset['creator_id'] == user_id)

    if fail_admin and not is_creator:
        return fail_admin

    op  = OpAsset (asset)
    result = op.delete()

    if result['ret'] == False:
        return default()

    if result['type'] == 'total':
        return CTK.HTTP_Redir(LOCATION)

    return default (ERROR_IN_USE)
开发者ID:manolodd,项目名称:activae,代码行数:33,代码来源:PageAsset.py

示例9: del_format

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def del_format():
    # Authentication
    fail = Auth.assert_is_role (Role.ROLE_ADMIN)
    if fail: return fail

    # Target format
    format_id = CTK.request.url.split('/')[-1]

    # Check whether it can be deleted
    q = ("SELECT COUNT(*) as total "
         "FROM view_asset_formats "
         "WHERE formats_id = %(format_id)s;" %(locals()))
    re = Query(q)

    usage = re['total'][0]
    if usage != 0:
        subs = [{'n':'','s':''},{'n':'n','s':''}][(usage > 1)]
        subs['num'] = usage
        msg  = ("Imposible realizar la operación ya que existe%(n)s "
                "%(num)d activo%(s)s en ese formato" % subs)

        return default (msg)

    # Delete
    q  = "DELETE FROM transcode_targets WHERE source_id = %(format_id)s OR target_id = %(format_id)s;" %(locals())
    q += "DELETE FROM formats WHERE id = %(format_id)s;" %(locals())
    q  = "START TRANSACTION; %s COMMIT;" % q

    ok = transaction_check_success (q)

    if not ok:
        msg = 'No se pudo eliminar el formato.'
        return default (msg)
    return default()
开发者ID:manolodd,项目名称:activae,代码行数:36,代码来源:PageAdminFormats.py

示例10: edit_format

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def edit_format():
    # Authentication
    fail = Auth.assert_is_role (Role.ROLE_ADMIN)
    if fail: return fail

    # Table
    format_id = CTK.request.url.split('/')[-1]
    f = Format.get_format (format_id)
    lossy_dict  = {'name': 'lossy_flag', 'checked': str(f['lossy_flag'])}

    table = CTK.PropsAuto ('%s/edit/apply'%LOCATION)
    table.AddConstant ('formatid', format_id)
    table.Add ('Formato',     CTK.RawHTML(f['name']), 'Nombre del formato')
    table.Add ('Con pérdida', CTK.Checkbox (lossy_dict),  'La transcodificación a este formato conlleva pérdida de calidad')

    page = Page.Default()
    page += CTK.RawHTML ("<h1>%s: Edicion de formato</h1>" %(MENU_LINK))
    page += table

    # New targets
    new_table = __get_new_targets_table (format_id)
    if new_table:
        page += CTK.RawHTML ("<h3>Agregar objetivos de transcodificación</h3>")
        page += new_table

    # Current targets
    target_table, dialogs = __get_current_targets_table (format_id)
    if target_table:
        page += CTK.RawHTML ("<h3>Objetivos de transcodificación existentes</h3>")
        page += target_table
        for dialog in dialogs:
            page += dialog
    return page.Render()
开发者ID:manolodd,项目名称:activae,代码行数:35,代码来源:PageAdminFormats.py

示例11: edit_format_apply

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def edit_format_apply():
    # Authentication
    fail = Auth.assert_is_role (Role.ROLE_ADMIN)
    if fail: return fail

    format_id = CTK.post.pop('formatid')
    if not format_id:
        return CTK.HTTP_Error(406)

    # Update the database
    q = ''
    for key in ['lossy_flag', 'format']:
        if key in CTK.post:
            q += "UPDATE formats SET %s='%s' WHERE id = %s;" % \
                (key, CTK.post[key], format_id)

    if 'target' in CTK.post:
        q += "INSERT INTO transcode_targets (source_id, target_id) VALUES ('%s','%s');" % \
            (format_id,CTK.post['target'])
    if q:
        q = "START TRANSACTION; %s COMMIT;" % q
        if not transaction_check_success (q):
            return {'ret': "error"}

    return {'ret': "ok",
            'redirect': '%s/edit/%s'%(LOCATION,format_id)}
开发者ID:manolodd,项目名称:activae,代码行数:28,代码来源:PageAdminFormats.py

示例12: del_type

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def del_type():
    # Authentication
    fail = Auth.assert_is_role (Role.ROLE_ADMIN)
    if fail: return fail

    # Target asset_type
    asset_type_id = CTK.request.url.split('/')[-1]

    # Check whether it can be deleted
    q = "SELECT COUNT(*) as total FROM assets WHERE asset_types_id = %(asset_type_id)s;" %(locals())
    re = Query(q)

    usage = re['total'][0]
    if usage != 0:
        subs = Util.get_es_substitutions (usage)
        msg  = ("No se puede eliminar. "
                "Existe%(n)s %(num)d activo%(s)s de este tipo." % subs)
        return default (msg)

    # Delete
    q = "DELETE FROM asset_types WHERE id = %(asset_type_id)s;" %(locals())
    ok = query_check_success (q)

    if not ok:
        return default ('No se pudo realizar la eliminación.')

    return CTK.HTTP_Redir(LOCATION)
开发者ID:manolodd,项目名称:activae,代码行数:29,代码来源:PageAdminTypes.py

示例13: transcode

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def transcode ():
    # Authentication
    fail = Auth.assert_is_role (Role.ROLE_PUBLISHER)
    if fail: return fail

    asset_id  = CTK.request.url.split('/')[-1]
    asset     = Asset(asset_id)

    if not asset._file.get('filename'):
        return error_page(NOTE_NO_FILE)

    format_id = asset._file.get('formats_id')
    if not format_id:
        info = get_info (asset._file.get('filename'))
        format_id = info.get('formats_id',None)

    if not format_id:
        return error_page(NOTE_NO_FORMAT)

    sql = "SELECT * FROM transcode_targets "\
          "JOIN formats ON target_id=formats.id "\
          "WHERE source_id = %(format_id)s;" %(locals())
    q = Query(sql)

    if not len(q):
        return error_page(NOTE_NO_TRANSCODING)

    table = CTK.Table ()

    header     = ['Formato', 'Convertir', 'Calidad de conversión']
    table[(1,1)] = [CTK.RawHTML(x) for x in header]
    table.set_header (row=True, num=1)
    n = 2

    for x in q:
        if q[x]['lossy_flag']: text = LOSSY
        else:                  text = LOSSLESS
        opts  = {'name': 'target_id_%s'% str(q[x]['target_id']),
                 'class':'required',
                 'checked': 0}

        fields = [CTK.RawHTML(q[x]['format'].upper()),
                  CTK.Checkbox(opts),
                  CTK.RawHTML(text)]

        table[(n,1)] = fields
        n += 1

    form = CTK.Submitter("%s/apply"%LOCATION)
    form += table
    form += CTK.HiddenField({'name':'asset_id','value':str(asset_id)})
    form += CTK.SubmitterButton('Enviar')

    page = Page.Default()
    page += CTK.RawHTML ('<h1>%s</h1>'%MENU_LINK)
    page += form
    return page.Render()
开发者ID:manolodd,项目名称:activae,代码行数:59,代码来源:PageTranscode.py

示例14: page_broken_file

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def page_broken_file ():
    # Authentication
    fail = Auth.assert_is_role (Role.ROLE_UPLOADER)
    if fail: return fail

    page  = Page.Default()
    page += CTK.RawHTML ("<h1>%s: A&ntilde;adir activo</h1>"%(MENU_LINK))
    page += CTK.RawHTML ("<p>El fichero está corrupto. Pruebe con otro.</p><p>No se pudo crear el activo.</p>")

    return page.Render()
开发者ID:manolodd,项目名称:activae,代码行数:12,代码来源:PageAssetCreate.py

示例15: default

# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import assert_is_role [as 别名]
def default (message = None):
    # Authentication
    fail = Auth.assert_is_role (Role.ROLE_ADMIN)
    if fail: return fail

    # List of profiles
    q = "SELECT * FROM profiles;"
    profiles = Query(q)

    table = CTK.Table()
    title = [CTK.RawHTML(x) for x in ['Profile', 'Descripcion', 'Role']]
    table[(1,1)] = title
    table.set_header (row=True, num=1)

    page = Page.Default()

    n = 2
    for profile in profiles:
        # Fetch data
        profile_id   = profiles[profile]['id']
        profile_name = profiles[profile]['name']
        profile_desc = profiles[profile]['description']

        # Role
        q = "SELECT * FROM profiles_has_roles WHERE profiles_id='%s';" %(profile_id)
        roles = Query(q)
        profile_roles_str = ', '.join([Role.role_to_name(roles[x]['roles_id']) for x in roles])

        # Delete profile
        dialog = CTK.Dialog ({'title': "Eliminando profile %s?"%(profile_name), 'autoOpen': False})
        dialog += CTK.RawHTML (NOTE_DELETE)
        dialog.AddButton ('Cancelar', "close")
        dialog.AddButton ('Borrar',   "/admin/profile/del/%s" %(profile_id))

        del_img  = '<img src="/CTK/images/del.png" alt="Borrar"'
        linkdel  = LINK_JS_ON_CLICK %(dialog.JS_to_show(), del_img)
        linkname = LINK_HREF %("/admin/profile/%s"%profile_id, profile_name)

        table[(n,1)] = [CTK.RawHTML(linkname),
                        CTK.RawHTML(profile_desc),
                        CTK.RawHTML(profile_roles_str),
                        CTK.RawHTML(linkdel)]

        page += dialog
        n += 1

    # Render
    page += CTK.RawHTML ("<h1>%s: Administraci&oacute;n de Profiles</h1>" %(ADMIN_PREFIX))
    page += CTK.RawHTML (LINK_HREF%('/admin/profile/new', 'A&ntilde;adir profile'))
    page += table

    if message:
        page += Message (message)

    return page.Render()
开发者ID:manolodd,项目名称:activae,代码行数:57,代码来源:PageAdminProfiles.py


注:本文中的Auth.assert_is_role方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。