feat: platform filter checkboxes for enrichment scan
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Users can now select which platforms to scan (Facebook, Instagram, LinkedIn, YouTube, Twitter/X, TikTok) via checkboxes in the confirmation dialog. Backend filters both company list and profiles. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2c9a45230d
commit
af225691b6
@ -837,9 +837,10 @@ def _format_value(key, val):
|
||||
return str(val)
|
||||
|
||||
|
||||
def _run_enrichment_background(company_ids):
|
||||
def _run_enrichment_background(company_ids, platforms_filter=None):
|
||||
"""Collect enrichment data into staging area (NO database writes).
|
||||
All state is persisted to shared file for multi-worker gunicorn compatibility.
|
||||
platforms_filter: optional list of platform names to scan (e.g. ['facebook', 'linkedin']).
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@ -873,10 +874,13 @@ def _run_enrichment_background(company_ids):
|
||||
completed += 1
|
||||
continue
|
||||
|
||||
profiles = db.query(CompanySocialMedia).filter(
|
||||
profiles_query = db.query(CompanySocialMedia).filter(
|
||||
CompanySocialMedia.company_id == company_id,
|
||||
CompanySocialMedia.is_valid == True
|
||||
).all()
|
||||
)
|
||||
if platforms_filter:
|
||||
profiles_query = profiles_query.filter(CompanySocialMedia.platform.in_(platforms_filter))
|
||||
profiles = profiles_query.all()
|
||||
|
||||
company_result = {
|
||||
'company_id': company_id,
|
||||
@ -886,11 +890,13 @@ def _run_enrichment_background(company_ids):
|
||||
}
|
||||
|
||||
# Check if company has Facebook OAuth config — sync via Graph API
|
||||
fb_config = db.query(SocialMediaConfig).filter(
|
||||
SocialMediaConfig.company_id == company_id,
|
||||
SocialMediaConfig.platform == 'facebook',
|
||||
SocialMediaConfig.page_id.isnot(None)
|
||||
).first()
|
||||
fb_config = None
|
||||
if not platforms_filter or 'facebook' in platforms_filter:
|
||||
fb_config = db.query(SocialMediaConfig).filter(
|
||||
SocialMediaConfig.company_id == company_id,
|
||||
SocialMediaConfig.platform == 'facebook',
|
||||
SocialMediaConfig.page_id.isnot(None)
|
||||
).first()
|
||||
fb_synced = False
|
||||
if fb_config:
|
||||
try:
|
||||
@ -1064,14 +1070,18 @@ def admin_social_audit_run_enrichment():
|
||||
}), 409
|
||||
|
||||
company_ids_param = request.form.get('company_ids', '')
|
||||
platforms_param = request.form.get('platforms', '')
|
||||
platforms_filter = [p.strip().lower() for p in platforms_param.split(',') if p.strip()] if platforms_param else None
|
||||
|
||||
if company_ids_param:
|
||||
company_ids = [int(x) for x in company_ids_param.split(',') if x.strip().isdigit()]
|
||||
else:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
company_ids = [row[0] for row in db.query(
|
||||
distinct(CompanySocialMedia.company_id)
|
||||
).filter(CompanySocialMedia.is_valid == True).all()]
|
||||
query = db.query(distinct(CompanySocialMedia.company_id)).filter(CompanySocialMedia.is_valid == True)
|
||||
if platforms_filter:
|
||||
query = query.filter(CompanySocialMedia.platform.in_(platforms_filter))
|
||||
company_ids = [row[0] for row in query.all()]
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
@ -1089,11 +1099,12 @@ def admin_social_audit_run_enrichment():
|
||||
'pending_changes': [],
|
||||
'approved': False,
|
||||
'last_run': None,
|
||||
'platforms_filter': platforms_filter,
|
||||
})
|
||||
|
||||
thread = threading.Thread(
|
||||
target=_run_enrichment_background,
|
||||
args=(company_ids,),
|
||||
args=(company_ids, platforms_filter),
|
||||
daemon=True
|
||||
)
|
||||
thread.start()
|
||||
|
||||
@ -564,6 +564,31 @@
|
||||
<p style="margin:4px 0 0; font-size:var(--font-size-sm); color:var(--text-secondary);">Audyt social media dla wszystkich firm</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Platform filter checkboxes -->
|
||||
<div style="margin-bottom:var(--spacing-lg);">
|
||||
<div style="font-size:var(--font-size-sm); font-weight:600; margin-bottom:8px;">Platformy do skanowania:</div>
|
||||
<div style="display:flex; gap:var(--spacing-sm); flex-wrap:wrap;">
|
||||
<label style="display:flex; align-items:center; gap:4px; font-size:var(--font-size-sm); cursor:pointer; padding:4px 10px; border-radius:var(--radius); border:1px solid var(--border-color, #e5e7eb); background:var(--background);">
|
||||
<input type="checkbox" class="enrich-platform" value="facebook" checked> Facebook
|
||||
</label>
|
||||
<label style="display:flex; align-items:center; gap:4px; font-size:var(--font-size-sm); cursor:pointer; padding:4px 10px; border-radius:var(--radius); border:1px solid var(--border-color, #e5e7eb); background:var(--background);">
|
||||
<input type="checkbox" class="enrich-platform" value="instagram" checked> Instagram
|
||||
</label>
|
||||
<label style="display:flex; align-items:center; gap:4px; font-size:var(--font-size-sm); cursor:pointer; padding:4px 10px; border-radius:var(--radius); border:1px solid var(--border-color, #e5e7eb); background:var(--background);">
|
||||
<input type="checkbox" class="enrich-platform" value="linkedin" checked> LinkedIn
|
||||
</label>
|
||||
<label style="display:flex; align-items:center; gap:4px; font-size:var(--font-size-sm); cursor:pointer; padding:4px 10px; border-radius:var(--radius); border:1px solid var(--border-color, #e5e7eb); background:var(--background);">
|
||||
<input type="checkbox" class="enrich-platform" value="youtube" checked> YouTube
|
||||
</label>
|
||||
<label style="display:flex; align-items:center; gap:4px; font-size:var(--font-size-sm); cursor:pointer; padding:4px 10px; border-radius:var(--radius); border:1px solid var(--border-color, #e5e7eb); background:var(--background);">
|
||||
<input type="checkbox" class="enrich-platform" value="twitter" checked> Twitter/X
|
||||
</label>
|
||||
<label style="display:flex; align-items:center; gap:4px; font-size:var(--font-size-sm); cursor:pointer; padding:4px 10px; border-radius:var(--radius); border:1px solid var(--border-color, #e5e7eb); background:var(--background);">
|
||||
<input type="checkbox" class="enrich-platform" value="tiktok" checked> TikTok
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="font-size:var(--font-size-sm); color:var(--text-secondary); margin-bottom:var(--spacing-lg);">
|
||||
<div style="display:flex; align-items:flex-start; gap:8px; margin-bottom:8px;">
|
||||
<svg width="16" height="16" fill="none" stroke="#22c55e" viewBox="0 0 24 24" style="flex-shrink:0; margin-top:2px;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/></svg>
|
||||
@ -1055,9 +1080,17 @@ function doStartEnrichment() {
|
||||
_enrichSince = 0;
|
||||
_enrichPendingCount = 0;
|
||||
|
||||
var platforms = Array.from(document.querySelectorAll('.enrich-platform:checked')).map(function(cb) { return cb.value; });
|
||||
if (platforms.length === 0) {
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Uruchom audyt';
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('{{ url_for("admin.admin_social_audit_run_enrichment") }}', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded', 'X-CSRFToken': '{{ csrf_token() }}'},
|
||||
body: 'platforms=' + platforms.join(','),
|
||||
})
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(data) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user