Exemple #1
0
 def _update_cookie(self):
     key = 'yugong.toutiao.cookie.%s' % config.get('app.toutiao.account')
     cookie_file = (config.APP_PATH + '/storage/cache/toutiao/%s.txt'
                    ) % config.get('app.toutiao.account')
     if not os.path.exists(os.path.split(cookie_file)[0]):
         os.makedirs(os.path.split(cookie_file)[0])
     json_cookie = json.dumps(self._browser.get_cookies())
     cache.put(key, json_cookie)
     with open(cookie_file, 'w+') as f:
         f.write(json_cookie)
Exemple #2
0
 def get_worksheet_name(self, worksheet_id):
     if worksheet_id == None or int(worksheet_id) == model.EMPTY_UID:
         return i18n.get_i18n_message(conf.get_preferred_language(), "task_label_workbasket")
     name = cache.get(CACHESPACE_WORKSPACENAME, worksheet_id)
     if name != None:
         return name
     else:
         worksheet = self.get_worksheet(worksheet_id)
         name = worksheet.ws_name if worksheet is not None else ''
         cache.put(CACHESPACE_WORKSPACENAME, worksheet_id, name)
         return name
Exemple #3
0
def get_user_display_name(user_id):
    user_name = cache.get(CACHESPACE_USERNAME, user_id)
    if user_name != None:
        return user_name
    else:
        user = get_user(user_id=user_id)
        user_name = ""
        if user != None:
            user_name = user.u_account if strutil.is_empty(user.u_name) else user.u_name
        cache.put(CACHESPACE_USERNAME, user_id, user_name)
        return user_name
Exemple #4
0
 def get_group_name(self, group_id):
     if group_id == None or group_id == model.EMPTY_UID:
         return ""
     name = cache.get(CACHESPACE_GROUPNAME, group_id)
     if name != None:
         return name
     else:
         group = self.get_group(group_id)
         name = group.group_name if group is not None else ''
         cache.put(CACHESPACE_GROUPNAME, group_id, name)
         return name
Exemple #5
0
 def get_contact_name(self, contact_id):
     if contact_id == None or contact_id == model.EMPTY_UID:
         return ""
     name = cache.get(CACHESPACE_CONTACTNAME, contact_id)
     if name != None:
         return name
     else:
         contact = self.get_contact(contact_id)
         name = contact.contact_name if contact is not None else ''
         cache.put(CACHESPACE_CONTACTNAME, contact_id, name)
         return name
Exemple #6
0
def has_permission(user_id, operation_key, oqlparams=None):
    b = False
    cachekey = '%d:%s:%r' % (user_id, operation_key, oqlparams)
    perm = cache.get(CACHESPACE_PERMISSION, cachekey)
    if perm != None:
        return perm
    
    query = stdModel.all()
    query.model(UserRole.get_modelname(), "a")
    query.model(Role.get_modelname(), "b", join="inner", on="a.role_id=b.uid")
    query.model(RoleOperation.get_modelname(), "c", join="inner", on="c.role_id=b.uid")
    query.model(Operation.get_modelname(), "d", join="inner", on="c.operation_key=d.operation_key")
    query.what("a.user_id", alias="user_id")
    query.what("b.uid", alias="role_id")
    query.what("d.operation_key", alias="operation_key")
    query.what("d.handler_classes", alias="handler_classes")
    query.what("d.resource_oql", alias="resource_oql")
    query.what("a.user_id", alias="user_id")
    
    query.filter("a.user_id =", user_id)
    if operation_key is not None:
        query.filter("d.operation_key =", operation_key)
    std = query.get()
    
    if std != None:
        if std.resource_oql != None:
            operation = get_operation(operation_key=operation_key)
            params = operation.get_resource_oql_paramnames()
            if len(params) != len(oqlparams):
                raise UnauthorizedError()
            query = stdModel.all()
            if oqlparams != None and len(oqlparams) > 0 :
                query = query.sql(std.resource_oql, sql_vars=oqlparams)
            else:
                query = query.sql(std.resource_oql)
            if query.count() > 0:
                b = True
        else:
            b = True
    cache.put(CACHESPACE_PERMISSION, cachekey, b)
    return b