Exemplo n.º 1
0
    def single(parameters, argument):
        """Retrieve one (or more) extensions by id.

           EXTENSION_ID : integer

           Retrieve an extension identified by its unique numeric id."""

        value = api.extension.fetch(parameters.critic,
                                    jsonapi.numeric_id(argument))

        if "users" in parameters.context:
            if value.publisher != parameters.context["users"]:
                raise InvalidExtensionId(jsonapi.numeric_id(argument))

        return value
Exemplo n.º 2
0
    def single(parameters, argument):
        """Retrieve one (or more) extensions by id.

           EXTENSION_ID : integer

           Retrieve an extension identified by its unique numeric id."""

        value = api.extension.fetch(parameters.critic,
                                    jsonapi.numeric_id(argument))

        if "users" in parameters.context:
            if value.publisher != parameters.context["users"]:
                raise InvalidExtensionId(jsonapi.numeric_id(argument))

        return value
Exemplo n.º 3
0
    def single(parameters, argument):
        """Retrieve one (or more) access tokens.

           TOKEN_ID : integer

           Retrieve an access token identified by its unique numeric id."""

        value = api.accesstoken.fetch(parameters.critic,
                                      jsonapi.numeric_id(argument))

        if "users" in parameters.context:
            if value.user != parameters.context["users"]:
                raise InvalidAccessTokenId(jsonapi.numeric_id(argument))

        return value
Exemplo n.º 4
0
    def single(parameters, argument):
        """Retrieve one (or more) access tokens.

           TOKEN_ID : integer

           Retrieve an access token identified by its unique numeric id."""

        value = api.accesstoken.fetch(parameters.critic,
                                      jsonapi.numeric_id(argument))

        if "users" in parameters.context:
            if value.user != parameters.context["users"]:
                raise InvalidAccessTokenId(jsonapi.numeric_id(argument))

        return value
Exemplo n.º 5
0
    def single(critic, context, argument, parameters):
        """Retrieve one (or more) users of this system.

           USER_ID : integer

           Retrieve a user identified by the user's unique numeric id."""

        return api.user.fetch(critic, user_id=jsonapi.numeric_id(argument))
Exemplo n.º 6
0
    def single(critic, context, argument, parameters):
        """Retrieve one (or more) branches in the Git repositories.

           BRANCH_ID : integer

           Retrieve a branch identified by its unique numeric id."""

        return api.branch.fetch(critic, branch_id=jsonapi.numeric_id(argument))
Exemplo n.º 7
0
    def single(parameters, argument):
        """Retrieve one (or more) files.

           FILE_ID : integer

           Retrieve a file identified by its unique numeric id."""

        return api.file.fetch(
            parameters.critic, file_id=jsonapi.numeric_id(argument))
Exemplo n.º 8
0
    def single(critic, context, argument, parameters):
        """Retrieve one (or more) repositories on this system.

           REPOSITORY_ID : integer

           Retrieve a repository identified by its unique numeric id."""

        return api.repository.fetch(
            critic, repository_id=jsonapi.numeric_id(argument))
Exemplo n.º 9
0
    def single(parameters, argument):
        """Retrieve one (or more) reviews in this system.

           REVIEW_ID : integer

           Retrieve a review identified by its unique numeric id."""

        return Reviews.setAsContext(parameters, api.review.fetch(
            parameters.critic, review_id=jsonapi.numeric_id(argument)))
Exemplo n.º 10
0
    def single(parameters, argument):
        """Retrieve one (or more) rebases in this system.

           REBASE_ID : integer

           Retrieve a rebase identified by its unique numeric id."""

        return Rebases.setAsContext(parameters, api.log.rebase.fetch(
            parameters.critic, rebase_id=jsonapi.numeric_id(argument)))
Exemplo n.º 11
0
    def single(parameters, argument):
        """Retrieve one (or more) repositories on this system.

           REPOSITORY_ID : integer

           Retrieve a repository identified by its unique numeric id."""

        return Repositories.setAsContext(parameters, api.repository.fetch(
            parameters.critic, repository_id=jsonapi.numeric_id(argument)))
Exemplo n.º 12
0
    def single(critic, argument, parameters):
        """Retrieve one (or more) reviews in this system.

           REVIEW_ID : integer

           Retrieve a review identified by its unique numeric id."""

        return Reviews.setAsContext(
            parameters,
            api.review.fetch(critic, review_id=jsonapi.numeric_id(argument)))
