Skip to content

Commit

Permalink
Prepare for contact flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Nov 3, 2023
1 parent 4a06ad4 commit f9a390f
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 72 deletions.
2 changes: 1 addition & 1 deletion batch/savepapers.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function run_one($index, $j) {
"lastName" => $this->tf->req["reviewerLast"] ?? "",
"email" => $this->tf->req["reviewerEmail"],
"affiliation" => $this->tf->req["reviewerAffiliation"] ?? null,
"disablement" => $this->disable_users ? Contact::DISABLEMENT_USER : 0
"disablement" => $this->disable_users ? Contact::CFLAG_UDISABLED : 0
])->store();
$this->tf->check_and_save($this->user, $prow, null);
}
Expand Down
2 changes: 1 addition & 1 deletion batch/updatecontactdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function run_authors() {
"firstName" => $au->firstName,
"lastName" => $au->lastName,
"affiliation" => $au->affiliation,
"disablement" => Contact::DISABLEMENT_PLACEHOLDER
"disablement" => Contact::CFLAG_PLACEHOLDER
])->store();
// NB: Contact::store() creates CONFLICT_AUTHOR records.
$u->update_cdb();
Expand Down
2 changes: 1 addition & 1 deletion src/assignmentset.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ function user_by_email($email, $create = false, $req = null) {
$cargs["firstName"] = "Jane Q.";
$cargs["lastName"] = "Public";
$cargs["affiliation"] = "Unaffiliated";
$cargs["disablement"] = Contact::DISABLEMENT_USER;
$cargs["disablement"] = Contact::CFLAG_UDISABLED;
}
$c = Contact::make_keyed($this->conf, $cargs);
}
Expand Down
5 changes: 5 additions & 0 deletions src/author.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ function is_nonauthor() {
return $this->status === self::STATUS_NONAUTHOR;
}

/** @return bool */
function is_placeholder() {
return ($this->disablement & Contact::CFLAG_PLACEHOLDER) !== 0;
}

