feat: company selector in B2B classifieds form
Users with multiple companies now see a dropdown to choose which company a B2B classified ad is posted for. Single-company users get a hidden field. Server-side validates the selected company_id against user's actual memberships. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
61204edd0c
commit
762e9a7b4a
@ -100,9 +100,19 @@ def new():
|
||||
# Automatyczne wygaśnięcie po 30 dniach
|
||||
expires = datetime.now() + timedelta(days=30)
|
||||
|
||||
from helpers.company_context import get_active_company_id
|
||||
from database import UserCompany
|
||||
|
||||
form_company_id = request.form.get('company_id', type=int) or get_active_company_id()
|
||||
# Validate user has access to this company
|
||||
if form_company_id and not db.query(UserCompany).filter_by(
|
||||
user_id=current_user.id, company_id=form_company_id
|
||||
).first():
|
||||
form_company_id = current_user.company_id
|
||||
|
||||
classified = Classified(
|
||||
author_id=current_user.id,
|
||||
company_id=current_user.company_id,
|
||||
company_id=form_company_id,
|
||||
listing_type=listing_type,
|
||||
category=category,
|
||||
title=title,
|
||||
|
||||
@ -259,6 +259,24 @@
|
||||
<form method="POST" action="{{ url_for('classifieds.classifieds_new') }}" enctype="multipart/form-data">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
|
||||
{% if has_multiple_companies %}
|
||||
<div class="form-group">
|
||||
<label for="company_id">Ogłoszenie w imieniu firmy</label>
|
||||
<select id="company_id" name="company_id" class="form-control" style="border: 2px solid var(--primary); background: var(--bg-secondary);">
|
||||
{% for uc in user_companies %}
|
||||
{% if uc.company %}
|
||||
<option value="{{ uc.company_id }}" {% if uc.company_id == active_company_id %}selected{% endif %}>
|
||||
{{ uc.company.name }}{% if uc.company_id == active_company_id %} (aktywna){% endif %}
|
||||
</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
<small style="color: var(--text-secondary); margin-top: 4px; display: block;">Ogłoszenie będzie widoczne na profilu wybranej firmy</small>
|
||||
</div>
|
||||
{% else %}
|
||||
<input type="hidden" name="company_id" value="{{ active_company_id }}">
|
||||
{% endif %}
|
||||
|
||||
<div class="form-group">
|
||||
<label>Typ ogłoszenia *</label>
|
||||
<div class="type-selector">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user