Metadata-Version: 2.5
Name: aa-recruitment
Version: 1.3.0
Summary: Recruitment and Application Management Plugin for Alliance Auth
Author-email: Maddog Broekman <maddogbroekman@gmail.com>
License: MIT
License-File: LICENSE
Keywords: allianceauth,eveonline,hr,recruitment
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Requires-Python: <3.14,>=3.11
Requires-Dist: allianceauth>=3.6.0
Requires-Dist: pypdf>=4.0
Requires-Dist: requests>=2.28.0
Provides-Extra: dev
Requires-Dist: build>=1.0.0; extra == 'dev'
Requires-Dist: ruff>=0.3.0; extra == 'dev'
Provides-Extra: test
Requires-Dist: pytest-django>=4.5; extra == 'test'
Requires-Dist: pytest>=7.0; extra == 'test'
Description-Content-Type: text/markdown

# AA Recruitment

Recruitment and Application Management Plugin for **Alliance Auth**.

Manage corporation and alliance recruitment workflows directly within Alliance Auth: customizable application forms, dynamic questionnaires, applicant dossiers, multi-stage status reviews, and Discord alerts.

---

## Features

- **Custom Application Forms:** Create corporation or division-specific recruitment postings with custom requirements and guidelines.
- **Dynamic Questionnaires:** Configure question types (short text, multi-line text, dropdown choices, checkboxes, numbers) with custom ordering.
- **Applicant Dashboard:** Users can submit applications, monitor their status, view recruiter feedback, and respond to inquiries.
- **Recruiter Workflow:**
  - Dedicated review queue with status and form filters.
  - Candidate dossier displaying Auth profile, linked characters, and submitted answers.
  - Reviewer assignment and status transitions (`Pending Review` → `Under Review` → `Accepted` / `Rejected`).
  - Internal recruiter notes (hidden from applicants) alongside public applicant feedback.
- **Audit Log:** Complete history of status changes, reviewer assignments, and actions.
- **Discord & In-App Alerts:** Webhook embed notifications for new applications and status updates, plus Alliance Auth native notifications.

---

## Installation

### 1. Install the package
In your Alliance Auth virtual environment:

```bash
pip install -e /path/to/plugins/aa-recruitment
```

### 2. Configure Alliance Auth
Add `'aa_recruitment'` to `INSTALLED_APPS` in your `local.py`:

```python
INSTALLED_APPS += [
    "aa_recruitment",
]
```

### 3. Run Migrations & Collect Static
```bash
python manage.py migrate
python manage.py collectstatic --noinput
```

### 4. Restart Services
```bash
sudo supervisorctl restart all
```

---

## Language of Discord messages

Discord messages don't follow the language of the recruiter who triggers them. Webhook posts use the language set per application form, or else in **Recruitment Forms & Settings -> Discord Messages**; when neither is set, the installation default applies. Notifications and direct messages to applicants use the applicant's own Alliance Auth language. Set the default in `myauth/settings/local.py` (it falls back to `LANGUAGE_CODE`):

```python
DISCORD_MESSAGE_LANGUAGE = "en"  # or e.g. "nl-nl"
```

## Vetting checks

Every application is vetted automatically. Next to the INIT blacklist, EVEWho corp history and zKillboard profile, the
plugin checks the applicant's **Character Audit** data (corptools; memberaudit for the wallet only):

| Check | What it looks for |
|---|---|
| Wallet | Large inbound transfers vs. the balance; donations with characters that are not declared alts; income sources; a corp-wallet withdrawal within 14 days before leaving that corp (the corp-theft signature); PLEX/extractor patterns; a wallet that came back to life just before applying |
| Alt detection | Donations and trades, low/zero-price contracts, watched or high-standing contacts and overlapping corp history with characters outside the applicant's Auth account; linked characters checked against the INIT blacklist |
| Character status | Current corp/alliance and coalition, unaffiliated, not logged in recently, an old character with very few logins |
| Skills | Focus areas by SP, cyno/capital/covert context, tutorial rewards near character creation |
| Assets | Items in hostile sovereign space (live ESI sovereignty), ships the visible skills cannot fly |
| Contracts | RMT wording, contracts far above the balance, repeated contracts with the same outsider, failed contracts |
| Mail | Serious keywords (CCP warnings, bans) and softer ones in 1-to-1 mails; only subjects go into the report |
| Mining | Ledger entries and systems |
| Killboard per corp stay | Active days, sessions (fleets), breaks, a burst after joining, quiet before leaving; heatmap from 6 months of killmails |
| Application | Risk language in the answers, the "all characters added?" answer, claimed playstyle vs. skills, ledger, bounties and kills |
| EVE forums, transcripts | Forum search for all characters; search of recruitment transcripts (upload PDFs in Django admin → Recruitment Transcripts) |

