Skip to content

OnlineMessagesApiService

Implements IOnlineMessagesApiService, selecting and localizing the online banner messages and tutorial messages a given user type/priority/application/language combination is permitted to see. It depends on IUnitOfWork for reading online messages, priority, user-type, and application reference data, and IUserProfileService for resolving the current user's active-directory status, employee status, and security-group authorization; on construction it eagerly loads all currently active (start-to-termination window) messages into memory.

Purpose

  • Determines whether the current user is active in the directory, is a SAIF employee, or otherwise has access to a message based on its target user type and priority.
  • Validates and normalizes user-type, priority, and application filter inputs against reference code tables.
  • Filters the pre-loaded active message set by user-type permission, priority, and application, then maps it to a localized (English/Spanish) OnlineMessageList.
  • Returns the tutorial-priority subset of messages for a user/language/application combination.

Context

  • Namespace: SAIF.Services.OnlineMessages
  • Assembly/package: SAIF.Services (packaged inside the SAIF.SAIFCode.Core NuGet package)

Public members

Member Signature Purpose
OnlineMessagesApiService(...) public OnlineMessagesApiService(IUnitOfWork uow, IUserProfileService profile) Validates both collaborators are non-null via Enforce.ArgumentNotNull, wires them in, and eagerly loads all messages whose active window (StartDate to TerminationDate) currently includes now.
UserIsInActiveDirectory public bool UserIsInActiveDirectory() Returns whether the current user's profile reports them as active in the directory.
UserIsEmployee public bool UserIsEmployee() Returns whether the current user resolves to a known SAIF employee record with a non-blank user ID.
UserHasAccessToMessage public bool UserHasAccessToMessage(string userType, string priority) Normalizes userType/priority, then returns true for urgent "all"-type messages shown to non-directory users, for employees, for "all"-type messages, and for users whose security group matches the message's required group; returns false for non-employees restricted to SAIF-employee-only messages or messages with no configured security group.
GetMessagePriorities public string[] GetMessagePriorities(string priority) Resolves a priority name (treating "tutorial" as "low") to its matching priority code(s); returns all of Urgent/High/Medium for an unrecognized or "all" priority, or the single matched code otherwise.
ValidateUserType public bool ValidateUserType(string userType) Returns whether the given user-type description exists in the OnlineUserType reference table.
ValidateApplicationCode public bool ValidateApplicationCode(string application) Returns true immediately for the literal "none"; otherwise returns whether the trimmed, uppercased application string matches a known ApplicationCode.
GetApplicationNames public string[] GetApplicationNames(string application) Returns an empty array when application is blank or "none"; otherwise returns a two-element array of the lower-cased application name plus the literal "all".
GetMessagesForUser public OnlineMessageList GetMessagesForUser(string userType, string priority, string language, string application) Normalizes inputs, filters the pre-loaded active messages to those the resolved user type is permitted to see at a matching priority (and, if specified, application), orders them by start date descending, and returns them as a localized OnlineMessageList.
GetTutorialList public OnlineMessageList GetTutorialList(string userType, string language, string application) Same filtering and localization pipeline as GetMessagesForUser, but forces the priority to the tutorial/low priority code.

Behavioral notes

  • The active message set is loaded once in the constructor and reused for every subsequent call on the instance, so messages that change activation window after construction are not reflected until a new service instance is created*.
  • UserHasAccessToMessage/GetMessagesForUser/GetTutorialList all mutate the instance fields userCode, priorityLookup, and applicationName as a side effect of calling the private ValidateInputParms helper, making the service not safely reusable across concurrent calls on the same instance*.
  • Message localization to Spanish falls back to the English text/title whenever the Spanish field is blank, ensuring a message is never rendered empty due to missing translation.

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified.

Sources

  • Services/SAIF.Services/OnlineMessages/OnlineMessagesApiService.cs