Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User profile end-of-life #928

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion schema/data-auth.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@
["Tracklist for any show/timeslot","AUTH_TRACKLIST_ALL", true],
["Access WebStudio", "AUTH_ACCESS_WEBSTUDIO", true],
["View Messages for Any Show", "AUTH_ANY_SHOW_MESSAGES", true],
["Give Anyone Any Training Status", "AUTH_AWARDANYTRAINING", true]
["Give Anyone Any Training Status", "AUTH_AWARDANYTRAINING", true],
["View Archived Members", "AUTH_VIEWARCHIVEDMEMBERS", true]
]
15 changes: 15 additions & 0 deletions schema/patches/5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
BEGIN;

ALTER TABLE public.member
ADD COLUMN eol_state SMALLINT DEFAULT 0;

COMMENT ON COLUMN public.member.eol_state
IS 'The end-of-life status of this profile. 0 is none, 10 deactivated, 20 archived. 1, 2, 3 are pending deactivated, archived, deleted';

ALTER TABLE public.member
ADD COLUMN eol_requested_at TIMESTAMPTZ NULL DEFAULT NULL;

COMMENT ON COLUMN public.member.eol_requested_at
IS 'The time that this member''s profile EOL was requested.';

COMMIT;
7 changes: 4 additions & 3 deletions src/Classes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ final class Config
public static $d_Podcast_enabled = true;
public static $d_StatsGen_enabled = true;
public static $d_Explicit_enabled = false;
public static $d_MemberEOL_enabled = false;

/**** STRINGS ****/
public static $short_name = 'URY';
Expand All @@ -690,9 +691,9 @@ final class Config
public static $welcome_email = <<<EOT

This is a welcome (sign-up) email. You can use #NAME to get the user's first name.

Here you should probably tell people about what they should do next to get started.

You can set the ($)welcome_email_sender_memberid variable to send this email from/reply to
someone important, maybe the head of station, so they can ask questions!

Expand All @@ -702,7 +703,7 @@ final class Config
This is an email to give a newly signed-up member their new login details.
You can use #NAME to get the new member's first name.
You can use #USER and #PASS to tell them their newly created login details.

This email will send from a no-reply email so that user's don't spread their login details.

EOT;
Expand Down
42 changes: 42 additions & 0 deletions src/Classes/Daemons/MyRadio_MemberEOLDaemon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace MyRadio\Daemons;

use MyRadio\Config;
use MyRadio\MyRadio\CoreUtils;
use MyRadio\MyRadioException;
use MyRadio\ServiceAPI\MyRadio_User;

/**
* This Daemon carries out member end-of-life actions.
*/
class MyRadio_MemberEOLDaemon extends \MyRadio\MyRadio\MyRadio_Daemon
{
public static function isEnabled()
{
return Config::$d_MemberEOL_enabled;
}

public static function run()
{
$hourkey = __CLASS__.'_last_run';
if (self::getVal($hourkey) > time() - 60 * 60) {
return;
}

$members = MyRadio_User::getPendingEOLMembers();
foreach ($members as $member) {
switch ($member->getEolState()) {
case MyRadio_User::EOL_STATE_PENDING_DEACTIVATE:
$member->deactivate();
break;
case MyRadio_User::EOL_STATE_PENDING_ARCHIVE:
case MyRadio_User::EOL_STATE_PENDING_DELETE:
throw new MyRadioException('NYI');
}
}

//Done
self::setVal($hourkey, time());
}
}
2 changes: 1 addition & 1 deletion src/Classes/MyRadioEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public function setSentToList(MyRadio_List $list)
*
* @param MyRadio_User $to
* @param string $subject email subject
* @param sting $message email message
* @param string $message email message
*
* @todo Check if "Receive Emails" is enabled for the User
*/
Expand Down
9 changes: 8 additions & 1 deletion src/Classes/ServiceAPI/MyRadio_Creditable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
namespace MyRadio\ServiceAPI;

use MyRadio\MyRadioException;
use MyRadio\ServiceAPI\MyRadio_User;
use MyRadio\ServiceAPI\MyRadio_Scheduler;

Expand Down Expand Up @@ -210,7 +211,13 @@ private function addNewCredits($old, $new, $table, $pkey)
foreach ($new as $credit) {
//Look for an existing credit
if (!in_array($credit, $old)) {
//Doesn't seem to exist.
// Doesn't seem to exist.
// Double-check they're not EOL'd
$creditedUser = MyRadio_User::getInstance($credit['memberid']);
if ($creditedUser->getEolState() >= MyRadio_User::EOL_STATE_DEACTIVATED) {
$name = $creditedUser->getName();
throw new MyRadioException("Cannot credit $name as their profile is deactivated or archived.", 400);
}
self::$db->query(
'INSERT INTO '.$table.' ('.$pkey.', credit_type_id, creditid, effective_from,'
.'memberid, approvedid) VALUES ($1, $2, $3, NOW(), $4, $4)',
Expand Down
Loading