Voile.Clearance (Voile v0.1.26)

Copy Markdown View Source

Context for managing clearance letters (Surat Keterangan Bebas Perpustakaan).

Handles eligibility checks, letter generation, verification, and revocation.

Summary

Functions

Builds a member snapshot map from a user struct.

Checks whether a user is eligible to receive a clearance letter.

Deletes the old signature image from storage. Safe to call with nil.

Returns the eligible member type slugs from settings (comma-separated string).

Returns true when the clearance feature is enabled in system settings.

Formats a letter number by replacing {N} (zero-padded) and {YEAR} in the format template.

Generates a clearance letter for a user inside a DB transaction.

Generates a clearance letter for a user with a custom identifier.

Gets a clearance letter by UUID, preloading member and revoked_by.

Gets the latest non-revoked clearance letter for a member.

Gets a non-revoked clearance letter for a member by identifier.

Gets all non-revoked clearance letters for a member.

Returns all clearance settings as a map with string keys.

Returns a paginated list of clearance letters with preloaded member and member's node.

Revokes a clearance letter.

Saves clearance settings. Accepts a map with string keys matching the fields returned by get_settings/0.

Functions

build_member_snapshot(user, identifier \\ nil)

Builds a member snapshot map from a user struct.

The user may be loaded without :node preloaded. Optionally accepts a custom identifier (for next-degree letters). When VOILE_UNPAD_VISITOR_SOURCE is configured, fetches student data from the external API using the effective identifier.

check_eligibility(user)

Checks whether a user is eligible to receive a clearance letter.

Returns a map with :eligible (bool) and :checks (list of check results). Each check is a map with :key, :label, :passed, and :detail.

The user must be preloaded with :user_type for the member type check. The locker check is only included when VoileLockerLuggage.Lockers is loaded.

delete_old_signature_image(url)

Deletes the old signature image from storage. Safe to call with nil.

eligible_member_type_slugs()

Returns the eligible member type slugs from settings (comma-separated string).

feature_enabled?()

Returns true when the clearance feature is enabled in system settings.

format_letter_number(sequence, format, year)

Formats a letter number by replacing {N} (zero-padded) and {YEAR} in the format template.

generate_letter(user)

Generates a clearance letter for a user inside a DB transaction.

The user may be loaded without :node preloaded.

Returns {:ok, letter} or {:error, reason}.

generate_letter_for_member(user, identifier)

Generates a clearance letter for a user with a custom identifier.

This is intended for super-admin dashboard usage, where the member may have already requested clearance under a previous identifier.

get_letter(uuid)

Gets a clearance letter by UUID, preloading member and revoked_by.

get_member_latest_letter(member_id)

Gets the latest non-revoked clearance letter for a member.

get_member_letter_by_identifier(member_id, identifier)

Gets a non-revoked clearance letter for a member by identifier.

get_member_letters(member_id)

Gets all non-revoked clearance letters for a member.

get_settings()

Returns all clearance settings as a map with string keys.

list_letters_paginated(page, per_page, opts \\ [])

Returns a paginated list of clearance letters with preloaded member and member's node.

Options:

  • :node_id — integer; when provided, only letters whose member belongs to this node are returned.
  • :search — string; fuzzy search on letter_number, member fullname, or member identifier.

Returns {letters, total_count, total_pages}.

revoke_letter(letter, revoked_by_id, reason)

Revokes a clearance letter.

save_settings(attrs)

Saves clearance settings. Accepts a map with string keys matching the fields returned by get_settings/0.