def toDataForJSON(self, media_type): """See `IJSONPublishable`.""" if media_type != "application/json": raise ValueError("Unhandled media type %s" % media_type) request = get_current_browser_request() field = InlineObject(schema=IGitNascentRuleGrant).bind(self) marshaller = getMultiAdapter((field, request), IFieldMarshaller) return marshaller.unmarshall(None, self)
class IGitNascentRule(Interface): """An access rule in the process of being created. This represents parameters for a rule that have been deserialised from a webservice request, but that have not yet been attached to a repository. """ ref_pattern = copy_field(IGitRule["ref_pattern"]) grants = List(value_type=InlineObject(schema=IGitNascentRuleGrant))
def test_unmarshall(self): field = InlineObject(schema=IInlineExample) request = WebServiceTestRequest() request.setVirtualHostRoot(names=["devel"]) marshaller = InlineObjectFieldMarshaller(field, request) obj = InlineExample(self.factory.makePerson(), JobStatus.WAITING) result = marshaller.unmarshall(None, obj) self.assertThat( result, MatchesDict({ "person_link": Equals(canonical_url(obj.person, request=request)), "status": Equals("Waiting"), }))
def test_marshall_from_json_data(self): self.useFixture(ZopeAdapterFixture(inline_example_from_dict)) field = InlineObject(schema=IInlineExample) request = WebServiceTestRequest() request.setVirtualHostRoot(names=["devel"]) marshaller = InlineObjectFieldMarshaller(field, request) person = self.factory.makePerson() data = { "person_link": canonical_url(person, request=request), "status": "Running", } obj = marshaller.marshall_from_json_data(data) self.assertThat( obj, MatchesStructure.byEquality(person=person, status=JobStatus.RUNNING))
class IGitRefEdit(Interface): """IGitRef methods that require launchpad.Edit permission.""" @export_read_operation() @operation_for_version("devel") def getGrants(): """Get the access grants specific to this reference. Other grants may apply via wildcard rules. """ @operation_parameters(grants=List( title=_("Grants"), # Really IGitNascentRuleGrant, patched in # _schema_circular_imports.py. value_type=InlineObject(schema=Interface), description=_( dedent("""\ The new list of grants for this reference. For example:: [ { "grantee_type": "Repository owner", "can_create": true, "can_push": true, "can_force_push": true }, { "grantee_type": "Person", "grantee_link": "/~example-person", "can_push": true } ]""")))) @call_with(user=REQUEST_USER) @export_write_operation() @operation_for_version("devel") def setGrants(grants, user): """Set the access grants specific to this reference. Other grants may apply via wildcard rules. """ @operation_parameters(person=Reference(title=_("Person to check"), schema=IPerson)) @export_read_operation() @operation_for_version("devel") def checkPermissions(person): """Check a person's permissions on this reference.
class IGitRepositoryEdit(IWebhookTarget): """IGitRepository methods that require launchpad.Edit permission.""" @mutator_for(IGitRepositoryView["name"]) @call_with(user=REQUEST_USER) @operation_parameters( new_name=TextLine(title=_("The new name of the repository."))) @export_write_operation() @operation_for_version("devel") def setName(new_name, user): """Set the name of the repository to be `new_name`.""" @mutator_for(IGitRepositoryView["owner"]) @call_with(user=REQUEST_USER) @operation_parameters(new_owner=Reference( title=_("The new owner of the repository."), schema=IPerson)) @export_write_operation() @operation_for_version("devel") def setOwner(new_owner, user): """Set the owner of the repository to be `new_owner`.""" @mutator_for(IGitRepositoryView["target"]) @call_with(user=REQUEST_USER) @operation_parameters(target=Reference(title=_( "The project, distribution source package, or person the " "repository belongs to."), schema=IHasGitRepositories, required=True)) @export_write_operation() @operation_for_version("devel") def setTarget(target, user): """Set the target of the repository.""" @export_write_operation() @operation_for_version("devel") def rescan(): """Force a rescan of this repository. This may be helpful in cases where a previous scan crashed. """ def addRule(ref_pattern, creator, position=None): """Add an access rule to this repository. :param ref_pattern: The reference pattern that the new rule should match. :param creator: The `IPerson` who is adding the rule. :param position: The list position at which to insert the rule, or None to append it. """ def moveRule(rule, position, user): """Move a rule to a new position in its repository's rule order. :param rule: The `IGitRule` to move. :param position: The new position. For example, 0 puts the rule at the start, while `len(repository.rules)` puts the rule at the end. If the new position is before the end of the list, then other rules are shifted to later positions to make room. :param user: The `IPerson` who is moving the rule. """ def findRuleGrantsByGrantee(grantee, include_transitive=True, ref_pattern=None): """Find the grants for a grantee applied to this repository. :param grantee: The `IPerson` to search for, or an item of `GitGranteeType` other than `GitGranteeType.PERSON` to search for some other kind of entity. :param include_transitive: If False, match `grantee` exactly; if True (the default), also accept teams of which `grantee` is a member. :param ref_pattern: If not None, only return grants for rules with this ref_pattern. """ @export_read_operation() @operation_for_version("devel") def getRules(): """Get the access rules for this repository.""" @operation_parameters(rules=List( title=_("Rules"), # Really IGitNascentRule, patched in # _schema_circular_imports.py. value_type=InlineObject(schema=Interface), description=_( dedent("""\ The new list of rules for this repository. For example:: [ { "ref_pattern": "refs/heads/*", "grants": [ { "grantee_type": "Repository owner", "can_create": true, "can_push": true, "can_force_push": true } ] }, { "ref_pattern": "refs/heads/stable/*", "grants": [ { "grantee_type": "Person", "grantee_link": "/~example-stable-team", "can_create": true, "can_push": true } ] } ]""")))) @call_with(user=REQUEST_USER) @export_write_operation() @operation_for_version("devel") def setRules(rules, user): """Set the access rules for this repository.""" def checkRefPermissions(person, ref_paths): """Check a person's permissions on some references in this repository. :param person: An `IPerson` to check, or `GitGranteeType.REPOSITORY_OWNER` to check an anonymous repository owner. :param ref_paths: An iterable of reference paths (each of which may be either bytes or text). :return: A dict mapping reference paths to sets of `GitPermissionType`, corresponding to the requested person's effective permissions on each of the requested references. """ @operation_parameters(person=Reference(title=_("Person to check"), schema=IPerson), paths=List(title=_("Reference paths"), value_type=TextLine())) @export_operation_as("checkRefPermissions") @export_read_operation() @operation_for_version("devel") def api_checkRefPermissions(person, paths): """Check a person's permissions on some references in this repository. :param person: An `IPerson` to check. :param paths: An iterable of reference paths. :return: A dict mapping reference paths to lists of zero or more of "create", "push", and "force-push", indicating the requested person's effective permissions on each of the requested references. """ @export_read_operation() @operation_for_version("devel") def canBeDeleted(): """Can this repository be deleted in its current state? A repository is considered deletable if it is not linked to any merge proposals. """ def getDeletionRequirements(eager_load=False): """Determine what is required to delete this branch. :param eager_load: If True, preload related information needed to display the deletion requirements. :return: a dict of {object: (operation, reason)}, where object is the object that must be deleted or altered, operation is either "delete" or "alter", and reason is a string explaining why the object needs to be touched. """ @call_with(break_references=True) @export_destructor_operation() @operation_for_version("devel") def destroySelf(break_references=False): """Delete the specified repository.
# IGitRef patch_reference_property(IGitRef, 'repository', IGitRepository) patch_plain_parameter_type( IGitRef, 'createMergeProposal', 'merge_target', IGitRef) patch_plain_parameter_type( IGitRef, 'createMergeProposal', 'merge_prerequisite', IGitRef) patch_collection_property( IGitRef, '_api_landing_targets', IBranchMergeProposal) patch_collection_property( IGitRef, '_api_landing_candidates', IBranchMergeProposal) patch_collection_property(IGitRef, 'dependent_landings', IBranchMergeProposal) patch_entry_return_type(IGitRef, 'createMergeProposal', IBranchMergeProposal) patch_collection_return_type( IGitRef, 'getMergeProposals', IBranchMergeProposal) patch_list_parameter_type( IGitRef, 'setGrants', 'grants', InlineObject(schema=IGitNascentRuleGrant)) # IGitRepository patch_collection_property(IGitRepository, 'branches', IGitRef) patch_collection_property(IGitRepository, 'refs', IGitRef) patch_collection_property(IGitRepository, 'subscriptions', IGitSubscription) patch_entry_return_type(IGitRepository, 'subscribe', IGitSubscription) patch_entry_return_type(IGitRepository, 'getSubscription', IGitSubscription) patch_reference_property(IGitRepository, 'code_import', ICodeImport) patch_entry_return_type(IGitRepository, 'getRefByPath', IGitRef) patch_collection_property( IGitRepository, '_api_landing_targets', IBranchMergeProposal) patch_collection_property( IGitRepository, '_api_landing_candidates', IBranchMergeProposal) patch_collection_property( IGitRepository, 'dependent_landings', IBranchMergeProposal)