1
0

Fixed client handling of is_archived

This commit is contained in:
Jon Michael Aanes 2024-10-02 10:31:42 +02:00
parent c7ccecf61d
commit 9fff7b972f
5 changed files with 46 additions and 37 deletions

View File

@ -228,7 +228,7 @@ class FavroClient:
'name': card_contents.name, 'name': card_contents.name,
'detailedDescription': card_contents.description, 'detailedDescription': card_contents.description,
'descriptionFormat': 'markdown', 'descriptionFormat': 'markdown',
'archived': card_contents.archived, 'archived': card_contents.is_archived,
} }
url = URL_UPDATE_CARD.format(card_id=card_id.raw_id) url = URL_UPDATE_CARD.format(card_id=card_id.raw_id)

View File

@ -227,7 +227,6 @@ class Card:
due_date: datetime.date | None due_date: datetime.date | None
attachments: list[dict] attachments: list[dict]
detailed_description: str | None detailed_description: str | None
archived: bool
@staticmethod @staticmethod
def from_json(json: dict[str, Any]) -> 'Card': def from_json(json: dict[str, Any]) -> 'Card':
@ -256,7 +255,6 @@ class Card:
custom_fields=[ custom_fields=[
CustomField.from_json(field) for field in json['customFields'] CustomField.from_json(field) for field in json['customFields']
], ],
archived=json['archived'],
attachments=json['attachments'], # TODO attachments=json['attachments'], # TODO
) )

View File

@ -58,6 +58,37 @@ class CardFileSystemItem(FileSystemItem):
seq_id: SeqId seq_id: SeqId
def to_card_contents(card: Card, favro_client: FavroClient) -> str:
tags = [favro_client.get_tag(tag_id).name for tag_id in card.tags]
assignments = [
favro_client.get_user(assignment.user).name
for assignment in card.assignments
]
dependencies = [
CARD_FILENAME_FORMAT.format(
seq_id=favro_client.get_card_by_card_id(dep.card_id).seq_id.raw_id,
)
for dep in card.dependencies
if dep.is_before
]
return CardContents(
CARD_IDENTIFIER_FORMAT.format(seq_id=card.seq_id.raw_id),
card.name,
card.detailed_description,
tags,
assignments,
dependencies,
url=OFFICIAL_URL.format(
org_id=card.organization_id.raw_id,
seq_id=card.seq_id.raw_id,
),
todo_list_completed=card.todo_list_completed,
is_archived=card.is_archived,
start_date=card.start_date,
due_date=card.due_date,
)
class FavroFuse(fuse.Fuse): class FavroFuse(fuse.Fuse):
"""Favro FileSystem in Userspace.""" """Favro FileSystem in Userspace."""
@ -176,35 +207,7 @@ class FavroFuse(fuse.Fuse):
def _format_card_file(self, card: Card) -> str: def _format_card_file(self, card: Card) -> str:
if card.seq_id in self.wiped_cards: if card.seq_id in self.wiped_cards:
return '' return ''
card_contents = to_card_contents(card, self.favro_client)
tags = [self.favro_client.get_tag(tag_id).name for tag_id in card.tags]
assignments = [
self.favro_client.get_user(assignment.user).name
for assignment in card.assignments
]
dependencies = [
CARD_FILENAME_FORMAT.format(
seq_id=self.favro_client.get_card_by_card_id(dep.card_id).seq_id.raw_id,
)
for dep in card.dependencies
if dep.is_before
]
card_contents = CardContents(
CARD_IDENTIFIER_FORMAT.format(seq_id=card.seq_id.raw_id),
card.name,
card.detailed_description,
tags,
assignments,
dependencies,
url=OFFICIAL_URL.format(
org_id=card.organization_id.raw_id,
seq_id=card.seq_id.raw_id,
),
todo_list_completed=card.todo_list_completed,
archived=card.archived,
start_date=card.start_date,
due_date=card.due_date,
)
return self.formatter.format_card_contents(card_contents) return self.formatter.format_card_contents(card_contents)

View File

@ -32,7 +32,7 @@ class CardContents:
card_dependencies: list[str] card_dependencies: list[str]
url: str url: str
todo_list_completed: bool | None todo_list_completed: bool | None
archived: bool is_archived: bool
start_date: datetime.date | None start_date: datetime.date | None
due_date: datetime.date | None due_date: datetime.date | None
@ -95,8 +95,8 @@ class CardFileFormatter:
] ]
if card.todo_list_completed is not None: if card.todo_list_completed is not None:
frontmatter_data[FM_KEY_TODO_LIST_COMPLETED] = card.todo_list_completed frontmatter_data[FM_KEY_TODO_LIST_COMPLETED] = card.todo_list_completed
if card.archived is not None: if card.is_archived is not None:
frontmatter_data[FM_KEY_ARCHIVED] = card.archived frontmatter_data[FM_KEY_ARCHIVED] = card.is_archived
if card.due_date is not None: if card.due_date is not None:
frontmatter_data[FM_KEY_DUE_DATE] = card.due_date frontmatter_data[FM_KEY_DUE_DATE] = card.due_date
if card.start_date is not None: if card.start_date is not None:
@ -152,7 +152,7 @@ class CardFileFormatter:
url: list[str] = fm.metadata.get(FM_KEY_URL) url: list[str] = fm.metadata.get(FM_KEY_URL)
todo_list_completed: bool | None = fm.metadata.get(FM_KEY_TODO_LIST_COMPLETED) todo_list_completed: bool | None = fm.metadata.get(FM_KEY_TODO_LIST_COMPLETED)
archived: bool = fm.metadata.get(FM_KEY_ARCHIVED) is_archived: bool = fm.metadata.get(FM_KEY_ARCHIVED)
start_date: datetime.date = fm.metadata.get(FM_KEY_START_DATE) start_date: datetime.date = fm.metadata.get(FM_KEY_START_DATE)
due_date: datetime.date = fm.metadata.get(FM_KEY_DUE_DATE) due_date: datetime.date = fm.metadata.get(FM_KEY_DUE_DATE)
@ -167,7 +167,7 @@ class CardFileFormatter:
card_dependencies=card_dependencies, card_dependencies=card_dependencies,
url=url, url=url,
todo_list_completed=todo_list_completed, todo_list_completed=todo_list_completed,
archived=archived, is_archived=is_archived,
start_date=start_date, start_date=start_date,
due_date=due_date, due_date=due_date,
) )

View File

@ -29,6 +29,13 @@ def test_get_card():
assert len(card.custom_fields) == 2 assert len(card.custom_fields) == 2
@needs_secrets
def test_get_archived_card():
client = create_client()
card = client.get_card(SeqId(8723))
assert card.is_archived
@needs_secrets @needs_secrets
def test_get_cards(): def test_get_cards():
client = create_client() client = create_client()
@ -48,3 +55,4 @@ def create_client():
def assert_valid_card(card): def assert_valid_card(card):
assert card is not None assert card is not None
assert card.name is not None assert card.name is not None
assert card.is_archived is not None