Skip to content

Commit

Permalink
Internal: Introduce ContactInfo.cflags in database.
Browse files Browse the repository at this point in the history
`cflags` will cover flags about contacts. It starts with disablement.

* Remove Contact::$disablement.
* Deprecate Contact::$disabled; refer only to $cflags.
* Add some invariants.
  • Loading branch information
kohler committed Nov 4, 2023
1 parent f9a390f commit d741e1e
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 70 deletions.
2 changes: 1 addition & 1 deletion batch/updatecontactdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private function run_users() {
$result->close();

// read current db roles
$result = Dbl::ql($this->conf->dblink, "select ContactInfo.contactId, email, firstName, lastName, unaccentedName, disabled,
$result = Dbl::ql($this->conf->dblink, "select ContactInfo.contactId, email, firstName, lastName, affiliation, cflags,
(ContactInfo.roles
| if(exists (select * from PaperConflict where contactId=ContactInfo.contactId and conflictType>=" . CONFLICT_AUTHOR . ")," . Contact::ROLE_AUTHOR . ",0)
| if(exists (select * from PaperReview where contactId=ContactInfo.contactId)," . Contact::ROLE_REVIEWER . ",0)) roles,
Expand Down
8 changes: 5 additions & 3 deletions src/api/api_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ static function user(Contact $user, Qrequest $qreq, PaperInfo $prow = null) {
- Contact::SLICEBIT_COUNTRY - Contact::SLICEBIT_ORCID;
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 not disabled{$roles} order by email asc limit 2", $email, $email . "~");
$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);
while (($u = Contact::fetch($result, $user->conf))) {
$users[] = $u;
}
Expand All @@ -36,7 +37,8 @@ static function user(Contact $user, Qrequest $qreq, PaperInfo $prow = null) {
$db = $user->conf->dblink;
$fields = $user->conf->user_query_fields($slice);
}
$result = Dbl::qe($db, "select {$fields} from ContactInfo where email>=? and email<? and not disabled order by email asc limit 2", $email, $email . "~");
$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);
$users = [];
while (($u = Contact::fetch($result, $user->conf))) {
$users[] = $u;
Expand All @@ -46,7 +48,7 @@ static function user(Contact $user, Qrequest $qreq, PaperInfo $prow = null) {

if (empty($users)
&& strcasecmp($user->email, $email) >= 0
&& strcasecmp($user->email, $email . "~") < 0) {
&& strcasecmp($user->email, "{$email}~") < 0) {
$users[] = $user;
}

Expand Down
2 changes: 1 addition & 1 deletion src/author.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Author {
/** @var int */
public $roles = 0;
/** @var int */
public $disablement = 0;
private $disablement = 0;
/** @var ?int */
public $conflictType;
/** @var ?int */
Expand Down
6 changes: 3 additions & 3 deletions src/conference.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ function __load_settings() {

function load_settings() {
$this->__load_settings();
if ($this->sversion < 284) {
if ($this->sversion < 285) {
$old_nerrors = Dbl::$nerrors;
while ((new UpdateSchema($this))->run()) {
usleep(50000);
Expand Down Expand Up @@ -1949,7 +1949,7 @@ function disablement_for($disabled, $roles) {
* @return string */
function user_query_fields($slice = Contact::SLICE_MINIMAL, $prefix = "") {
if (($slice & Contact::SLICEBIT_REST) !== 0) {
$f = "{$prefix}contactId, {$prefix}email, {$prefix}firstName, {$prefix}lastName, {$prefix}affiliation, {$prefix}roles, {$prefix}disabled, {$prefix}primaryContactId, {$prefix}contactTags";
$f = "{$prefix}contactId, {$prefix}email, {$prefix}firstName, {$prefix}lastName, {$prefix}affiliation, {$prefix}roles, {$prefix}disabled, {$prefix}primaryContactId, {$prefix}contactTags, {$prefix}cflags";
if (($slice & Contact::SLICEBIT_COLLABORATORS) === 0) {
$f .= ", {$prefix}collaborators";
}
Expand All @@ -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::CFLAG_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, " . Contact::CFLAG_DELETED . " cflags, 0 _slice";
}

/** @param int $slice
Expand Down
17 changes: 14 additions & 3 deletions src/confinvariants.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,13 @@ function check_users() {
$u->primaryContactId = intval($u->primaryContactId);
$u->roles = intval($u->roles);
$u->disabled = intval($u->disabled);
$u->cflags = intval($u->cflags);
unset($authors[strtolower($u->email)]);

// anonymous users are disabled
if (str_starts_with($u->email, "anonymous")
&& Contact::is_anonymous_email($u->email)
&& ($u->disabled & 1) !== 1) {
&& ($u->cflags & Contact::CFLAG_UDISABLED) === 0) {
$this->invariant_error("anonymous_user_enabled", "anonymous user {$u->email} is not disabled");
}

Expand Down Expand Up @@ -446,8 +447,18 @@ function check_users() {
}

// disabled has only expected bits
if (($u->disabled & ~Contact::DISABLEMENT_DB) !== 0) {
$this->invariant_error("user_disabled", "user {$u->email}/{$u->contactId} is funkily disabled");
if (($u->disabled & Contact::CFLAG_DISABLEMENT & ~Contact::CFLAG_DBMASK) !== 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) {
$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)) {
$this->invariant_error("user_cflags_disabled", sprintf("user {$u->email}/{$u->contactId} disabled %x unreflected in cflags %x", $u->disabled, $u->cflags));
}

// contactTags is a valid tag string
Expand Down
Loading

0 comments on commit d741e1e

Please sign in to comment.