/** @return int */
function disabled_flags() {
return $this->disablement;
Expand Down
4 changes: 2 additions & 2 deletions src/conference.php
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,7 @@ function site_contact() {
* @return int */
function disablement_for($disabled, $roles) {
if ($this->disable_non_pc && ($roles & Contact::ROLE_PCLIKE) === 0) {
$disabled |= Contact::DISABLEMENT_ROLE;
$disabled |= Contact::CFLAG_ROLEDISABLED;
}
return $disabled;
}
Expand Down Expand Up @@ -1971,7 +1971,7 @@ function user_query_fields($slice = Contact::SLICE_MINIMAL, $prefix = "") {
/** @param string $prefix
* @return string */
function deleted_user_query_fields($prefix = "") {
return "{$prefix}contactId, {$prefix}email, {$prefix}firstName, {$prefix}lastName, {$prefix}affiliation, 0 roles, " . Contact::DISABLEMENT_DELETED . " disabled, 0 primaryContactId, '' contactTags, 0 _slice";
return "{$prefix}contactId, {$prefix}email, {$prefix}firstName, {$prefix}lastName, {$prefix}affiliation, 0 roles, " . Contact::CFLAG_DELETED . " disabled, 0 primaryContactId, '' contactTags, 0 _slice";
}

/** @param int $slice
Expand Down
47 changes: 28 additions & 19 deletions src/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Contact implements JsonSerializable {
/** @var ?string */
public $contactTags;
/** @var int */
public $contactFlags = 0;
public $cflags = 0;

/** @var int */
public $_slice = 0;
Expand Down Expand Up @@ -205,13 +205,22 @@ class Contact implements JsonSerializable {
public $myReviewPermissions;
public $paperId;

/** @deprecated */
const DISABLEMENT_USER = 1;
/** @deprecated */
const DISABLEMENT_PLACEHOLDER = 2;
// NB some code depends on PLACEHOLDER being highest bit in DB
const DISABLEMENT_DB = 3;
/** @deprecated */
const DISABLEMENT_ROLE = 4;
/** @deprecated */
const DISABLEMENT_DELETED = 8;

const CFLAG_UDISABLED = 1;
const CFLAG_PLACEHOLDER = 2;
const CFLAG_ROLEDISABLED = 4;
const CFLAG_DELETED = 8;

const PROP_LOCAL = 0x01;
const PROP_CDB = 0x02;
const PROP_SLICE = 0x04;
Expand Down Expand Up @@ -282,7 +291,7 @@ static function make_email(Conf $conf, $email) {
static function make_placeholder(Conf $conf) {
$u = new Contact($conf);
$u->contactXid = self::$next_xid--;
$u->disabled = self::DISABLEMENT_PLACEHOLDER;
$u->disabled = self::CFLAG_PLACEHOLDER;
$u->set_roles_properties();
return $u;
}
Expand All @@ -294,7 +303,7 @@ static function make_deleted(Conf $conf, $contactId) {
$u->contactId = $contactId;
$u->contactXid = $contactId > 0 ? $contactId : self::$next_xid--;
$u->email = "<deleted>";
$u->disablement = self::DISABLEMENT_DELETED;
$u->disablement = self::CFLAG_DELETED;
$u->set_roles_properties();
return $u;
}
Expand Down Expand Up @@ -408,7 +417,7 @@ private function set_roles_properties() {
$this->isPC = ($this->roles & self::ROLE_PCLIKE) !== 0;
$this->privChair = ($this->roles & (self::ROLE_ADMIN | self::ROLE_CHAIR)) !== 0;
$this->disablement = $this->conf->disablement_for($this->disabled, $this->roles)
| ($this->disablement & self::DISABLEMENT_DELETED);
| ($this->disablement & self::CFLAG_DELETED);
}

/** @suppress PhanAccessReadOnlyProperty */
Expand Down Expand Up @@ -955,9 +964,9 @@ function update_cdb() {
$cdbux->set_prop("passwordUseTime", $this->passwordUseTime);
}
if ($this->disablement === 0) {
$cdbux->set_prop("disabled", $cdbux->disabled & ~Contact::DISABLEMENT_PLACEHOLDER);
$cdbux->set_prop("disabled", $cdbux->disabled & ~Contact::CFLAG_PLACEHOLDER);
} else if (!$cdbur) {
$cdbux->set_prop("disabled", Contact::DISABLEMENT_PLACEHOLDER);
$cdbux->set_prop("disabled", Contact::CFLAG_PLACEHOLDER);
}
if (!empty($cdbux->_mod_undo)) {
assert($cdbux->cdb_confid !== 0);
Expand Down Expand Up @@ -1000,7 +1009,7 @@ function owns_email($email) {

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

/** @return bool */
Expand All @@ -1010,18 +1019,18 @@ function is_dormant() {

/** @return bool */
function is_explicitly_disabled() {
return ($this->disablement & self::DISABLEMENT_USER) !== 0;
return ($this->disablement & self::CFLAG_UDISABLED) !== 0;
}

/** @return bool */
function is_placeholder() {
return ($this->disablement & self::DISABLEMENT_PLACEHOLDER) !== 0;
return ($this->disablement & self::CFLAG_PLACEHOLDER) !== 0;
}

/** @return bool */
function contactdb_disabled() {
$cdbu = $this->cdb_user();
return $cdbu && ($cdbu->disablement & ~self::DISABLEMENT_PLACEHOLDER) !== 0;
return $cdbu && ($cdbu->disablement & ~self::CFLAG_PLACEHOLDER) !== 0;
}

/** @return int */
Expand Down Expand Up @@ -1760,7 +1769,7 @@ function set_prop($prop, $value, $ifempty = false) {
// on `$ifempty`, update only empty properties and placeholder users
$old = $this->prop1($prop, $shape);
if ($ifempty
&& (($this->disabled & self::DISABLEMENT_PLACEHOLDER) === 0
&& (($this->disabled & self::CFLAG_PLACEHOLDER) === 0
|| $value === null
|| $value === "")) {
if ($old !== null && $old !== "") {
Expand Down Expand Up @@ -1846,9 +1855,9 @@ function prop_changed($prop = null) {
/** @param bool $always
* @return bool */
function activate_placeholder_prop($always) {
if (($this->disabled & self::DISABLEMENT_PLACEHOLDER) !== 0
if (($this->disabled & self::CFLAG_PLACEHOLDER) !== 0
&& ($always || $this->conf->allow_user_activate_other())) {
$this->set_prop("disabled", $this->disabled & ~self::DISABLEMENT_PLACEHOLDER);
$this->set_prop("disabled", $this->disabled & ~self::CFLAG_PLACEHOLDER);
return true;
} else {
return false;
Expand Down Expand Up @@ -1991,19 +2000,19 @@ function import_prop($src, $ifempty) {
if ($src->disablement !== 0
&& $this->cdb_confid !== 0
&& $this->contactDbId === 0) {
$this->set_prop("disabled", $this->disabled | self::DISABLEMENT_PLACEHOLDER);
$this->set_prop("disabled", $this->disabled | self::CFLAG_PLACEHOLDER);
}
// source is non-disabled local user: this is not placeholder
if ($src->cdb_confid === 0
&& $src->disablement === 0
&& ($this->disabled & self::DISABLEMENT_PLACEHOLDER) !== 0) {
$this->set_prop("disabled", $this->disabled & ~self::DISABLEMENT_PLACEHOLDER);
&& ($this->disabled & self::CFLAG_PLACEHOLDER) !== 0) {
$this->set_prop("disabled", $this->disabled & ~self::CFLAG_PLACEHOLDER);
}
// source is globally disabled: this local user is disabled
if (($src->disabled & self::DISABLEMENT_USER) !== 0
if (($src->disabled & self::CFLAG_UDISABLED) !== 0
&& $src->cdb_confid !== 0
&& $this->cdb_confid === 0) {
$this->set_prop("disabled", $this->disabled | self::DISABLEMENT_USER);
$this->set_prop("disabled", $this->disabled | self::CFLAG_UDISABLED);
}
}

Expand Down Expand Up @@ -2094,7 +2103,7 @@ function store($flags = 0, $actor = null) {
}

// log creation (except for placeholder accounts)
if ($this->disabled !== self::DISABLEMENT_PLACEHOLDER) {
if ($this->disabled !== self::CFLAG_PLACEHOLDER) {
$type = $this->disabled !== 0 ? ", disabled" : "";
$this->conf->log_for($actor && $actor->has_email() ? $actor : $this, $this, "Account created" . $type);
}
Expand Down
2 changes: 1 addition & 1 deletion src/contactlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ function _rows() {
} else if ($this->_limit_cids !== null) {
$mainwhere[] = "contactId" . sql_in_int_list(array_keys($this->_limit_cids));
}
$mainwhere[] = "disabled<" . Contact::DISABLEMENT_PLACEHOLDER;
$mainwhere[] = "disabled<" . Contact::CFLAG_PLACEHOLDER;

// make query
$result = $this->conf->qe_raw("select * from ContactInfo" . (empty($mainwhere) ? "" : " where " . join(" and ", $mainwhere)));
Expand Down
5 changes: 2 additions & 3 deletions src/options/o_contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ private function apply_parsed_users(PaperValue $ov, $specau) {
if ($j !== false) {
if ($specau[$i]->conflictType !== 0) {
$curau[$j]->author_index = $specau[$i]->author_index;
$modified = $modified
|| ($curau[$j]->disabled_flags() & Contact::DISABLEMENT_PLACEHOLDER) !== 0;
$modified = $modified || $curau[$j]->is_placeholder();
} else {
// only remove contacts on exact email match
// (removing by a non-primary email has no effect)
Expand Down Expand Up @@ -280,7 +279,7 @@ function print_web_edit(PaperTable $pt, $ov, $reqov) {
Ht::hidden("contacts:{$cidx}:email", $au->email);
if (($au->contactId > 0
&& ($au->conflictType & CONFLICT_AUTHOR) !== 0
&& ($au->disabled_flags() & Contact::DISABLEMENT_PLACEHOLDER) === 0)
&& !$au->is_placeholder())
|| ($au->contactId === $pt->user->contactId
&& $ov->prow->paperId <= 0)) {
echo Ht::hidden("contacts:{$cidx}:active", 1),
Expand Down
4 changes: 2 additions & 2 deletions src/pages/p_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ function user_html($user) {
if (($pc = $this->conf->pc_member_by_id($user->contactId))) {
$user = $pc;
}
if ($user->disabled_flags() & Contact::DISABLEMENT_DELETED) {
if ($user->disabled_flags() & Contact::CFLAG_DELETED) {
$t = '<del>' . $user->name_h(NAME_E) . '</del>';
} else {
$t = $user->name_h(NAME_P);
Expand Down Expand Up @@ -403,7 +403,7 @@ function users_html($users, $trueContactId) {
&& (!isset($user->roles) || !($user->roles & Contact::ROLE_PCLIKE))) {
$all_pc = false;
}
if ($user->disabled_flags() & Contact::DISABLEMENT_DELETED) {
if ($user->disabled_flags() & Contact::CFLAG_DELETED) {
if ($user->email) {
$t = '<del>' . $user->name_h(NAME_E) . '</del>';
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/paperstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,8 @@ private function _make_user($au, $ctype) {
}
if (!$uu && $ctype >= CONFLICT_AUTHOR) {
$j = $au->unparse_nea_json();
$j["disablement"] = ($this->disable_users ? Contact::DISABLEMENT_USER : 0)
| Contact::DISABLEMENT_PLACEHOLDER;
$j["disablement"] = ($this->disable_users ? Contact::CFLAG_UDISABLED : 0)
| Contact::CFLAG_PLACEHOLDER;
$uu = Contact::make_keyed($this->conf, $j)->store(0, $this->user);
if ($uu) {
$this->_created_contacts[] = $uu;
Expand Down
14 changes: 7 additions & 7 deletions src/userstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ function save_user($cj, $old_user = null) {
$this->check_invariants($cj);
$actor = $this->viewer->is_root_user() ? null : $this->viewer;
if (!$old_user) {
$create_cj = array_merge((array) $cj, ["disablement" => Contact::DISABLEMENT_PLACEHOLDER]);
$create_cj = array_merge((array) $cj, ["disablement" => Contact::CFLAG_PLACEHOLDER]);
$user = Contact::make_keyed($this->conf, $create_cj)->store(0, $actor);
$cj->email = $user->email; // adopt contactdb’s email capitalization
}
Expand Down Expand Up @@ -1015,15 +1015,15 @@ static function save_main(UserStatus $us) {
$disablement = $user->disabled_flags() & Contact::DISABLEMENT_DB;
if (isset($cj->disabled)) {
if ($cj->disabled) {
$disablement |= Contact::DISABLEMENT_USER;
$disablement |= Contact::CFLAG_UDISABLED;
} else {
$disablement &= ~Contact::DISABLEMENT_USER;
$disablement &= ~Contact::CFLAG_UDISABLED;
}
}
if ($disablement === Contact::DISABLEMENT_PLACEHOLDER
if ($disablement === Contact::CFLAG_PLACEHOLDER
&& ($us->viewer->is_root_user()
|| $us->conf->allow_user_activate_other())) {
$disablement &= ~Contact::DISABLEMENT_PLACEHOLDER;
$disablement &= ~Contact::CFLAG_PLACEHOLDER;
}
$user->set_prop("disabled", $disablement);
if ($user->prop_changed("disabled") && isset($cj->disabled)) {
Expand Down Expand Up @@ -1640,7 +1640,7 @@ static function print_main_actions(UserStatus $us) {
$us->cs()->add_section_class("form-outline-section")->print_start_section("User administration");
echo '<div class="grid-btn-explanation"><div class="d-flex mf mf-absolute">';

if ($us->user->disabled_flags() === Contact::DISABLEMENT_PLACEHOLDER) {
if ($us->user->disabled_flags() === Contact::CFLAG_PLACEHOLDER) {
$disabled = !$us->conf->allow_user_activate_other();
} else {
$disabled = $us->user->disabled_flags() !== 0;
Expand All @@ -1649,7 +1649,7 @@ static function print_main_actions(UserStatus $us) {

if (!$us->is_auth_user()) {
echo '<div class="d-flex mf mf-absolute">';
$disablement = $us->user->disabled_flags() & ~Contact::DISABLEMENT_PLACEHOLDER;
$disablement = $us->user->disabled_flags() & ~Contact::CFLAG_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 Down
Loading

0 comments on commit f9a390f

Please sign in to comment.