Пример #1
0
def webpack_asset(bundle, kind='js', add_serial=False):
    if get_setting('eor.webpack-asset-autoreload'):
        load_definitions()

    res = get_setting('eor.webpack-asset-url-prefix') + _definitions[bundle][kind]
    if add_serial:
        res = res + '?' + get_setting('eor.static-serial')

    return res
Пример #2
0
def static_serial():
    """
    .ini: app.static-serial = 1
    <script src="/site/js/site.js${h.static_serial() | n}"></script>
    """
    serial = get_setting('eor.static-serial')
    return u'?%s' % serial if serial else u''
Пример #3
0
 def __acl__(self):
     """
     acl for user and entity (but no entity id)
     """
     from ..models import User
     try:
         object_id = object_id_getter(self.request) if object_id_getter else None
         if get_setting('eor.debug-auth'):
             log.info('EntityFactory.__acl__(): user_id %s, object type %s, object id %s' % (self.user_id, self.entity,  object_id))
         permissions = User.get_permissions_for_object_type(self.user_id, self.entity, object_id)
         acl = [(Allow, self.user_id, perm.permission) for perm in permissions]
         if get_setting('eor.debug-auth'):
             log.info('EntityFactory.__acl__(): acl %s' % acl)
         return acl
     except Exception as e:
         log.error('!!!!!!!!!!!!! exception in get_permissions_for_object_type(): %s %s' % (type(e), e))
         return []
Пример #4
0
def send_email(to, subject, body, html=False):
    msg = MIMEText(body, 'html' if html else 'plain', 'utf-8')

    smtp_host = get_setting('eor.smtp-host')
    msg['From'] = get_setting('eor.email-from')
    msg['To'] = to
    msg['Subject'] = subject

    try:
        s = smtplib.SMTP(smtp_host)
        s.sendmail(msg['From'], msg['To'], msg.as_string())
        s.quit()
        log.info('отправлено сообщение %s, тема [%s]' % (to, subject))
    except Exception as e:
        msg = 'ошибка отправки сообщения на адрес %s, %s, smtp-host=%s' % (to, str(e), smtp_host)
        log.error(msg)
        raise EmailException(msg)
Пример #5
0
 def __acl__(self):
     """
     acl for user, entity and entity_id
     """
     # [ (Allow, '<user_id>', 'view') ]
     # takes into account user's groups in a single database query
     if get_setting('eor.debug-auth'):
         print('>>>>>>> EntityFactory.__acl__: user_id =', self.user_id, 'object type =', self.entity, 'object id =', self.entity_id)
     return permissions_for_entity_from_database(self.user_id, self.entity, self.entity_id)
Пример #6
0
def load_definitions():
    defs_path = os.path.join(get_setting('eor.webpack-asset-path'), get_setting('eor.webpack-asset-defs'))

    try:
        last_modified = os.path.getmtime(defs_path)
    except OSError as e:
        log.error('eor.asset_utils: error loading %s: %s (eor.webpack-asset-path = %s, eor.webpack-asset-defs = %s)',
          defs_path, e, get_setting('eor.webpack-asset-path'), get_setting('eor.webpack-asset-defs'))
        return

    if last_modified == _last_modified:
        return

    global _last_modified
    _last_modified = last_modified

    with open(defs_path, 'r') as f:
        s = f.read()

    global _definitions
    _definitions = json.loads(s)
Пример #7
0
    def fs_path(self):
        """
        :return: absolute filesystem path to the file
        """
        id = self.parsed_id

        comps = [get_setting('eor-filestore.path')]
        if id.category:
            comps.append(id.category)
        comps.append(_subdirs(id.uuid))
        comps.append(id.make_name(self.variant_name))

        return os.path.abspath(os.path.join(*comps))
Пример #8
0
    def permits(self, context, principals, permission):
        """ Return an instance of
        :class:`pyramid.security.ACLAllowed` instance if the policy
        permits access, return an instance of
        :class:`pyramid.security.ACLDenied` if not."""

        if get_setting('eor.debug-auth'):
            log.info('permits: context %s, principals %s, permission %s' % (context, principals, permission))

        acl = '<No ACL found on any object in resource lineage>'

        for location in lineage(context):
            try:
                acl = location.__acl__
            except AttributeError:
                continue

            if acl and isinstance(acl, collections.Callable):
                acl = acl()

            for ace in acl:
                ace_action, ace_principal, ace_permissions = ace
                if ace_principal in principals:
                    if not is_nonstr_iter(ace_permissions):
                        ace_permissions = [ace_permissions]
                    if permission in ace_permissions:
                        if ace_action == Allow:
                            return ACLAllowed(ace, acl, permission,
                                              principals, location)
                        else:
                            return ACLDenied(ace, acl, permission,
                                             principals, location)

        # default deny (if no ACL in lineage at all, or if none of the
        # principals were mentioned in any ACE we found)
        return ACLDenied(
            '<default deny>',
            acl,
            permission,
            principals,
            context)
Пример #9
0
def static_domain():
    return get_setting('eor.static-domain')
Пример #10
0
 def get_fs_path(self):
     """Get path to directory where files for this category are stored."""
     comps = [get_setting('eor-filestore.path'), self.category]
     return os.path.abspath(os.path.join(*comps))
Пример #11
0
 def _filesystem_path_prefix(cls):
     return get_setting('eor-store.path')
Пример #12
0
 def _url_prefix(cls):
     return '//' + get_setting('eor.static-domain') + '/store/'