Fixed mastodon checkbox on new entry page

This commit is contained in:
2026-08-27 22:08:30 +02:00
parent 1c2d1b71ff
commit d433a305f5
10 changed files with 65 additions and 6 deletions
+6 -1
View File
@@ -24,6 +24,7 @@ class LinkCreate(BaseModel):
comment: str = ''
timestamp: str | None = None
tags: list[str] = []
post_to_mastodon: bool = True
class LinkUpdate(BaseModel):
@@ -89,7 +90,11 @@ def create_link_endpoint(payload: LinkCreate, response: Response, authorization:
raise HTTPException(status_code=422, detail=str(error)) from error
if duplicate:
response.status_code = status.HTTP_200_OK
plugin_results = plugin_manager.dispatch({'type': 'link_created', **record})
plugin_results = plugin_manager.dispatch({
'type': 'link_created',
'post_to_mastodon': payload.post_to_mastodon,
**record,
})
mastodon_result = next((result for result in plugin_results if result.get('plugin') == 'mastodon'), None)
if mastodon_result and mastodon_result.get('status') == 'posted':
mark_mastodon_posted(record['id'], info['user_id'], mastodon_result.get('post_id'))
+2
View File
@@ -390,6 +390,8 @@ def get_user_plugin_config(plugin_name: str, user: dict = Depends(get_current_us
return {}
config = json.loads(row['config']) if row['config'] else {}
if plugin_name == 'mastodon':
config['configured'] = bool(config.get('instance') and config.get('access_token'))
if config.get('access_token'):
config.pop('access_token')
return config
+3
View File
@@ -34,6 +34,9 @@ class MastodonPlugin(BasePlugin):
return True
def handle_event(self, event):
if not event.get('post_to_mastodon', True):
return {'status': 'skipped', 'plugin': self.name, 'reason': 'not_requested'}
config = dict(self.config)
user_id = event.get('user_id')
if user_id:
+13
View File
@@ -889,6 +889,18 @@ def test_link_submission_posts_to_enabled_mastodon_plugin():
server.server_close()
def test_link_submission_can_skip_mastodon_posting():
with patch('backend.app.api.links.plugin_manager.dispatch', return_value=[]) as dispatch:
response = client.post('/api/links', headers=login_headers(), json={
'title': 'Private share',
'url': 'https://example.com/private-share',
'post_to_mastodon': False,
})
assert response.status_code == 201
assert dispatch.call_args.args[0]['post_to_mastodon'] is False
def test_mastodon_post_without_title_omits_source_line():
from backend.app.services.plugin_manager import MastodonPlugin
@@ -922,6 +934,7 @@ def test_plugin_config_can_be_saved_for_mastodon():
payload = client.get('/api/user/plugins/mastodon', headers=headers).json()
assert payload['instance'] == 'mastodon.social'
assert payload['post_prefix'] == 'From my #LinkLog: '
assert payload['configured'] is True
admin_update = client.put('/api/admin/plugins/mastodon', headers=headers, json={
'enabled': True,