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


Python model.User类代码示例

本文整理汇总了Python中ckan.model.User的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: authenticate

    def authenticate(self, environ, identity):
        if not ('login' in identity and 'password' in identity):
            return None

        login = identity['login']
        user = User.by_name(login)

        ## HDX HACK ##
        if user is None:
            users = User.by_email(login)
            try:
                user = users[0]
            except:
                user = None
        ## END HDX HACK ##

        if user is None:
            log.debug('Login failed - username %r not found', login)
        elif not user.is_active():
            log.debug('Login as %r failed - user isn\'t active', login)
        elif not user.validate_password(identity['password']):
            log.debug('Login as %r failed - password not valid', login)
        else:
            return user.name

        return None
开发者ID:aalecs,项目名称:hdx-ckan-ci,代码行数:26,代码来源:authenticator.py

示例2: send_email

def send_email(req):
    requestee = User.get(req.user_id)
    pkg = Package.get(req.pkg_id)
    selrole = False
    for role in pkg.roles:
        if role.role == "admin":
            selrole = role
    if not selrole:
        return
    admin = User.get(selrole.user_id)
    msg = _("""%s (%s) is requesting editor access to a dataset you have created
    %s.

Please click this link if you want to give this user write access:
%s%s""")
    controller = 'ckanext.kata.controllers:AccessRequestController'
    body = msg % (requestee.name, requestee.email, pkg.title if pkg.title else pkg.name,
                config.get('ckan.site_url', ''),
                h.url_for(controller=controller,
                action="unlock_access",
                id=req.id))
    email_dict = {}
    email_dict["subject"] = _("Access request for dataset %s" % pkg.title if pkg.title else pkg.name)
    email_dict["body"] = body
    send_notification(admin.as_dict(), email_dict)
开发者ID:ugeuder-kata,项目名称:ckanext-kata,代码行数:25,代码来源:utils.py

示例3: is_owner

def is_owner(context, data_dict):
    '''
    This is used in "request edit rights" feature.
    Checks if the user is admin or editor of the
    package in question

    :param context: context
    :param data_dict: package data
    :type data_dict: dictionary

    :rtype: dictionary
    '''

    pkg = context.get('package', None)
    roles = pkg.roles if pkg else Package.get(data_dict['id']).roles
    user = context.get('user', False)
    if user:
        for role in roles:
            ruser = User.get(role.user.id)
            if user == ruser.name and role.role in ('admin', 'editor'):
                return {'success': True}

    # Check if the user has editor rights to this dataset through an organization
    package = get_package_object(context, data_dict)
    if new_authz.has_user_permission_for_group_or_org(package.owner_org, user, 'delete_dataset'):
        return {'success': True}

    return {'success': False}
开发者ID:atehwa,项目名称:ckanext-kata,代码行数:28,代码来源:auth_functions.py

示例4: send

 def send(self, pkg_id):
     package = Package.get(pkg_id)
     url = h.url_for(controller='package',
             action="read",
             id=package.id)
     if c.user:
             userid = None
             for role in package.roles:
                 if role.role == "admin":
                     userid = role.user_id
                     break
             if userid:
                 owner = User.get(userid)
                 msg = request.params.get('msg', '')
                 if msg:
                     send_contact_email(owner, c.userobj, package,\
                                    msg)
                 else:
                     h.flash_error(_("No message"))
                     return redirect(url)
             else:
                 h.flash_error(_("No owner found"))
                 return redirect(url)
             h.flash_notice(_("Message sent"))
     else:
         h.flash_error(_("Please login"))
     return redirect(url)
开发者ID:ugeuder-kata,项目名称:ckanext-kata,代码行数:27,代码来源:controllers.py

示例5: harvest_jobs_run

def harvest_jobs_run(context,data_dict):
    model = context['model']
    user = context.get('user')

    # Check user is logged in
    if not user:
        return {'success': False, 'msg': _('Only logged users are authorized to run harvest jobs')}

    user_obj = User.get(user)

    # Checks for non sysadmin users
    if not Authorizer().is_sysadmin(user):
        if not user_obj or len(user_obj.get_groups(u'publisher')) == 0:
            return {'success': False, 'msg': _('User %s must belong to a publisher to run harvest jobs') % str(user)}

        source_id = data_dict.get('source_id',False)
        if not source_id:
            return {'success': False, 'msg': _('Only sysadmins can run all harvest jobs') % str(user)}

        source = HarvestSource.get(source_id)
        if not source:
            raise NotFound

        if not source.publisher_id in [g.id for g in user_obj.get_groups(u'publisher')]:
            return {'success': False, 'msg': _('User %s not authorized to run jobs from source %s') % (str(user),source.id)}

    return {'success': True}