Exemplo n.º 13
0
 def deduce(critic, parameters):
     review = parameters.context.get("reviews")
     review_parameter = parameters.getQueryParameter("review")
     if review_parameter is not None:
         if review is not None:
             raise jsonapi.UsageError(
                 "Redundant query parameter: review=%s" % review_parameter)
         review = api.review.fetch(
             critic, review_id=jsonapi.numeric_id(review_parameter))
     return review
Exemplo n.º 14
0
    def single(parameters, argument):
        """Retrieve one (or more) reviewable file change.

           FILECHANGE_ID : integer

           Retrieve the reviewable changes to a file in a commit identified by
           its unique numeric id."""

        return api.reviewablefilechange.fetch(parameters.critic,
                                              jsonapi.numeric_id(argument))
Exemplo n.º 15
0
 def deduce(parameters):
     batch = parameters.context.get("batches")
     batch_parameter = parameters.getQueryParameter("batch")
     if batch_parameter is not None:
         if batch is not None:
             raise jsonapi.UsageError(
                 "Redundant query parameter: batch=%s" % batch_parameter)
         batch = api.batch.fetch(
             parameters.critic, jsonapi.numeric_id(batch_parameter))
     return batch
Exemplo n.º 16
0
    def single(parameters, argument):
        """Retrieve one (or more) access control profiles.

           PROFILE_ID : integer

           Retrieve an access control profile identified by the profile's unique
           numeric id."""

        return api.accesscontrolprofile.fetch(
            parameters.critic, profile_id=jsonapi.numeric_id(argument))
Exemplo n.º 17
0
 def deduce(critic, parameters):
     review = parameters.context.get("reviews")
     review_parameter = parameters.getQueryParameter("review")
     if review_parameter is not None:
         if review is not None:
             raise jsonapi.UsageError(
                 "Redundant query parameter: review=%s" % review_parameter)
         review = api.review.fetch(
             critic, review_id=jsonapi.numeric_id(review_parameter))
     return review
Exemplo n.º 18
0
    def single(parameters, argument):
        """Retrieve one (or more) reviewable file change.

           FILECHANGE_ID : integer

           Retrieve the reviewable changes to a file in a commit identified by
           its unique numeric id."""

        return api.reviewablefilechange.fetch(
            parameters.critic, jsonapi.numeric_id(argument))
Exemplo n.º 19
0
    def single(critic, argument, parameters):
        """Retrieve one (or more) users of this system.

           USER_ID : integer

           Retrieve a user identified by the user's unique numeric id."""

        return Users.setAsContext(
            parameters,
            api.user.fetch(critic, user_id=jsonapi.numeric_id(argument)))
Exemplo n.º 20
0
    def single(parameters, argument):
        """Retrieve one (or more) access control profiles.

           PROFILE_ID : integer

           Retrieve an access control profile identified by the profile's unique
           numeric id."""

        return api.accesscontrolprofile.fetch(
            parameters.critic, profile_id=jsonapi.numeric_id(argument))
Exemplo n.º 21
0
    def single(critic, argument, parameters):
        """Retrieve one (or more) branches in the Git repositories.

           BRANCH_ID : integer

           Retrieve a branch identified by its unique numeric id."""

        return Branches.setAsContext(
            parameters,
            api.branch.fetch(critic, branch_id=jsonapi.numeric_id(argument)))
Exemplo n.º 22
0
 def deduce(parameters):
     profile = parameters.context.get("accesscontrolprofiles")
     profile_parameter = parameters.getQueryParameter("profile")
     if profile_parameter is not None:
         if profile is not None:
             raise jsonapi.UsageError(
                 "Redundant query parameter: profile=%s" % profile_parameter)
         profile_id = jsonapi.numeric_id(profile_parameter)
         profile = api.accesscontrolprofile.fetch(
             parameters.critic, profile_id=profile_id)
     return profile
Exemplo n.º 23
0
    def single(critic, argument, parameters):
        """Retrieve one (or more) rebases in this system.

           REBASE_ID : integer

           Retrieve a rebase identified by its unique numeric id."""

        return Rebases.setAsContext(
            parameters,
            api.log.rebase.fetch(critic,
                                 rebase_id=jsonapi.numeric_id(argument)))
