Class: Organizations::Domain

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/organizations/models/domain.rb

Overview

An email domain owned/claimed by an organization, used for verified joining.

A user who proves control of an inbox under one of the organization's domains (emailed code, or an already-confirmed account email — see Organization#join_with_account_email!) is considered a verified member.

Matching is EXACT and dot-boundary safe: "alumnos.urjc.es" and "urjc.es" are two different domains and must both be enrolled if both should join. This is deliberate — subdomains often carry different member semantics (e.g. students vs employees), and suffix matching would collapse them. It also neutralizes lookalike attacks ("urjc.es.evil.com" never equals "urjc.es").

membership_metadata is copied onto memberships created through this domain (see JoinRequest#approve!) — hosts use it for cohort tags like { "member_kind" => "student" } without the gem interpreting the contents.

Examples:

org.add_domain!("inizio.com")
org.add_domain!("alumnos.urjc.es", membership_metadata: { member_kind: "student" })
Organizations::Domain.matching_email("j.doe@inizio.com") # => [domain]

Instance Method Summary collapse

Instance Method Details

#matches_email?(email) ⇒ Boolean

Whether an email address belongs to this domain (exact match).

Parameters:

  • email (String)

Returns:

  • (Boolean)


59
60
61
62
# File 'lib/organizations/models/domain.rb', line 59

def matches_email?(email)
  extracted = EmailNormalizer.domain_of(email)
  extracted.present? && extracted == domain
end