开发者ID:SenseTecnic,项目名称:ckanext-harvest,代码行数:27,代码来源:update.py

示例6: authenticate

 def authenticate(self, environ, identity):
     if 'repoze.who.plugins.openid.userid' in identity:
         openid = identity.get('repoze.who.plugins.openid.userid')
         user = User.by_openid(openid)
         if user is None:
             return None
         else:
             return user.name
     return None
开发者ID:31H0B1eV,项目名称:ckan,代码行数:9,代码来源:authenticator.py

示例7: authenticate

 def authenticate(self, environ, identity):
     if not 'login' in identity or not 'password' in identity:
         return None
     user = User.by_name(identity.get('login'))
     if user is None: 
         return None
     if user.validate_password(identity.get('password')):
         return user.name
     return None
开发者ID:AdamJensen-dk,项目名称:ckan-drupal,代码行数:9,代码来源:authenticator.py

示例8: authenticate

 def authenticate(self, environ, identity):
     '''Fetch the user given its username in identity'''
     if 'username' in identity:
         user = User.by_name(identity['username'])
         if user is None:
             return None
         else:
             identity.update({'repoze.who.userid': user.name})
             return user.name
     return None
开发者ID:etalab,项目名称:ckanext-youckan,代码行数:10,代码来源:repozewho.py

示例9: test_authenticate_step_two

 def test_authenticate_step_two(self):
     plugin = self._makeOne()
     environ = {"REQUEST_METHOD": "GET", "QUERY_STRING": "oauth_token=foo", "ckan.who.oauth.challenge": "1"}
     identity = plugin.identify(environ)
     username = identity.get("repoze.who.userid")
     self.assertEqual(username, "boz")
     user = User.by_name("boz")
     self.assertEqual(user.email, "[email protected]")
     groups = Session.query(AuthorizationGroup).filter(AuthorizationGroup.users.contains(user))
     self.assertEqual(groups.count(), 1)
开发者ID:okfn,项目名称:ckanext-oauth,代码行数:10,代码来源:test_general.py

示例10: is_owner

def is_owner(context, data_dict):
    pkg = context.get('package', None)
    roles = pkg.roles if pkg else Package.get(data_dict['id']).roles
    user = context.get('user', False)
    if user:
        for role in roles:
            ruser = User.get(role.user_id)
            if user == ruser.name and role.role in ('admin', 'editor'):
                return {'success': True}
    else:
        return {'success': False}
    return {'success': False}
开发者ID:ugeuder-kata,项目名称:ckanext-kata,代码行数:12,代码来源:auth_functions.py

示例11: authenticate

    def authenticate(self, environ, identity):

        if 'shibboleth_auth' in identity:
            userid = identity['shibboleth_auth']
            user = User.get(userid)
            if user is None or not user.is_active():
                log.info("ShibbolethAuthenticator: user not found: %s", userid)
                return None
            else:
                log.info("ShibbolethAuthenticator: user found %s", userid)
                return user.name
        return None
开发者ID:geosolutions-it,项目名称:ckanext-shibboleth,代码行数:12,代码来源:auth.py

示例12: send_edit_access_request_email

def send_edit_access_request_email(req):
    """
    Send edit access request email.

    :param user_id: user who requests access
    :param pkg_id: dataset's id
    """
    requester = User.get(req.user_id)
    pkg = Package.get(req.pkg_id)
    selrole = False
    for role in pkg.roles:
        if role.role == "admin":
            selrole = role
    if not selrole:
        return

    admin = User.get(selrole.user_id)
    admin_dict = admin.as_dict()
    admin_dict['name'] = admin.fullname if admin.fullname else admin.name

    msg = u'{a} ({b}) is requesting editing rights to the metadata in dataset\n\n{c}\n\n\
for which you are currently an administrator. Please click this \
link if you want to allow this user to edit the metadata of the dataset:\n\
{d}\n\n{a} ({b}) pyytää muokkausoikeuksia tietoaineiston\n\n{c}\n\n\
metatietoihin, joiden ylläpitäjä olet. Klikkaa linkkiä, jos haluat tämän käyttäjän \
saavan muokkausoikeudet aineiston metatietoihin:\n\
{d}\n'

    controller = 'ckanext.kata.controllers:EditAccessRequestController'

    requester_name = requester.fullname if requester.fullname else requester.name
    accessurl = config.get('ckan.site_url', '') + h.url_for(controller=controller, action="unlock_access", id=req.id)
    body = msg.format(a=requester_name, b=requester.email, c=pkg.title if pkg.title else pkg.name, d=accessurl)
    email_dict = {}
    email_dict["subject"] = u"Access request for dataset / pyyntö koskien tietoaineistoa %s" % pkg.title if pkg.title else pkg.name
    email_dict["body"] = body
    send_notification(admin_dict, email_dict)
