Add "explain" field to users filter actions so admins can customize the message to user
This commit is contained in:
parent
2a0ce78f3c
commit
481eb92b1a
|
@ -26,8 +26,12 @@ if ($id === null || $action === null)
|
|||
apiresult(['error' => '<id> or <action> parameter is not valid']);
|
||||
|
||||
$interval = 0;
|
||||
if (isset($_GET['interval']))
|
||||
$interval = intval(trim($_GET['interval']));
|
||||
if (isset($_POST['interval']))
|
||||
$interval = intval(trim($_POST['interval']));
|
||||
|
||||
$explain = null;
|
||||
if (isset($_POST['explain']))
|
||||
$explain = trim($_POST['explain']);
|
||||
|
||||
$afile_name = $type.','.$GLOBALS['ap_instance'].',';
|
||||
$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))
|
||||
unlink($action_file);
|
||||
else if ($action !== 'none')
|
||||
file_put_contents($action_file, serialize(
|
||||
['name' => $action, 'interval' => $interval]));
|
||||
file_put_contents($action_file,
|
||||
serialize([
|
||||
'name' => $action,
|
||||
'interval' => $interval,
|
||||
'explain' => $explain,
|
||||
]));
|
||||
apiresult(['ok' => 'filter action has been succesfully saved']);
|
||||
|
|
|
@ -5,7 +5,12 @@ $_ = function() {
|
|||
if (!valid_mastodon_account_id($id))
|
||||
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);
|
||||
return apiresult($output);
|
||||
};
|
||||
|
|
|
@ -120,6 +120,12 @@
|
|||
<option value="suspend">Suspend</option>
|
||||
</select>
|
||||
</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">
|
||||
<label for="instance_action_interval">Job interval (in seconds):</label>
|
||||
<input type="number" name="instance_action_interval" placeholder="60"/>
|
||||
|
|
|
@ -134,11 +134,13 @@ window.view.instance = {
|
|||
return tpl;
|
||||
});
|
||||
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]')
|
||||
.value = js.action.name;
|
||||
E.element('#filter-instance-action input[name=instance_action_interval]')
|
||||
.value = js.action.interval;
|
||||
E.element('#filter-instance-action textarea[name=instance_action_explain]')
|
||||
.value = js.action.explain;
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
@ -151,8 +153,10 @@ window.view.instance = {
|
|||
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();
|
||||
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}`,
|
||||
{},function(js){ if (js.ok) toast.info(js.ok) });
|
||||
const v3 = E.element('#filter-instance-action textarea[name=instance_action_explain]').value.trim();
|
||||
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) {
|
||||
if (!confirm('Are you sure you want to delete this filter?'))
|
||||
|
|
Loading…
Reference in New Issue