feat: auto-sync is_norda_member flag when linking/unlinking companies
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
- Set is_norda_member=True when admin assigns active company to user - Clear is_norda_member=False when last active company is removed - Covers admin edit route and admin API add/remove company routes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ce72155f82
commit
b0a8971980
@ -402,11 +402,22 @@ def admin_user_assign_company(user_id):
|
||||
db.add(uc)
|
||||
else:
|
||||
existing_uc.is_primary = True
|
||||
|
||||
# Auto-set Norda membership when linking to active company
|
||||
if company.status == 'active':
|
||||
user.is_norda_member = True
|
||||
else:
|
||||
user.company_id = None
|
||||
company_name = None
|
||||
# Remove primary flag from all user_companies
|
||||
db.query(UserCompany).filter_by(user_id=user.id, is_primary=True).update({'is_primary': False})
|
||||
# Clear Norda membership if user has no remaining active company links
|
||||
remaining = db.query(UserCompany).filter(
|
||||
UserCompany.user_id == user.id,
|
||||
UserCompany.company_id != None
|
||||
).join(Company).filter(Company.status == 'active').first()
|
||||
if not remaining:
|
||||
user.is_norda_member = False
|
||||
|
||||
db.commit()
|
||||
|
||||
|
||||
@ -751,6 +751,11 @@ def admin_user_company_add(user_id):
|
||||
is_primary=is_primary,
|
||||
)
|
||||
db.add(uc)
|
||||
|
||||
# Auto-set Norda membership when linking to active company
|
||||
if company.status == 'active':
|
||||
user.is_norda_member = True
|
||||
|
||||
db.commit()
|
||||
|
||||
logger.info(f"Admin {current_user.email} added company {company_id} ({company.name}) to user {user.email} with role {role}")
|
||||
@ -788,6 +793,17 @@ def admin_user_company_remove(user_id, company_id):
|
||||
company_name = company.name
|
||||
|
||||
db.delete(uc)
|
||||
|
||||
# Clear Norda membership if user has no remaining active company links
|
||||
user = db.query(User).get(user_id)
|
||||
if user:
|
||||
remaining = db.query(UserCompany).filter(
|
||||
UserCompany.user_id == user_id,
|
||||
UserCompany.company_id != company_id
|
||||
).join(Company).filter(Company.status == 'active').first()
|
||||
if not remaining:
|
||||
user.is_norda_member = False
|
||||
|
||||
db.commit()
|
||||
|
||||
logger.info(f"Admin {current_user.email} removed company {company_id} ({company_name}) from user {user_id}")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user