Exemplo n.º 24
0
 def deduce(parameters):
     comment = parameters.context.get("comments")
     comment_parameter = parameters.getQueryParameter("comment")
     if comment_parameter is not None:
         if comment is not None:
             raise jsonapi.UsageError(
                 "Redundant query parameter: comment=%s" % comment_parameter)
         comment = api.comment.fetch(
             parameters.critic,
             comment_id=jsonapi.numeric_id(comment_parameter))
     return comment
Exemplo n.º 25
0
 def deduce(parameters):
     profile = parameters.context.get("accesscontrolprofiles")
     profile_parameter = parameters.getQueryParameter("profile")
     if profile_parameter is not None:
         if profile is not None:
             raise jsonapi.UsageError(
                 "Redundant query parameter: profile=%s" %
                 profile_parameter)
         profile_id = jsonapi.numeric_id(profile_parameter)
         profile = api.accesscontrolprofile.fetch(parameters.critic,
                                                  profile_id=profile_id)
     return profile
Exemplo n.º 26
0
 def deduce(parameters):
     comment = parameters.context.get("comments")
     comment_parameter = parameters.getQueryParameter("comment")
     if comment_parameter is not None:
         if comment is not None:
             raise jsonapi.UsageError(
                 "Redundant query parameter: comment=%s" %
                 comment_parameter)
         comment = api.comment.fetch(
             parameters.critic,
             comment_id=jsonapi.numeric_id(comment_parameter))
     return comment
Exemplo n.º 27
0
    def single(parameters, argument):
        """A primary email address by index.

           INDEX : integer

           Retrieve a primary email address identified by its index."""

        emails = list(parameters.context["users"].primary_emails)

        try:
            return emails[jsonapi.numeric_id(argument) - 1]
        except IndexError:
            raise jsonapi.PathError("List index out of range")
Exemplo n.º 28
0
    def single(parameters, argument):
        """A primary email address by index.

           INDEX : integer

           Retrieve a primary email address identified by its index."""

        emails = list(parameters.context["users"].primary_emails)

        try:
            return emails[jsonapi.numeric_id(argument) - 1]
        except IndexError:
            raise jsonapi.PathError("List index out of range")
Exemplo n.º 29
0
 def deduce(parameters):
     changeset = jsonapi.deduce("v1/changesets", parameters)
     if changeset is None:
         raise jsonapi.UsageError(
             "changeset needs to be specified, ex. &changeset=<id>")
     filechange = parameters.context.get(FileChanges.name)
     filechange_parameter = parameters.getQueryParameter("filechange")
     if filechange_parameter is not None:
         if filechange is not None:
             raise jsonapi.UsageError(
                 "Redundant query parameter: filechange=%s"
                 % filechange_parameter)
         filechange_id = jsonapi.numeric_id(filechange_parameter)
         filechange = api.filechange.fetch(
             parameters.critic, changeset, filechange_id)
     return filechange
Exemplo n.º 30
0
 def deduce(parameters):
     changeset = jsonapi.deduce("v1/changesets", parameters)
     if changeset is None:
         raise jsonapi.UsageError(
             "changeset needs to be specified, ex. &changeset=<id>")
     filechange = parameters.context.get(FileChanges.name)
     filechange_parameter = parameters.getQueryParameter("filechange")
     if filechange_parameter is not None:
         if filechange is not None:
             raise jsonapi.UsageError(
                 "Redundant query parameter: filechange=%s" %
                 filechange_parameter)
         filechange_id = jsonapi.numeric_id(filechange_parameter)
         filechange = api.filechange.fetch(parameters.critic, changeset,
                                           filechange_id)
     return filechange
Exemplo n.º 31
0
    def single(parameters, argument):
        """Retrieve one (or more) of a user's repository filters.

           FILTER_ID : integer

           Retrieve a filter identified by the filters's unique numeric id."""

        user = parameters.context["users"]
        filter_id = jsonapi.numeric_id(argument)

        for repository_filters in user.repository_filters.values():
            for repository_filter in repository_filters:
                if repository_filter.id == filter_id:
                    return repository_filter

        raise KeyError("invalid filter id: %d" % filter_id)
Exemplo n.º 32
0
    def single(parameters, argument):
        """Retrieve one (or more) users of this system.

           USER_ID : integer or "me"

           Retrieve a user identified by the user's unique numeric id, or the
           identifier "me" to retrieve the current user."""

        if argument == "me":
            user = parameters.critic.actual_user
            if user is None:
                raise api.user.UserError("'users/me' (not signed in)")
        else:
            user = api.user.fetch(parameters.critic,
                                  user_id=jsonapi.numeric_id(argument))
        return Users.setAsContext(parameters, user)
