Skip to content

Commit

Permalink
More nits.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Jan 3, 2024
1 parent 177516a commit e6c0c8a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/api/api_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static function user(Contact $user, Qrequest $qreq, PaperInfo $prow = null) {
if ($user->privChair || $user->can_view_pc()) {
$roles = $user->is_manager() ? "" : " and roles!=0 and (roles&" . Contact::ROLE_PC . ")!=0";
$result = $user->conf->qe("select " . $user->conf->user_query_fields($slice) . " from ContactInfo where email>=? and email<? and (cflags&?)=0{$roles} order by email asc limit 2",
$email, "{$email}~", Contact::CFLAG_DISABLEMENT);
$email, "{$email}~", Contact::CFMASK_DISABLEMENT);
while (($u = Contact::fetch($result, $user->conf))) {
$users[] = $u;
}
Expand All @@ -38,7 +38,7 @@ static function user(Contact $user, Qrequest $qreq, PaperInfo $prow = null) {
$fields = $user->conf->user_query_fields($slice);
}
$result = Dbl::qe($db, "select {$fields} from ContactInfo where email>=? and email<? and (cflags&?)=0 order by email asc limit 2",
$email, "{$email}~", Contact::CFLAG_DISABLEMENT);
$email, "{$email}~", Contact::CFMASK_DISABLEMENT);
$users = [];
while (($u = Contact::fetch($result, $user->conf))) {
$users[] = $u;
Expand Down
6 changes: 3 additions & 3 deletions src/confinvariants.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,17 +447,17 @@ function check_users() {
}

// disabled has only expected bits
if (($u->disabled & Contact::CFLAG_DISABLEMENT & ~Contact::CFLAG_DBMASK) !== 0) {
if (($u->disabled & Contact::CFMASK_DISABLEMENT & ~Contact::CFMASK_DB) !== 0) {
$this->invariant_error("user_disabled", sprintf("user {$u->email}/{$u->contactId} bad disabled %x", $u->disabled));
}

// cflags has only expected bits
if (($u->cflags & ~Contact::CFLAG_DBMASK) !== 0) {
if (($u->cflags & ~Contact::CFMASK_DB) !== 0) {
$this->invariant_error("user_cflags", sprintf("user {$u->email}/{$u->contactId} bad cflags %x", $u->cflags));
}

// cflags reflects disabled
if ($u->disabled !== ($u->cflags & Contact::CFLAG_DISABLEMENT)) {
if ($u->disabled !== ($u->cflags & Contact::CFMASK_DISABLEMENT)) {
$this->invariant_error("user_cflags_disabled", sprintf("user {$u->email}/{$u->contactId} disabled %x unreflected in cflags %x", $u->disabled, $u->cflags));
}

Expand Down
36 changes: 18 additions & 18 deletions src/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ class Contact implements JsonSerializable {
const CFLAG_GDISABLED = 0x10;
const CFLAG_UNCONFIRMED = 0x20;

const CFLAG_DISABLEMENT = 0x1F;
const CFLAG_DBMASK = ~0xC;
const CFMASK_DISABLEMENT = 0x1F;
const CFMASK_DB = ~0xC;

const PROP_LOCAL = 0x01;
const PROP_CDB = 0x02;
Expand Down Expand Up @@ -345,7 +345,7 @@ static function make_keyed(Conf $conf, $args) {
$u->orcid = trim($args["orcid"] ?? "");
$u->cflags = ($args["disablement"] ?? 0) | self::CFLAG_UNCONFIRMED;
/** @phan-suppress-next-line PhanDeprecatedProperty */
$u->disabled = $u->cflags & self::CFLAG_DISABLEMENT & self::CFLAG_DBMASK;
$u->disabled = $u->cflags & self::CFMASK_DISABLEMENT & self::CFMASK_DB;
$u->set_roles_properties();
return $u;
}
Expand Down Expand Up @@ -980,12 +980,12 @@ function update_cdb() {
$cdbux->set_prop("passwordTime", $this->passwordTime);
$cdbux->set_prop("passwordUseTime", $this->passwordUseTime);
}
if (($this->cflags & self::CFLAG_DISABLEMENT) === 0) {
if (($this->cflags & self::CFMASK_DISABLEMENT) === 0) {
$cdbux->set_prop("cflags", $cdbux->cflags & ~Contact::CFLAG_PLACEHOLDER);
$cdbux->set_prop("disabled", $cdbux->cflags & Contact::CFLAG_DISABLEMENT & Contact::CFLAG_DBMASK);
$cdbux->set_prop("disabled", $cdbux->cflags & Contact::CFMASK_DISABLEMENT & Contact::CFMASK_DB);
} else if (!$cdbur) {
$cdbux->set_prop("cflags", $cdbux->cflags | Contact::CFLAG_PLACEHOLDER);
$cdbux->set_prop("disabled", $cdbux->cflags & Contact::CFLAG_DISABLEMENT & Contact::CFLAG_DBMASK);
$cdbux->set_prop("disabled", $cdbux->cflags & Contact::CFMASK_DISABLEMENT & Contact::CFMASK_DB);
}
if (($this->cflags & self::CFLAG_UNCONFIRMED) === 0) {
$cdbux->set_prop("cflags", $cdbux->cflags & ~Contact::CFLAG_UNCONFIRMED);
Expand Down Expand Up @@ -1032,12 +1032,12 @@ function owns_email($email) {

/** @return bool */
function is_disabled() {
return ($this->cflags & self::CFLAG_DISABLEMENT & ~self::CFLAG_PLACEHOLDER) !== 0;
return ($this->cflags & self::CFMASK_DISABLEMENT & ~self::CFLAG_PLACEHOLDER) !== 0;
}

/** @return bool */
function is_dormant() {
return ($this->cflags & self::CFLAG_DISABLEMENT) !== 0;
return ($this->cflags & self::CFMASK_DISABLEMENT) !== 0;
}

/** @return bool */
Expand All @@ -1053,12 +1053,12 @@ function is_placeholder() {
/** @return bool */
function contactdb_disabled() {
$cdbu = $this->cdb_user();
return $cdbu && ($cdbu->cflags & self::CFLAG_DISABLEMENT & ~self::CFLAG_PLACEHOLDER) !== 0;
return $cdbu && ($cdbu->cflags & self::CFMASK_DISABLEMENT & ~self::CFLAG_PLACEHOLDER) !== 0;
}

/** @return int */
function disabled_flags() {
return $this->cflags & self::CFLAG_DISABLEMENT;
return $this->cflags & self::CFMASK_DISABLEMENT;
}

/** @return bool */
Expand All @@ -1069,7 +1069,7 @@ function is_unconfirmed() {
/** @param bool $self_requested
* @return bool */
function can_receive_mail($self_requested = false) {
$disabled = self::CFLAG_DISABLEMENT;
$disabled = self::CFMASK_DISABLEMENT;
if ($self_requested) {
$disabled &= ~self::CFLAG_PLACEHOLDER;
} else if (($this->cflags & self::CFLAG_UNCONFIRMED) !== 0
Expand Down Expand Up @@ -1764,7 +1764,7 @@ private function clean_prop_value($prop, $value) {
if ($prop === "roles") {
return $value & ($this->cdb_confid === 0 ? self::ROLE_DBMASK : self::ROLE_CDBMASK);
} else if ($prop === "cflags") {
return $value & self::CFLAG_DBMASK;
return $value & self::CFMASK_DB;
} else {
assert(false);
return $value;
Expand Down Expand Up @@ -1922,7 +1922,7 @@ function activate_placeholder_prop($confirm) {
$changed = false;
if (($this->cflags & self::CFLAG_PLACEHOLDER) !== 0) {
$this->set_prop("cflags", $this->cflags & ~self::CFLAG_PLACEHOLDER);
$this->set_prop("disabled", $this->cflags & self::CFLAG_DISABLEMENT & self::CFLAG_DBMASK);
$this->set_prop("disabled", $this->cflags & self::CFMASK_DISABLEMENT & self::CFMASK_DB);
$changed = true;
}
if (($this->cflags & self::CFLAG_UNCONFIRMED) !== 0 && $confirm) {
Expand Down Expand Up @@ -2068,26 +2068,26 @@ function import_prop($src, $ifempty) {

// disablement import is special
// source is disabled local user, creating cdb user: cdb is placeholder
$sdflags = $src->cflags & self::CFLAG_DISABLEMENT;
$sdflags = $src->cflags & self::CFMASK_DISABLEMENT;
if ($sdflags !== 0
&& $this->cdb_confid !== 0
&& $this->contactDbId === 0) {
$this->set_prop("cflags", $this->cflags | self::CFLAG_PLACEHOLDER);
$this->set_prop("disabled", $this->cflags & self::CFLAG_DISABLEMENT & self::CFLAG_DBMASK);
$this->set_prop("disabled", $this->cflags & self::CFMASK_DISABLEMENT & self::CFMASK_DB);
}
// source is non-disabled local user: this is not placeholder
if ($src->cdb_confid === 0
&& $sdflags === 0
&& ($this->cflags & self::CFLAG_PLACEHOLDER) !== 0) {
$this->set_prop("cflags", $this->cflags & ~self::CFLAG_PLACEHOLDER);
$this->set_prop("disabled", $this->cflags & self::CFLAG_DISABLEMENT & self::CFLAG_DBMASK);
$this->set_prop("disabled", $this->cflags & self::CFMASK_DISABLEMENT & self::CFMASK_DB);
}
// source is globally disabled: this local user is disabled
if (($sdflags & self::CFLAG_GDISABLED) !== 0
&& $src->cdb_confid !== 0
&& $this->cdb_confid === 0) {
$this->set_prop("cflags", $this->cflags | self::CFLAG_GDISABLED);
$this->set_prop("disabled", $this->cflags & self::CFLAG_DISABLEMENT & self::CFLAG_DBMASK);
$this->set_prop("disabled", $this->cflags & self::CFMASK_DISABLEMENT & self::CFMASK_DB);
}

// unconfirmed import is special
Expand Down Expand Up @@ -2186,7 +2186,7 @@ function store($flags = 0, $actor = null) {
// log creation (except for placeholder accounts)
if (($this->cflags & self::CFLAG_PLACEHOLDER) === 0) {
$msg = "Account created";
if (($this->cflags & self::CFLAG_DISABLEMENT & ~self::CFLAG_ROLEDISABLED) !== 0) {
if (($this->cflags & self::CFMASK_DISABLEMENT & ~self::CFLAG_ROLEDISABLED) !== 0) {
$msg .= ", disabled";
}
$this->conf->log_for($actor && $actor->has_email() ? $actor : $this, $this, $msg);
Expand Down
2 changes: 1 addition & 1 deletion src/mailrecipients.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ function paper($pid) {
* @return string|false */
function query($paper_sensitive) {
$cols = [];
$where = ["(cflags&" . Contact::CFLAG_DISABLEMENT . ")=0"];
$where = ["(cflags&" . Contact::CFMASK_DISABLEMENT . ")=0"];
$joins = ["ContactInfo"];

// reviewer limit
Expand Down
4 changes: 2 additions & 2 deletions src/userstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -1060,10 +1060,10 @@ static function save_main(UserStatus $us) {
$cflags &= ~Contact::CFLAG_UDISABLED;
}
}
if (($cflags & Contact::CFLAG_DISABLEMENT) === Contact::CFLAG_PLACEHOLDER) {
if (($cflags & Contact::CFMASK_DISABLEMENT) === Contact::CFLAG_PLACEHOLDER) {
$cflags &= ~Contact::CFLAG_PLACEHOLDER;
}
$user->set_prop("disabled", $cflags & Contact::CFLAG_DISABLEMENT);
$user->set_prop("disabled", $cflags & Contact::CFMASK_DISABLEMENT);
$user->set_prop("cflags", $cflags);
if ($user->prop_changed("disabled") && isset($cj->disabled)) {
$us->diffs[$cj->disabled ? "disabled" : "enabled"] = true;
Expand Down

0 comments on commit e6c0c8a

Please sign in to comment.