Example #1
0
    def _resolve_branch_switch(self, curbranch, curversion, outstack=[]):
        for upd in self._list(from_branch=(curbranch, curversion),
                              type="branch"):
            if upd.branch == self._reqbranch and pkg_resources.parse_version(
                    upd.version) <= pkg_resources.parse_version(
                        self._reqversion):
                return outstack + [upd]

            elif upd in outstack:
                log.get_logger().warning(
                    "cyclic branch dependencies detected: %s",
                    " -> ".join(text_type(i) for i in outstack + [upd]))
                continue

            else:
                ret = self._resolve_branch_switch(upd.branch,
                                                  upd.version,
                                                  outstack=outstack[:] + [upd])
                if ret:
                    return ret

        for upd in self._list(from_version=curversion,
                              branch=curbranch,
                              type="update"):
            ret = self._resolve_branch_switch(upd.branch,
                                              upd.version,
                                              outstack=outstack[:] + [upd])
            if ret:
                return ret

        return []
Example #2
0
    def _get_schema_list(self, **kwargs):
        from_version = to_version = None

        if "from_version" in kwargs:
            from_version = pkg_resources.parse_version(
                kwargs.pop("from_version"))

        if "to_version" in kwargs:
            to_version = pkg_resources.parse_version(kwargs.pop("to_version"))

        dirnames = self._get_update_directories()

        for importer, package_name, _ in pkgutil.iter_modules(dirnames):
            try:
                mod = importer.find_module(package_name).load_module(
                    package_name).SQLUpdate(self)
            except Exception as e:
                log.get_logger().exception(
                    "[%s]: error loading SQL update '%s' : %s" %
                    (self._full_module_name, package_name, e))
                continue

            if any(kwargs[k] != getattr(mod, k) for k in kwargs.keys()):
                continue

            version = pkg_resources.parse_version(mod.version)
            if (not from_version or
                (version > from_version)) and (not to_version or
                                               (version <= to_version)):
                yield mod
Example #3
0
    def apply(self):
        log.get_logger().info("%s: please standby while %s is applied",
                              self._full_module_name, text_type(self))

        self.run()

        if self.type == "install":
            self.db.upsert(
                "Prewikka_Module_Registry", ("module", "branch", "version"),
                ((self._full_module_name, self.branch, self.version), ),
                pkey=("module", ))

        elif self.type == "update":
            self.db.query(
                "UPDATE Prewikka_Module_Registry SET version=%s WHERE module=%s%s"
                % (self.db.escape(
                    self.version), self.db.escape(self._full_module_name),
                   self.db._chknull("branch", self.branch)))

        elif self.type == "branch":
            self.db.query(
                "UPDATE Prewikka_Module_Registry SET branch=%s, version=%s, enabled=1 WHERE module=%s",
                self.branch, self.version, self._full_module_name)

        self.db._update_state(self.version, self.branch)
Example #4
0
 def _get_update_directories(self):
     for i in pkg_resources.iter_entry_points("prewikka.updatedb",
                                              self._module_name):
         try:
             yield i.load().__path__[0]
         except Exception as e:
             log.get_logger().exception(
                 "[%s]: error loading SQL updates: %s",
                 self._full_module_name, e)
Example #5
0
from copy import copy
from prewikka import compat, csrf, error, hookmanager, log, mainmenu, pluginmanager, registrar, response, template, usergroup, utils

import werkzeug.exceptions
from werkzeug.routing import Map, Rule, BaseConverter

if sys.version_info >= (3, 0):
    import builtins
else:
    import __builtin__ as builtins

_SENTINEL = object()
_URL_ADAPTER_CACHE = {}
_ROUTE_OVERRIDE_TYPE = ("make_url", "make_parameters", "check_permissions")
logger = log.get_logger(__name__)


def check_permissions(user, users=([], []), groups=([], []), others=[]):
    if user:
        if user in users[0]:
            return user.has(users[1])

        if groups[0] and set(env.auth.get_member_of(user)) & set(groups[0]):
            return user.has(groups[1])

        if others:
            return user.has(others)

    # If there is no users / groups / others permission defined, then it is considered public and we return True
    # Otherwise, if any kind of permission is defined and there was no match, return False.