Exemplo n.º 33
0
    def single(parameters, argument):
        """Retrieve one (or more) replies to comments.

           REPLY_ID : integer

           Retrieve a reply identified by its unique numeric id."""

        reply = api.reply.fetch(parameters.critic,
                                reply_id=jsonapi.numeric_id(argument))

        comment = jsonapi.deduce("v1/comments", parameters)
        if comment and comment != reply.comment:
            raise jsonapi.PathError(
                "Reply does not belong to specified comment")

        return reply
Exemplo n.º 34
0
 def deduce(parameters):
     repository = jsonapi.deduce("v1/repositories", parameters)
     changeset = parameters.context.get(Changesets.name)
     changeset_parameter = parameters.getQueryParameter("changeset")
     if changeset_parameter is not None:
         if changeset is not None:
             raise jsonapi.UsageError(
                 "Redundant query parameter: changeset=%s"
                 % changeset_parameter)
         if repository is None:
             raise jsonapi.UsageError(
                 "repository needs to be specified, ex. &repository=<id>")
         changeset_id = jsonapi.numeric_id(changeset_parameter)
         changeset = api.changeset.fetch(
             parameters.critic, repository, changeset_id=changeset_id)
     return changeset
Exemplo n.º 35
0
    def single(parameters, argument):
        """Retrieve one (or more) users of this system.

           USER_ID : integer or "me"

           Retrieve a user identified by the user's unique numeric id, or the
           identifier "me" to retrieve the current user."""

        if argument == "me":
            user = parameters.critic.actual_user
            if user is None:
                raise api.user.UserError("'users/me' (not signed in)")
        else:
            user = api.user.fetch(parameters.critic,
                                  user_id=jsonapi.numeric_id(argument))
        return Users.setAsContext(parameters, user)
Exemplo n.º 36
0
    def single(parameters, argument):
        """Retrieve one (or more) of a user's repository filters.

           FILTER_ID : integer

           Retrieve a filter identified by the filters's unique numeric id."""

        user = parameters.context["users"]
        filter_id = jsonapi.numeric_id(argument)

        for repository_filters in user.repository_filters.values():
            for repository_filter in repository_filters:
                if repository_filter.id == filter_id:
                    return repository_filter

        raise KeyError("invalid filter id: %d" % filter_id)
Exemplo n.º 37
0
    def single(parameters, argument):
        """Retrieve one (or more) comments in reviews.

           COMMENT_ID : integer

           Retrieve a comment identified by its unique numeric id."""

        comment = api.comment.fetch(parameters.critic,
                                    comment_id=jsonapi.numeric_id(argument))

        review = jsonapi.deduce("v1/reviews", parameters)
        if review and review != comment.review:
            raise jsonapi.PathError(
                "Comment does not belong to specified review")

        return Comments.setAsContext(parameters, comment)
Exemplo n.º 38
0
    def single(parameters, argument):
        """Retrieve one (or more) batches in reviews.

           BATCH_ID : integer

           Retrieve a batch identified by its unique numeric id."""

        batch = api.batch.fetch(
            parameters.critic, batch_id=jsonapi.numeric_id(argument))

        review = jsonapi.deduce("v1/reviews", parameters)
        if review and review != batch.review:
            raise jsonapi.PathError(
                "Batch does not belong to specified review")

        return Batches.setAsContext(parameters, batch)
Exemplo n.º 39
0
    def single(parameters, argument):
        """Retrieve one (or more) comments in reviews.

           COMMENT_ID : integer

           Retrieve a comment identified by its unique numeric id."""

        comment = api.comment.fetch(
            parameters.critic, comment_id=jsonapi.numeric_id(argument))

        review = jsonapi.deduce("v1/reviews", parameters)
        if review and review != comment.review:
            raise jsonapi.PathError(
                "Comment does not belong to specified review")

        return Comments.setAsContext(parameters, comment)
Exemplo n.º 40
0
    def single(parameters, argument):
        """Retrieve one (or more) replies to comments.

           REPLY_ID : integer

           Retrieve a reply identified by its unique numeric id."""

        reply = api.reply.fetch(
            parameters.critic, reply_id=jsonapi.numeric_id(argument))

        comment = jsonapi.deduce("v1/comments", parameters)
        if comment and comment != reply.comment:
            raise jsonapi.PathError(
                "Reply does not belong to specified comment")

        return reply
