Beispiel #1
0
 def _set_maxage(self, repo_obj, maxage=None, **kwargs):
     """
     Update repository maxage via Ajax.
     """
     validate_int(maxage)
     repo_obj.maxage = maxage
     return _("Updated")
Beispiel #2
0
    def _handle_set_notification_info(self, **kwargs):

        # Loop trough user repo and update max age.
        for repo in self.app.currentuser.repo_objs:
            # Get value received for the repo.
            value = kwargs.get(repo.name, None)
            if value:
                # Update the maxage
                repo.maxage = validate_int(value)
Beispiel #3
0
    def default(self, path=b"", restore="", limit='10'):
        validate_isinstance(restore, str)
        limit = validate_int(limit)
        restore = bool(restore)

        # Check user access to the given repo & path
        (repo_obj, path_obj) = self.app.store.get_repo_path(path)

        # Build the parameters
        # Build "parent directories" links
        # TODO This Should to me elsewhere. It contains logic related to librdiff encoding.
        parents = []
        parents.append({"path": b"", "name": repo_obj.display_name})
        parent_path_b = b""
        for part_b in path_obj.path.split(b'/'):
            if part_b:
                parent_path_b = os.path.join(parent_path_b, part_b)
                display_name = repo_obj._decode(repo_obj.unquote(part_b))
                parents.append({"path": parent_path_b, "name": display_name})

        # Set up warning about in-progress backups, if necessary
        warning = False
        status = repo_obj.status
        if status[0] != 'ok':
            warning = status[1] + ' ' + _(
                "The displayed data may be inconsistent.")

        dir_entries = []
        restore_dates = []
        if restore:
            restore_dates = path_obj.change_dates[:-limit - 1:-1]
        else:
            # Get list of actual directory entries
            dir_entries = path_obj.dir_entries[::-1]

        parms = {
            "repo": repo_obj,
            "path": path_obj,
            "limit": limit,
            "dir_entries": dir_entries,
            "parents": parents,
            "restore_dates": restore_dates,
            "warning": warning
        }
        return self._compile_template("browse.html", **parms)
Beispiel #4
0
    def default(self, path=b"", limit='10', **kwargs):
        limit = validate_int(limit)

        repo_obj = self.app.store.get_repo(path)

        # Set up warning about in-progress backups, if necessary
        warning = False
        status = repo_obj.status
        if status[0] != 'ok':
            warning = status[1] + ' ' + _("The displayed data may be inconsistent.")

        parms = {
            "limit": limit,
            "repo": repo_obj,
            "history_entries": repo_obj.get_history_entries(numLatestEntries=limit, reverse=True),
            "warning": warning,
        }

        return self._compile_template("history.html", **parms)
Beispiel #5
0
 def _remove_older(self, repo_obj, keepdays=None, **kwargs):
     is_maintainer()
     validate_int(keepdays)
     # Update the database.
     repo_obj.keepdays = keepdays
     return _("Updated")
Beispiel #6
0
    def _users_handle_action(self, action, username, email, password,
                             user_root, role):

        success = ""

        # We need to change values. Change them, then give back that main
        # page again, with a message
        if username == self.app.currentuser.username:
            # Don't allow the user to changes it's "role" state.
            role = self.app.currentuser.role

        # Fork the behaviour according to the action.
        if action == "edit":
            # Validation
            validate_int(role, 'role should be an integer')
            validate(int(role) in ROLES, 'invalid role')

            user = self.app.store.get_user(username)
            logger.info("updating user [%s] info", user)
            if password:
                user.set_password(password, old_password=None)
            user.user_root = user_root
            user.role = role
            # Avoid updating the email fields is it didn'T changed. see pdsl/minarca#187
            if email != user.email:
                user.email = email
            success = _("User information modified successfully.")

            # Check and update user directory
            if user.user_root:
                self._check_user_root_dir(user.user_root)
                user.update_repos()

        elif action == "add":
            # Validation
            validate_int(role, 'role should be an integer')
            validate(int(role) in ROLES, 'invalid role')

            if username == "":
                raise RdiffWarning(_("The username is invalid."))
            logger.info("adding user [%s]", username)

            user = self.app.store.add_user(username, password)
            if user_root:
                user.user_root = user_root
            user.role = role
            user.email = email

            # Check and update user directory
            if user.user_root:
                self._check_user_root_dir(user.user_root)
                user.update_repos()
            success = _("User added successfully.")

        if action == "delete":
            if username == self.app.currentuser.username:
                raise RdiffWarning(_("You cannot remove your own account!"))
            user = self.app.store.get_user(username)
            if not user:
                raise RdiffWarning(_("User doesn't exists!"))
            try:
                user.delete()
            except ValueError as e:
                raise RdiffWarning(e)
            success = _("User account removed.")

        # Return messages
        return {'success': success}