panel-redesign: inbound is delegated per user, separately from outbound
Stage 1, step 2 (plan § Who sees what).
Store
- Reach{AllDomains, DomainIDs, AllInbound, InboundDomainIDs} is what a
domain user is assigned. CreateUser takes it; SetUserReach / ClearUserReach
replace SetUserDomains / ClearUserDomains and write both directions in one
transaction. A domain user with nothing on either list is refused
(ErrEmptyReach). With All set the rows of that direction are not stored,
so clearing All later brings nothing stale back.
- ListDomainsForUser honours all_domains; ListInboundDomainsForUser is its
inbound twin. Both filter in the query.
Authorization
- auth.Principal carries the whole reach: CanAccessDomain (now also true
with All), CanAccessInboundDomain, HasOutbound, HasInbound. An id or a
name on one list opens nothing on the other.
- Inbound handlers in three strengths: requireInbound (the list, filtered),
requireInboundDomain (one domain: page, DNS re-check, upstream,
recipients), requireInboundGlobal (add, delete confirm, delete). All
answer the same 404.
- domainIDSet and the DMARC report pages go through the principal instead
of looking at p.Domains themselves.
Panel (old templates, until stage 2)
- User form: two lists with All; inbound is offered only where the feature
is on, and saving the form with it off keeps the user's inbound reach.
Promotion to global drops the reach.
- Menu: a group with nothing assigned is absent; / sends an inbound-only
administrator to Inbound. The inbound pages hide add / delete from a
domain administrator.
Tests: every route of one inbound domain against five kinds of refused
request (another tenant's id, a missing id, outbound-only reach, an outbound
domain with the same id, one with the same name, no principal) with the 404
bodies compared; add/delete as every non-global user; the filtered list
including a domain added later; thirteen outbound routes against another
tenant's domain and application id; the user form; the reach in the store;
the principal matrix; the menu; the home redirect. Removing the access check
or the query filter makes the tests fail (checked by hand).
go test ./... green except the two Windows-only failures in internal/domain
and internal/logtail that predate this work.
Roadmap 12/27.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -113,6 +113,35 @@ func (s *Store) ListInboundDomains() ([]InboundDomain, error) {
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// ListInboundDomainsForUser returns the inbound domains a domain user reaches,
|
||||
// ordered by name: the assigned ones, or every inbound domain when the user's
|
||||
// All flag is set. Like ListDomainsForUser, the filter is in the query.
|
||||
func (s *Store) ListInboundDomainsForUser(userID int64) ([]InboundDomain, error) {
|
||||
rows, err := s.db.Query(`
|
||||
SELECT d.id, d.name, d.recipient_mode, d.created_at,
|
||||
t.host, t.port, t.tls_mode,
|
||||
(SELECT COUNT(*) FROM inbound_recipients r WHERE r.inbound_domain_id = d.id)
|
||||
FROM inbound_domains d
|
||||
INNER JOIN inbound_transports t ON t.inbound_domain_id = d.id
|
||||
WHERE EXISTS (SELECT 1 FROM users u WHERE u.id = ? AND u.all_inbound_domains = 1)
|
||||
OR EXISTS (SELECT 1 FROM user_inbound_domains ud WHERE ud.user_id = ? AND ud.inbound_domain_id = d.id)
|
||||
ORDER BY d.name`, userID, userID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list inbound domains for user: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var out []InboundDomain
|
||||
for rows.Next() {
|
||||
d, err := scanInboundDomain(rows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, d)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// GetInboundDomain returns one inbound domain with its recipient list, or
|
||||
// ErrInboundDomainNotFound.
|
||||
func (s *Store) GetInboundDomain(id int64) (InboundDomain, error) {
|
||||
|
||||
Reference in New Issue
Block a user