Exemplo n.º 41
0
    def single(parameters, argument):
        """TODO: add documentation"""

        changeset = jsonapi.deduce("v1/changesets", parameters)
        if changeset is None:
            raise jsonapi.UsageError(
                "changeset needs to be specified, ex. &changeset=<id>")

        repository = jsonapi.deduce("v1/repositories", parameters)
        if repository is None:
            raise jsonapi.UsageError(
                "repository needs to be specified, "
                "ex. &repository=<id or name>")

        file = api.file.fetch(parameters.critic, jsonapi.numeric_id(argument))
        filechange = api.filechange.fetch(parameters.critic, changeset, file)

        return api.filediff.fetch(parameters.critic, filechange)
Exemplo n.º 42
0
    def single(parameters, argument):
        """Retrieve one (or more) commits from a Git repository.

           COMMIT_ID : integer

           Retrieve a commit identified by its unique numeric id.

           repository : REPOSITORY : -

           Specify repository to access, identified by its unique numeric id or
           short-name.  Required unless a repository is specified in the
           resource path."""

        repository = jsonapi.deduce("v1/repositories", parameters)
        if repository is None:
            raise jsonapi.UsageError(
                "Commit reference must have repository specified.")
        return Commits.setAsContext(parameters, api.commit.fetch(
            repository, commit_id=jsonapi.numeric_id(argument)))
Exemplo n.º 43
0
    def single(parameters, argument):
        """Retrieve one (or more) filechanges (changed files).

           FILE_ID : integer

           Retrieve the changes to a file identified by its unique numeric id.

           changeset : CHANGESET : -

           Retrieve the changes from a changeset identified by its unique numeric id.

           reposititory : REPOSITORY : -

           The repository in which the files exist."""

        changeset = jsonapi.deduce("v1/changesets", parameters)
        file = api.file.fetch(parameters.critic, jsonapi.numeric_id(argument))

        return FileChanges.setAsContext(
            parameters, api.filechange.fetch(parameters.critic, changeset,
                                             file))
Exemplo n.º 44
0
    def single(parameters, argument):
        """Retrieve one (or more) filechanges (changed files).

           FILE_ID : integer

           Retrieve the changes to a file identified by its unique numeric id.

           changeset : CHANGESET : -

           Retrieve the changes from a changeset identified by its unique numeric id.

           reposititory : REPOSITORY : -

           The repository in which the files exist."""

        changeset = jsonapi.deduce("v1/changesets", parameters)
        file = api.file.fetch(parameters.critic, jsonapi.numeric_id(argument))

        return FileChanges.setAsContext(
            parameters, api.filechange.fetch(
                parameters.critic, changeset, file))
Exemplo n.º 45
0
    def single(parameters, argument):
        """Retrieve one (or more) commits from a Git repository.

           COMMIT_ID : integer

           Retrieve a commit identified by its unique numeric id.

           repository : REPOSITORY : -

           Specify repository to access, identified by its unique numeric id or
           short-name.  Required unless a repository is specified in the
           resource path."""

        repository = jsonapi.deduce("v1/repositories", parameters)
        if repository is None:
            raise jsonapi.UsageError(
                "Commit reference must have repository specified.")
        return Commits.setAsContext(
            parameters,
            api.commit.fetch(repository,
                             commit_id=jsonapi.numeric_id(argument)))
Exemplo n.º 46
0
    def single(parameters, argument):
        """Retrieve one (or more) changesets.

           CHANGESET_ID : integer

           Retrieve a changeset identified by its unique numeric id.

           repository : REPOSITORY : -

           Specify repository to access, identified by its unique numeric id or
           short-name.  Required unless a repository is specified in the
           resource path."""

        repository = jsonapi.deduce("v1/repositories", parameters)
        if repository is None:
            raise jsonapi.UsageError(
                "repository needs to be specified, ex. &repository=<id>")
        return Changesets.setAsContext(parameters,
                                       api.changeset.fetch(
                                           parameters.critic,
                                           repository,
                                           jsonapi.numeric_id(argument)))
Exemplo n.º 47
0
 def fromParameter(value, parameters):
     return api.reply.fetch(parameters.critic, jsonapi.numeric_id(value))
Exemplo n.º 48
0
 def fromParameter(value, parameters):
     return api.reply.fetch(parameters.critic, jsonapi.numeric_id(value))