Transfers with your own corporation and alliance (SRP, buyback, payouts) never raise a finding. Set them with:

```python
AA_RECRUITMENT_TRUSTED_CORPORATION_IDS = [98000001]  # the Activity Settings corporation is added automatically
AA_RECRUITMENT_TRUSTED_ALLIANCE_IDS = [1900696668]  # its alliance is added automatically
AA_RECRUITMENT_TRUSTED_CHARACTER_NAMES = ["Buyback Service"]
AA_RECRUITMENT_HOSTILE_TERMS = [...]  # optional: replaces the built-in hostile list
AA_RECRUITMENT_FRIENDLY_TERMS = [...]
```

Hostile terms match whole words only ("pl" no longer matches "Exploration"). All results are listed per check in the
dossier's **Audit Details** tab.

### Vetting settings and data sources

**Recruitment → Vetting Settings** lists every check: what it looks at, where the data comes from, its parameters
(thresholds and word lists) and every finding it can raise with its severity. Recruiters with `manage_recruitment`
can read it; `admin_recruitment` can switch a check off, change a parameter, give a finding another severity or hide
it, and reset a check to its defaults. Only values that differ from the code are stored (model `CheckConfig`).
Changes apply to the next vetting run (**Re-Run Audit** on a dossier). The hostile and friendly term lists set here
win over `AA_RECRUITMENT_HOSTILE_TERMS` / `AA_RECRUITMENT_FRIENDLY_TERMS`.

**Data sources** (button on the settings page and in every dossier) reads each Character Audit data type for one
applicant, the same way the vetting does, and shows the rows, the time and the exact error when a read fails, plus
which Auth characters are in Character Audit and how many rows each holds. Every report also gets a **Data sources**
section; characters that are not in Character Audit at all are a medium finding. `AA_RECRUITMENT_AUDIT_BACKEND`
(`corptools` or `memberaudit`) forces the audit app when both are installed.

