-
Notifications
You must be signed in to change notification settings - Fork 1
Enhance project member management and update documentation #755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e34d095
Add project member repository
yuji38kwmt 705d823
Raise error when project member user is missing
yuji38kwmt 0417dc9
Revise project member repository docstrings
yuji38kwmt 02de3b7
Raise error when project member is missing
yuji38kwmt 5ac384a
`get_message_with_lang` : テストケースを更新し、型の無視を明示化
yuji38kwmt 83841fd
Use minimal typed dicts for annotation name helpers
yuji38kwmt c777c2e
Reduce casts for annotation spec name helpers
yuji38kwmt 394e341
Remove trailing whitespace in index.rst and add project_member_reposi…
yuji38kwmt 7d5cff5
index.rst: pydantic_modelsとmodelsの順序を修正
yuji38kwmt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| from collections.abc import Callable | ||
|
|
||
| import more_itertools | ||
|
|
||
| from annofabapi import Resource | ||
| from annofabapi.models import ProjectMember | ||
|
|
||
|
|
||
| class ProjectMemberRepository: | ||
| """プロジェクトメンバ情報を取得するRepository。""" | ||
|
|
||
| def __init__(self, resource: Resource) -> None: | ||
| self.resource = resource | ||
| self._members_by_project_id: dict[str, list[ProjectMember]] = {} | ||
|
|
||
| def _get_project_member_with_predicate(self, project_id: str, predicate: Callable[[ProjectMember], bool]) -> ProjectMember | None: | ||
| """条件に一致するプロジェクトメンバを取得する。 | ||
|
|
||
| プロジェクトメンバの一覧をプロジェクトIDごとにキャッシュする。 | ||
|
|
||
| Args: | ||
| project_id: プロジェクトID | ||
| predicate: プロジェクトメンバの検索条件 | ||
|
|
||
| Returns: | ||
| 条件に一致するプロジェクトメンバ。見つからない場合はNone。 | ||
| """ | ||
| project_member_list = self._members_by_project_id.get(project_id) | ||
| if project_member_list is None: | ||
| project_member_list = self.resource.wrapper.get_all_project_members(project_id, query_params={"include_inactive_member": True}) | ||
| self._members_by_project_id[project_id] = project_member_list | ||
| return more_itertools.first_true(project_member_list, pred=predicate) | ||
|
|
||
| def get_project_member_from_account_id(self, project_id: str, account_id: str) -> ProjectMember: | ||
| """account_idからプロジェクトメンバを取得する。 | ||
|
|
||
| Args: | ||
| project_id: プロジェクトID | ||
| account_id: アカウントID | ||
|
|
||
| Returns: | ||
| 指定したaccount_idのプロジェクトメンバ。 | ||
|
|
||
| Raises: | ||
| ValueError: 指定したaccount_idのプロジェクトメンバが見つからない場合。 | ||
| """ | ||
| member = self._get_project_member_with_predicate(project_id, predicate=lambda e: e["account_id"] == account_id) | ||
| if member is None: | ||
| raise ValueError(f"project_member is not found. project_id='{project_id}', account_id='{account_id}'") | ||
| return member | ||
|
|
||
| def get_project_member_from_user_id(self, project_id: str, user_id: str) -> ProjectMember: | ||
| """user_idからプロジェクトメンバを取得する。 | ||
|
|
||
| Args: | ||
| project_id: プロジェクトID | ||
| user_id: ユーザーID | ||
|
|
||
| Returns: | ||
| 指定したuser_idのプロジェクトメンバ。 | ||
|
|
||
| Raises: | ||
| ValueError: 指定したuser_idのプロジェクトメンバが見つからない場合。 | ||
| """ | ||
| member = self._get_project_member_with_predicate(project_id, predicate=lambda e: e["user_id"] == user_id) | ||
| if member is None: | ||
| raise ValueError(f"project_member is not found. project_id='{project_id}', user_id='{user_id}'") | ||
| return member | ||
|
|
||
| def get_user_id_from_account_id(self, project_id: str, account_id: str) -> str: | ||
| """account_idからuser_idを取得する。 | ||
|
|
||
| Args: | ||
| project_id: プロジェクトID | ||
| account_id: アカウントID | ||
|
|
||
| Returns: | ||
| 指定したaccount_idに対応するユーザーID。 | ||
|
|
||
| Raises: | ||
| ValueError: 指定したaccount_idのプロジェクトメンバが見つからない場合。 | ||
| """ | ||
| return self.get_project_member_from_account_id(project_id, account_id)["user_id"] | ||
|
|
||
| def get_account_id_from_user_id(self, project_id: str, user_id: str) -> str: | ||
| """user_idからaccount_idを取得する。 | ||
|
|
||
| Args: | ||
| project_id: プロジェクトID | ||
| user_id: ユーザーID | ||
|
|
||
| Returns: | ||
| 指定したuser_idに対応するアカウントID。 | ||
|
|
||
| Raises: | ||
| ValueError: 指定したuser_idのプロジェクトメンバが見つからない場合。 | ||
| """ | ||
| return self.get_project_member_from_user_id(project_id, user_id)["account_id"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| annofabapi.project_member_repository module | ||
| =========================================== | ||
|
|
||
|
|
||
|
|
||
| .. automodule:: annofabapi.project_member_repository | ||
| :members: |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.