Add "explain" field to users filter actions so admins can customize the message to user

This commit is contained in:
Bofh 2022-12-09 00:36:06 +01:00
parent 2a0ce78f3c
commit 481eb92b1a
4 changed files with 31 additions and 8 deletions

View File

@ -26,8 +26,12 @@ if ($id === null || $action === null)
apiresult(['error' => '<id> or <action> parameter is not valid']); apiresult(['error' => '<id> or <action> parameter is not valid']);
$interval = 0; $interval = 0;
if (isset($_GET['interval'])) if (isset($_POST['interval']))
$interval = intval(trim($_GET['interval'])); $interval = intval(trim($_POST['interval']));
$explain = null;
if (isset($_POST['explain']))
$explain = trim($_POST['explain']);
$afile_name = $type.','.$GLOBALS['ap_instance'].','; $afile_name = $type.','.$GLOBALS['ap_instance'].',';
$action_file = $actions_dir.'/'.$type.','.$GLOBALS['ap_instance'].','.$id; $action_file = $actions_dir.'/'.$type.','.$GLOBALS['ap_instance'].','.$id;
@ -35,6 +39,10 @@ $action_file = $actions_dir.'/'.$type.','.$GLOBALS['ap_instance'].','.$id;
if ($action === 'none' && file_exists($action_file)) if ($action === 'none' && file_exists($action_file))
unlink($action_file); unlink($action_file);
else if ($action !== 'none') else if ($action !== 'none')
file_put_contents($action_file, serialize( file_put_contents($action_file,
['name' => $action, 'interval' => $interval])); serialize([
'name' => $action,
'interval' => $interval,
'explain' => $explain,
]));
apiresult(['ok' => 'filter action has been succesfully saved']); apiresult(['ok' => 'filter action has been succesfully saved']);

View File

@ -5,7 +5,12 @@ $_ = function() {
if (!valid_mastodon_account_id($id)) if (!valid_mastodon_account_id($id))
return apiresult(['error' => 'id parameter has incorrect format'], 400); return apiresult(['error' => 'id parameter has incorrect format'], 400);
instance_http_post('/api/v1/admin/accounts/'.$id.'/action',['type' => 'suspend']); $explain = 'Your account has been suspended';
if (isset($_POST['explain']))
$explain = trim($_POST['explain']);
instance_http_post('/api/v1/admin/accounts/'.$id.'/action',
['type' => 'suspend', 'text' => $explain ]);
$output = instance_http_delete('/api/v1/admin/accounts/'.$id); $output = instance_http_delete('/api/v1/admin/accounts/'.$id);
return apiresult($output); return apiresult($output);
}; };

View File

@ -120,6 +120,12 @@
<option value="suspend">Suspend</option> <option value="suspend">Suspend</option>
</select> </select>
</div> </div>
<div class="input">
<label for="instance_action_explain">Generic explanation to users:</label>
<br class="sep"/>
<textarea type="text" name="instance_action_explain" style="min-height: 6em" class="w100"
placeholder="Generic explanation that will be sent to users when an action is taken..."></textarea>
</div>
<div class="input"> <div class="input">
<label for="instance_action_interval">Job interval (in seconds):</label> <label for="instance_action_interval">Job interval (in seconds):</label>
<input type="number" name="instance_action_interval" placeholder="60"/> <input type="number" name="instance_action_interval" placeholder="60"/>

View File

@ -134,11 +134,13 @@ window.view.instance = {
return tpl; return tpl;
}); });
if (js.action === null) if (js.action === null)
js.action = { name: 'none', interval: NaN }; js.action = { name: 'none', interval: NaN, explain: '' };
E.element('#filter-instance-action select[name=instance_action_name]') E.element('#filter-instance-action select[name=instance_action_name]')
.value = js.action.name; .value = js.action.name;
E.element('#filter-instance-action input[name=instance_action_interval]') E.element('#filter-instance-action input[name=instance_action_interval]')
.value = js.action.interval; .value = js.action.interval;
E.element('#filter-instance-action textarea[name=instance_action_explain]')
.value = js.action.explain;
}); });
break; break;
} }
@ -151,8 +153,10 @@ window.view.instance = {
const v = E.element('#filter-instance-action select[name=instance_action_name]').value.trim(); const v = E.element('#filter-instance-action select[name=instance_action_name]').value.trim();
var v2 = E.element('#filter-instance-action input[name=instance_action_interval]').value.trim(); var v2 = E.element('#filter-instance-action input[name=instance_action_interval]').value.trim();
v2 = Number.parseInt(v2) === NaN ? 0 : Number.parseInt(v2); v2 = Number.parseInt(v2) === NaN ? 0 : Number.parseInt(v2);
http.get(`api/v1/config/filters/actions/put?instance=${hargs.instance}&type=users&id=${_id}&action=${v}&interval=${v2}`, const v3 = E.element('#filter-instance-action textarea[name=instance_action_explain]').value.trim();
{},function(js){ if (js.ok) toast.info(js.ok) }); const payload = { interval: v2, explain: v3 };
http.post(`api/v1/config/filters/actions/put?instance=${hargs.instance}&type=users&id=${_id}&action=${v}`,
payload, function(js){ if (js.ok) toast.info(js.ok) });
}, },
delete_filter: function(_id) { delete_filter: function(_id) {
if (!confirm('Are you sure you want to delete this filter?')) if (!confirm('Are you sure you want to delete this filter?'))