**Character Audit site** (top of Vetting Settings) sets where the Character Audit data comes from and where the
dossier's **Character Audit** button points. Empty, or this Auth's own address: the local database is read. Another
Auth (for example Prod while testing on Dev): its corptools API is read (`/audit/api/account/<id>/...`) with the
session cookie of a user there who can see the applicant (`corptools.view_characteraudit` plus `guest_hr` for
applicants, or `global_hr`). **Test connection** checks it. Through the API, mail bodies are not available and mining
is grouped per day and ore. `AA_RECRUITMENT_AUDIT_SITE_URL` and `AA_RECRUITMENT_AUDIT_SESSION` in local.py override the
fields and keep the cookie out of the database. When moving to Prod, clear the field (or set it to Prod's own address)
and remove the cookie.

In the dossier, findings are listed most severe first, can be filtered by severity, and open to show the evidence,
the question to ask and the recruiter action; **Show the details** jumps to the data behind a finding.

## Member activity (Activity Center)

**Recruitment → Member Activity** is the 3Gods userscript's Activity Center, inside Auth, for everyone with
`view_member_activity`. The page runs the userscript's own dashboard code (`static/aa_recruitment/js/activity_center.js`)
on data from the plugin (`activity/data.json`), so it looks and works the same:

- Fleet participation (FATs): tiles, INIT compliance (VIP limit, 6-month rule, dropping below soon), FATs per month,
  FAT minimum per month, members by status, Top 10 per period (FATs, kills, ISK destroyed).
- Killboard: tiles, kills / losses / ISK destroyed / ISK lost per month, participation per month, status per update,
  weekday x hour heatmap of the last 90 days.
- Members: Leave of Absence list, last 30 / 90 days or a calendar month, status chips and special filters, search,
  tiles for the view, sortable table with tags and month bars, CSV export of the view.
- Member drawer: tiles, FAT history with chart, LoA, other activity, per calendar month, kills/losses and ISK charts,
  history over updates, characters, recent killmails and **Contact member** (the friendly check-in message).
- Export menu: members (latest / every update), 3Gods (every update / per month), characters per month, killmails.

The data is collected by the Celery task `aa_recruitment.tasks.update_member_activity` (run it daily); recruitment
admins can start it with **Run update** and change the status rules and VIPs with **Settings**. Without a FAT source
or LoA provider configured on the server, the page reads Auth's FAT analysis (`/fatanalysis/`) and LoA HR dashboard
(`/loa/hr/`) in the browser, exactly like the userscript. **Open ticket form** copies the message to the clipboard;
with the userscript installed the kanban form is filled in as before.

`AA_RECRUITMENT_TICKET_URL` (default `/kanban/tickets/create/`) and `AA_RECRUITMENT_LOA_URL` set the links used by the
member page.

## Member activity & INIT compliance

**Recruitment → INIT Compliance** shows, for the members of one corporation (mains whose main character is in it):

- **VIP limit (INIT rule 1):** VIPs against the allowance (3 up to 50 mains, otherwise 5% of mains rounded up).
- **Long-term inactive (INIT rule 3):** fewer than 15 FATs over the last 6 full months. VIPs are left out; a leave of absence does not exempt anyone. Members who joined during those 6 months are not judged yet.
- **Dropping below soon:** still compliant, but below the 6-month minimum by the end of this month or next month if they join no more fleets.
- **Below INIT 90 days:** fewer than 15 FATs over the last 3 full months (new members and members on leave left out).
- Per member a small bar chart of FATs per month (6 full months plus the running month, shown lighter) and an outlook: *below now*, *below from end <month>*, *safe 6+ months* or *not 6 months yet*.

Only full months are judged. INIT rule 2 (Discord, Mumble and ghost compliance) is not checked.

### Setup

1. In Django admin → **Activity Settings**, set the **corporation ID** to track. The FAT minimums (5 per month, 15 per 90 days, 15 per 6 months) and the "new member" window (35 days) can be changed there.
2. Add VIPs in Django admin → **VIP Members**.
3. Give the people who should see the page the permission `aa_recruitment.view_member_activity`.
4. Schedule the daily update on **Settings → General → Schedule** (recommended; no restart needed), or in `local.py`:

```python
CELERYBEAT_SCHEDULE["aa_recruitment_update_member_activity"] = {
    "task": "aa_recruitment.tasks.update_member_activity",
    "schedule": crontab(minute=17, hour=3),
}
```

Recruitment administrators can also start an update from the page.

### Where the data comes from

| Data | Source |
|---|---|
| FATs | aFAT or Alliance Auth's fleet activity tracking, found automatically. Any other FAT app: set `AA_RECRUITMENT_FAT_PROVIDER` (below). |
| Kills and losses per month | zKillboard stats endpoint, all characters of the member. Turn off with `AA_RECRUITMENT_ACTIVITY_KILLBOARD = False`; pause between calls `AA_RECRUITMENT_ZKILL_PAUSE` (default 1 second). |
| Join date | ESI corporation history of the main character. |
| Leave of absence | Optional: `AA_RECRUITMENT_LOA_PROVIDER` (below). |

Custom FAT or LoA source, for apps the plugin does not know:

```python
# myapp/recruitment.py
def fats(users, since):
    """users: QuerySet of User; since: date. Return {user_id: {date(2026, 10, 1): 17, ...}}"""


def leaves(users, today):
    """Return {user_id: {"start": date, "end": date or None, "reason": str}} for active leaves."""


# local.py
AA_RECRUITMENT_FAT_PROVIDER = "myapp.recruitment.fats"
AA_RECRUITMENT_LOA_PROVIDER = "myapp.recruitment.leaves"
```

### Settings without local.py

**Settings → General** holds the schedule of the background jobs, the links (ticket form, LoA page, INIT blacklist),
trusted corporations/alliances/characters, the INIT VIP rule and the zKillboard limits. A value saved there wins over
the matching `AA_RECRUITMENT_*` setting in local.py and is used right away. Only new code, migrations, the FAT/LoA
provider and (optionally) `AA_RECRUITMENT_AUDIT_SESSION` still need the server.

### Character audit apps

Alt detection reads wallet transfers from **corptools** (Character Audit) or **memberaudit**, whichever is installed (`aa_recruitment/sources/audit.py`). Contract and contact checks still need memberaudit.

---

## Permissions

| Permission | Codename | Description |
| :--- | :--- | :--- |
| **Basic Access** | `aa_recruitment.basic_access` | View recruitment forms, submit applications, and track own status. |
| **Recruitment Officer** | `aa_recruitment.manage_recruitment` | Access review queue, manage applications, add comments, assign reviewers, update status. |
| **Recruitment Administrator** | `aa_recruitment.admin_recruitment` | Create and edit application forms, questions, and global plugin configuration. |
| **Activity Viewer** | `aa_recruitment.view_member_activity` | View member activity and the INIT compliance page. |

---

## Celery Tasks

Add periodic tasks to `CELERYBEAT_SCHEDULE` if using scheduled maintenance (optional):

```python
# Optional periodic cleanup or reminder tasks
```

---

## License
MIT License.
