Skip to content

Commit

Permalink
Send account info and disable/enable buttons are smarter about placeh…
Browse files Browse the repository at this point in the history
…olders.
  • Loading branch information
kohler committed Oct 4, 2023
1 parent cdb6dd6 commit 89ae497
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 30 deletions.
3 changes: 2 additions & 1 deletion lib/messageset.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ function jsonSerialize() {
}

/** @param ?string $msg
* @return array{ok:false,message_list:list<MessageItem>} */
* @return array{ok:false,message_list:list<MessageItem>}
* @deprecated */
static function make_error_json($msg) {
return ["ok" => false, "message_list" => [new MessageItem(null, $msg ?? "", 2)]];
}
Expand Down
11 changes: 10 additions & 1 deletion scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -11893,7 +11893,16 @@ handle_ui.on("js-disable-user", function () {
removeClass(self, "btn-success");
addClass(self, "btn-danger");
}
$(self.form).find(".js-send-user-accountinfo").prop("disabled", data.disabled);
const h2 = document.querySelector("h2.leftmenu");
if (h2) {
if (h2.lastChild.nodeType === 1
&& h2.lastChild.className === "n dim user-disabled-marker") {
data.disabled || h2.lastChild.remove();
} else {
data.disabled && h2.appendChild($e("span", "n dim user-disabled-marker", "(disabled)"));
}
}
$(self.form).find(".js-send-user-accountinfo").prop("disabled", data.disabled || data.placeholder);
}
minifeedback(self, data);
});
Expand Down
4 changes: 2 additions & 2 deletions src/api/api_taganno.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TagAnno_API {
static function get(Contact $user, Qrequest $qreq) {
$tagger = new Tagger($user);
if (!($tag = $tagger->check($qreq->tag, Tagger::NOVALUE))) {
return MessageItem::make_error_json($tagger->error_ftext());
return JsonResult::make_error(400, $tagger->error_ftext());
}
$dt = $user->conf->tags()->ensure(Tagger::tv_tag($tag));
$anno = [];
Expand All @@ -29,7 +29,7 @@ static function get(Contact $user, Qrequest $qreq) {
static function set(Contact $user, Qrequest $qreq) {
$tagger = new Tagger($user);
if (!($tag = $tagger->check($qreq->tag, Tagger::NOVALUE))) {
return MessageItem::make_error_json($tagger->error_ftext());
return JsonResult::make_error(400, $tagger->error_ftext());
}
if (!$user->can_edit_tag_anno($tag)) {
return ["ok" => false, "error" => "Permission error"];
Expand Down
2 changes: 1 addition & 1 deletion src/api/api_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static function run(Contact $user, $qreq, $prow) {
static function votereport_api(Contact $user, Qrequest $qreq, PaperInfo $prow) {
$tagger = new Tagger($user);
if (!($tag = $tagger->check($qreq->tag, Tagger::NOVALUE))) {
return MessageItem::make_error_json($tagger->error_ftext());
return JsonResult::make_error(400, $tagger->error_ftext());
}
if (!$user->can_view_peruser_tag($prow, $tag)) {
return ["ok" => false, "error" => "Permission error"];
Expand Down
24 changes: 19 additions & 5 deletions src/api/api_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ static function account_disable(Contact $user, Contact $viewer, $disabled) {
$ustatus = new UserStatus($viewer);
$ustatus->set_user($user);
if ($ustatus->save_user((object) ["disabled" => $disabled], $user)) {
return new JsonResult(["ok" => true, "u" => $user->email, "disabled" => $user->disablement !== 0]);
$d = $user->disablement;
return new JsonResult([
"ok" => true,
"u" => $user->email,
"disabled" => ($d & ~Contact::DISABLEMENT_PLACEHOLDER) !== 0,
"placeholder" => ($d & Contact::DISABLEMENT_PLACEHOLDER) !== 0
]);
} else {
return new JsonResult(["ok" => false, "u" => $user->email]);
}
Expand All @@ -124,14 +130,22 @@ static function account_disable(Contact $user, Contact $viewer, $disabled) {
static function account_sendinfo(Contact $user, Contact $viewer) {
if (!$viewer->privChair) {
return JsonResult::make_permission_error();
} else if ($user->disablement === 0) {
}
if ($user->activate_placeholder_prop(false)) {
$user->save_prop();
}
if ($user->disablement === 0) {
$user->send_mail("@accountinfo");
return new JsonResult(["ok" => true, "u" => $user->email]);
}
if ($user->disablement === Contact::DISABLEMENT_PLACEHOLDER) {
$msg = "<0>This user has not yet activated their account";
} else {
$j = MessageItem::make_error_json("<0>User disabled");
$j["u"] = $user->email;
return new JsonResult($j);
$msg = "<0>User disabled";
}
$jr = JsonResult::make_error(400, $msg);
$jr->content["u"] = $user->email;
return $jr;
}

/** @return JsonResult */
Expand Down
26 changes: 15 additions & 11 deletions src/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ static function make_email(Conf $conf, $email) {
return $u;
}

/** @param int $contactId
* @return Contact */
/** @return Contact */
static function make_placeholder(Conf $conf) {
$u = new Contact($conf);
$u->contactXid = self::$next_xid--;
Expand Down Expand Up @@ -765,8 +764,7 @@ function activate($qreq, $signin, $userindex = 0) {

// maybe auto-create a user
if (($this->_activated & 2) === 0 && $this->email) {
if (($this->disabled & self::DISABLEMENT_PLACEHOLDER) !== 0) {
$this->activate_placeholder_prop();
if ($this->activate_placeholder_prop(true)) {
$this->save_prop();
}
$trueuser_aucheck = $qreq->csession("trueuser_author_check") ?? 0;
Expand Down Expand Up @@ -1586,11 +1584,11 @@ function escape($qreq = null) {
} else {
$m = "<0>You don’t have permission to access this function";
}
$j = MessageItem::make_error_json($m);
$jr = JsonResult::make_error(403, $m);
if (!$this->is_signed_in()) {
$j["loggedout"] = true;
$jr->content["loggedout"] = true;
}
json_exit($j);
json_exit($jr);
}

if ($this->is_signed_in()) {
Expand Down Expand Up @@ -1837,9 +1835,15 @@ function prop_changed($prop = null) {
return $prop ? array_key_exists($prop, $this->_mod_undo ?? []) : !empty($this->_mod_undo);
}

function activate_placeholder_prop() {
if (($this->disabled & self::DISABLEMENT_PLACEHOLDER) !== 0) {
/** @param bool $always
* @return bool */
function activate_placeholder_prop($always) {
if (($this->disabled & self::DISABLEMENT_PLACEHOLDER) !== 0
&& ($always || $this->conf->allow_user_activate_other())) {
$this->set_prop("disabled", $this->disabled & ~self::DISABLEMENT_PLACEHOLDER);
return true;
} else {
return false;
}
}

Expand Down Expand Up @@ -2359,7 +2363,7 @@ function change_password($new) {
$saveu->set_prop("password", $hash);
$saveu->set_prop("passwordTime", Conf::$now);
$saveu->set_prop("passwordUseTime", $use_time);
$saveu->activate_placeholder_prop();
$saveu->activate_placeholder_prop(true);
$saveu->save_prop();
}

Expand All @@ -2368,7 +2372,7 @@ function change_password($new) {
$this->set_prop("passwordTime", Conf::$now);
$this->set_prop("passwordUseTime", $use_time);
}
$this->activate_placeholder_prop();
$this->activate_placeholder_prop(true);
$this->save_prop();

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/p_doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static function go($user, $qreq) {
// check for contents request
if ($qreq->fn === "listing" || $qreq->fn === "consolidatedlisting") {
if (!$doc->is_archive()) {
json_exit(MessageItem::make_error_json("<0>That file is not an archive"));
json_exit(JsonResult::make_error(400, "<0>That file is not an archive"));
} else if (($listing = $doc->archive_listing(65536)) === null) {
$ml = $doc->message_list();
if (empty($ml)) {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/p_profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,9 @@ function print() {
if ($this->user !== $this->viewer) {
echo $this->viewer->name_for("rn", $this->user), ' ';
}
echo htmlspecialchars($this->ustatus->cs()->get($this->topic)->title);
echo htmlspecialchars($this->ustatus->cs()->get($this->topic)->title), ' ';
if ($this->user->is_disabled()) {
echo ' <span class="n dim">(disabled)</span>';
echo '<span class="n dim user-disabled-marker">(disabled)</span>';
}
}
echo '</h2>';
Expand Down
5 changes: 2 additions & 3 deletions src/paperstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -1225,9 +1225,8 @@ private function _execute_conflicts() {
continue;
}
$us[] = $u;
if ($u->is_placeholder()
&& self::new_conflict_value($this->_conflict_values[$u->contactId]) >= CONFLICT_CONTACTAUTHOR) {
$u->activate_placeholder_prop();
if (self::new_conflict_value($this->_conflict_values[$u->contactId]) >= CONFLICT_CONTACTAUTHOR
&& $u->activate_placeholder_prop(false)) {
$u->save_prop();
$this->_created_contacts[] = $u;
}
Expand Down
14 changes: 11 additions & 3 deletions src/userstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -1638,11 +1638,18 @@ static function print_main_actions(UserStatus $us) {
return;
}
$us->cs()->add_section_class("form-outline-section")->print_start_section("User administration");
$disablement = $us->user->disablement & ~Contact::DISABLEMENT_PLACEHOLDER;
echo '<div class="btngrid"><div class="d-flex mf mf-absolute">',
Ht::button("Send account information", ["class" => "ui js-send-user-accountinfo flex-grow-1", "disabled" => $disablement !== 0]), '</div><p></p>';
echo '<div class="btngrid"><div class="d-flex mf mf-absolute">';

if ($us->user->disablement === Contact::DISABLEMENT_PLACEHOLDER) {
$disabled = !$us->conf->allow_user_activate_other();
} else {
$disabled = $us->user->disablement !== 0;
}
echo Ht::button("Send account information", ["class" => "ui js-send-user-accountinfo flex-grow-1", "disabled" => $disabled]), '</div><p></p>';

if (!$us->is_auth_user()) {
echo '<div class="d-flex mf mf-absolute">';
$disablement = $us->user->disablement & ~Contact::DISABLEMENT_PLACEHOLDER;
if ($us->user->contactdb_disabled()) {
$klass = "flex-grow-1 disabled";
$p = "<p class=\"pt-1 mb-0 feedback is-warning\">This account is disabled on all sites.</p>";
Expand All @@ -1662,6 +1669,7 @@ static function print_main_actions(UserStatus $us) {

self::print_delete_action($us);
}

echo '</div>';
}

Expand Down

0 comments on commit 89ae497

Please sign in to comment.