Skip to content

Commit 0bfb1d2

Browse files
committed
fix: lint fixes + allow to forget messages that are in a removing state
1 parent 2187524 commit 0bfb1d2

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/aleph/handlers/content/forget.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,15 @@ async def check_permissions(self, session: DbSession, message: MessageDb):
113113
if target_status.status in (
114114
MessageStatus.FORGOTTEN,
115115
MessageStatus.REJECTED,
116+
MessageStatus.REMOVED,
116117
):
117118
continue
118119

119-
if target_status.status != MessageStatus.PROCESSED:
120+
# Note: Only allow to forget messages that are processed or marked for removing
121+
if (
122+
target_status.status != MessageStatus.PROCESSED
123+
or target_status.status != MessageStatus.REMOVING
124+
):
120125
raise ForgetTargetNotFound(target_hash=target_hash)
121126

122127
target_message = get_message_by_item_hash(
@@ -190,7 +195,11 @@ async def _forget_item_hash(
190195
)
191196
return
192197

193-
if message_status.status != MessageStatus.PROCESSED:
198+
# Note: Only allow to forget messages that are processed or marked for removing
199+
if (
200+
message_status.status != MessageStatus.PROCESSED
201+
and message_status.status != MessageStatus.REMOVING
202+
):
194203
logger.error(
195204
"FORGET message %s targets message %s which is not processed yet. This should not happen.",
196205
forgotten_by.item_hash,

src/aleph/web/controllers/prices.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ class HTTPProcessing(HTTPException):
4646
web.HTTPGone,
4747
"This message has been forgotten",
4848
),
49+
MessageStatus.REMOVING: (
50+
web.HTTPGone,
51+
"This message is marked for removing",
52+
),
53+
MessageStatus.REMOVED: (
54+
web.HTTPGone,
55+
"This message has been removed",
56+
),
4957
}
5058

5159

tests/jobs/test_balance_job.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
from aleph.db.models.balances import AlephBalanceDb
1111
from aleph.db.models.chains import ChainTxDb
1212
from aleph.db.models.cron_jobs import CronJobDb
13-
from aleph.db.models.files import FilePinDb, FilePinType, GracePeriodFilePinDb, MessageFilePinDb, StoredFileDb
13+
from aleph.db.models.files import (
14+
FilePinType,
15+
GracePeriodFilePinDb,
16+
MessageFilePinDb,
17+
StoredFileDb,
18+
)
1419
from aleph.db.models.messages import MessageDb, MessageStatusDb
1520
from aleph.jobs.cron.balance_job import BalanceCronJob
1621
from aleph.toolkit.constants import STORE_AND_PROGRAM_COST_CUTOFF_HEIGHT, MiB
@@ -274,9 +279,7 @@ async def fixture_message_for_recovery(session_factory, now, fixture_base_data):
274279
session.add_all([message])
275280
session.commit()
276281

277-
session.add_all(
278-
[wallet, file, file_pin, message_status, message_cost]
279-
)
282+
session.add_all([wallet, file, file_pin, message_status, message_cost])
280283
session.commit()
281284

282285
return {

0 commit comments

Comments
 (0)