开发者ID:atehwa,项目名称:ckanext-kata,代码行数:37,代码来源:utils.py

示例13: _get_sources_for_user

def _get_sources_for_user(context, data_dict):

    model = context['model']
    session = context['session']
    user = context.get('user', '')

    only_active = data_dict.get('only_active', False)
    only_to_run = data_dict.get('only_to_run', False)

    query = session.query(HarvestSource) \
        .order_by(HarvestSource.created.desc())

    if only_active:
        query = query.filter(HarvestSource.active) \

    if only_to_run:
        query = query.filter(HarvestSource.frequency != 'MANUAL')
        query = query.filter(or_(HarvestSource.next_run <=
                                 datetime.datetime.utcnow(),
                                 HarvestSource.next_run is None))

    user_obj = User.get(user)
    # Sysadmins will get all sources
    if user_obj and not user_obj.sysadmin:
        # This only applies to a non sysadmin user when using the
        # publisher auth profile. When using the default profile,
        # normal users will never arrive at this point, but even if they
        # do, they will get an empty list.

        publisher_filters = []
        publishers_for_the_user = user_obj.get_groups(u'publisher')
        for publisher_id in [g.id for g in publishers_for_the_user]:
            publisher_filters.append(
                HarvestSource.publisher_id == publisher_id)

        if len(publisher_filters):
            query = query.filter(or_(*publisher_filters))
        else:
            # This user does not belong to a publisher yet, no sources for
            # him/her
            return []

        log.debug('User %s with publishers %r has Harvest Sources: %r',
                  user, publishers_for_the_user,
                  [(hs.id, hs.url) for hs in query])

    sources = query.all()

    return sources
开发者ID:rossjones,项目名称:ckanext-harvestodm,代码行数:49,代码来源:get.py

示例14: harvest_source_create

def harvest_source_create(context,data_dict):
    model = context['model']
    user = context.get('user','')

    # Non-logged users can not create sources
    if not user:
        return {'success': False, 'msg': _('Non-logged in users are not authorized to create harvest sources')}

    # Sysadmins and the rest of logged users can create sources,
    # as long as they belong to a publisher
    user_obj = User.get(user)
    if not user_obj or not Authorizer().is_sysadmin(user) and len(user_obj.get_groups(u'publisher')) == 0:
        return {'success': False, 'msg': _('User %s must belong to a publisher to create harvest sources') % str(user)}
    else:
        return {'success': True}
开发者ID:SenseTecnic,项目名称:ckanext-harvest,代码行数:15,代码来源:create.py

示例15: preauthenticate

    def preauthenticate(self, environ, identity):
        # turn the oauth identity into a CKAN one; set it in our identity
        import oauth2 as oauth
        try:
            access_token = dict(urlparse.parse_qsl(identity['userdata']))
            oauth_token = access_token['oauth_token']
            oauth_token_secret = access_token['oauth_token_secret']
        except KeyError:
            return None
        access_token = oauth.Token(oauth_token,
                                   oauth_token_secret)
        client = oauth.Client(self.consumer, access_token)
        resp, content = client.request(self.user_url, "GET")
        data = json.loads(content)
        user_id = data['id']
        logging.info("Preauth: Got oauth user data for user %s" % user_id)
        user = User.by_openid(user_id)
        if user is None:
            user = User(openid=user_id,
                        name=data['id'],
                        fullname=data['name'],
                        email=data['mail'])
            Session.add(user)
        else:
            user.fullname = data['name'] # if the name is updated
        Session.commit()
        Session.remove()
        logging.info("Preauth: Created new/updated user %s" % user_id)

        # deal with groups
        user_groups = data['groups']
        _sync_auth_groups(user, user_groups)
        name = user.name.encode("utf8")
        logging.info("Preauth: Returning user identifier %s" % name)
        identity['repoze.who.userid'] = name 
        return identity
开发者ID:okfn,项目名称:ckanext-oauth,代码行数:36,代码来源:plugin.py


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