Loading lib/galaxy/files/sources/_rdm.py +8 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ OptionalUserContext = Optional[ProvidesUserFileSourcesUserContext] class RDMFilesSourceProperties(FilesSourceProperties): url: str token: str public_name: str class RecordFilename(NamedTuple): Loading Loading @@ -79,7 +80,9 @@ class RDMRepositoryInteractor: """ raise NotImplementedError() def create_draft_record(self, title: str, user_context: OptionalUserContext = None): def create_draft_record( self, title: str, public_name: Optional[str] = None, user_context: OptionalUserContext = None ): """Creates a draft record (directory) in the repository with basic metadata. The metadata is usually just the title of the record and the user that created it. Loading Loading @@ -200,3 +203,7 @@ class RDMFilesSource(BaseFilesSource): f"Please provide a personal access token in your user's preferences for '{self.label}'" ) return token def get_public_name(self, user_context: OptionalUserContext) -> Optional[str]: effective_props = self._serialization_props(user_context) return effective_props.get("public_name") lib/galaxy/files/sources/invenio.py +18 −12 Original line number Diff line number Diff line Loading @@ -135,7 +135,8 @@ class InvenioRDMFilesSource(RDMFilesSource): user_context: OptionalUserContext = None, opts: Optional[FilesSourceOptions] = None, ) -> Entry: record = self.repository.create_draft_record(entry_data["name"], user_context=user_context) public_name = self.get_public_name(user_context) record = self.repository.create_draft_record(entry_data["name"], public_name, user_context=user_context) return { "uri": self.repository.to_plugin_uri(record["id"]), "name": record["metadata"]["title"], Loading Loading @@ -198,9 +199,11 @@ class InvenioRepositoryInteractor(RDMRepositoryInteractor): response_data = self._get_response(user_context, request_url) return self._get_record_files_from_response(record_id, response_data) def create_draft_record(self, title: str, user_context: OptionalUserContext = None) -> RemoteDirectory: def create_draft_record( self, title: str, public_name: Optional[str] = None, user_context: OptionalUserContext = None ) -> RemoteDirectory: today = datetime.date.today().isoformat() creator = self._get_creator_from_user_context(user_context) creator = self._get_creator_from_public_name(public_name) create_record_request = { "files": {"enabled": True}, "metadata": { Loading Loading @@ -360,10 +363,9 @@ class InvenioRepositoryInteractor(RDMRepositoryInteractor): ) return rval def _get_creator_from_user_context(self, user_context: OptionalUserContext): public_name = self.get_user_preference_by_key("public_name", user_context) family_name = "Galaxy User" def _get_creator_from_public_name(self, public_name: Optional[str] = None) -> Creator: given_name = "Anonymous" family_name = "Galaxy User" if public_name: tokens = public_name.split(", ") if len(tokens) == 2: Loading @@ -371,12 +373,16 @@ class InvenioRepositoryInteractor(RDMRepositoryInteractor): given_name = tokens[1] else: given_name = public_name return {"person_or_org": {"family_name": family_name, "given_name": given_name, "type": "personal"}} def get_user_preference_by_key(self, key: str, user_context: OptionalUserContext): preferences = user_context.preferences if user_context else None value = preferences.get(f"{self.plugin.id}|{key}", None) if preferences else None return value return { "person_or_org": { "name": f"{given_name} {family_name}", "family_name": family_name, "given_name": given_name, "type": "personal", "identifiers": [], }, "affiliations": [], } def _get_response( self, user_context: OptionalUserContext, request_url: str, params: Optional[Dict[str, Any]] = None Loading Loading
lib/galaxy/files/sources/_rdm.py +8 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ OptionalUserContext = Optional[ProvidesUserFileSourcesUserContext] class RDMFilesSourceProperties(FilesSourceProperties): url: str token: str public_name: str class RecordFilename(NamedTuple): Loading Loading @@ -79,7 +80,9 @@ class RDMRepositoryInteractor: """ raise NotImplementedError() def create_draft_record(self, title: str, user_context: OptionalUserContext = None): def create_draft_record( self, title: str, public_name: Optional[str] = None, user_context: OptionalUserContext = None ): """Creates a draft record (directory) in the repository with basic metadata. The metadata is usually just the title of the record and the user that created it. Loading Loading @@ -200,3 +203,7 @@ class RDMFilesSource(BaseFilesSource): f"Please provide a personal access token in your user's preferences for '{self.label}'" ) return token def get_public_name(self, user_context: OptionalUserContext) -> Optional[str]: effective_props = self._serialization_props(user_context) return effective_props.get("public_name")
lib/galaxy/files/sources/invenio.py +18 −12 Original line number Diff line number Diff line Loading @@ -135,7 +135,8 @@ class InvenioRDMFilesSource(RDMFilesSource): user_context: OptionalUserContext = None, opts: Optional[FilesSourceOptions] = None, ) -> Entry: record = self.repository.create_draft_record(entry_data["name"], user_context=user_context) public_name = self.get_public_name(user_context) record = self.repository.create_draft_record(entry_data["name"], public_name, user_context=user_context) return { "uri": self.repository.to_plugin_uri(record["id"]), "name": record["metadata"]["title"], Loading Loading @@ -198,9 +199,11 @@ class InvenioRepositoryInteractor(RDMRepositoryInteractor): response_data = self._get_response(user_context, request_url) return self._get_record_files_from_response(record_id, response_data) def create_draft_record(self, title: str, user_context: OptionalUserContext = None) -> RemoteDirectory: def create_draft_record( self, title: str, public_name: Optional[str] = None, user_context: OptionalUserContext = None ) -> RemoteDirectory: today = datetime.date.today().isoformat() creator = self._get_creator_from_user_context(user_context) creator = self._get_creator_from_public_name(public_name) create_record_request = { "files": {"enabled": True}, "metadata": { Loading Loading @@ -360,10 +363,9 @@ class InvenioRepositoryInteractor(RDMRepositoryInteractor): ) return rval def _get_creator_from_user_context(self, user_context: OptionalUserContext): public_name = self.get_user_preference_by_key("public_name", user_context) family_name = "Galaxy User" def _get_creator_from_public_name(self, public_name: Optional[str] = None) -> Creator: given_name = "Anonymous" family_name = "Galaxy User" if public_name: tokens = public_name.split(", ") if len(tokens) == 2: Loading @@ -371,12 +373,16 @@ class InvenioRepositoryInteractor(RDMRepositoryInteractor): given_name = tokens[1] else: given_name = public_name return {"person_or_org": {"family_name": family_name, "given_name": given_name, "type": "personal"}} def get_user_preference_by_key(self, key: str, user_context: OptionalUserContext): preferences = user_context.preferences if user_context else None value = preferences.get(f"{self.plugin.id}|{key}", None) if preferences else None return value return { "person_or_org": { "name": f"{given_name} {family_name}", "family_name": family_name, "given_name": given_name, "type": "personal", "identifiers": [], }, "affiliations": [], } def _get_response( self, user_context: OptionalUserContext, request_url: str, params: Optional[Dict[str, Any]] = None Loading