Skip to content

Commit

Permalink
Attempt to ensure creating users have accounts.
Browse files Browse the repository at this point in the history
Seeing some inappropriate behavior but can't replicate it in a test.
Nevertheless, this is better.
  • Loading branch information
kohler committed Sep 15, 2023
1 parent 7f5b51a commit 83a30ce
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/pages/p_paper.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,6 @@ static function go(Contact $user, Qrequest $qreq) {
$pp->load_prow();

// fix user
if ($qreq->is_post() && $qreq->valid_token()) {
$user->ensure_account_here();
// XXX escape unless update && can_start_paper???
}
if ($pp->prow->paperId === 0
&& $user->privChair
&& !$pp->prow->submission_round()->time_register(true)) {
Expand Down
14 changes: 13 additions & 1 deletion src/paperstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,14 @@ function clear_conflict_values($bit) {
* @return ?Contact */
private function _make_user($au, $ctype) {
$uu = $this->conf->user_by_email($au->email, USER_SLICE);
if (!$uu && $ctype >= CONFLICT_AUTHOR) {
if (!$uu
&& $ctype >= CONFLICT_AUTHOR
&& strcasecmp($au->email, $this->user->email) === 0) {
$this->user->ensure_account_here();
$uu = $this->conf->user_by_email($au->email, USER_SLICE);
}
if (!$uu
&& $ctype >= CONFLICT_AUTHOR) {
$j = $au->unparse_nea_json();
$j["disablement"] = ($this->disable_users ? Contact::DISABLEMENT_USER : 0)
| Contact::DISABLEMENT_PLACEHOLDER;
Expand Down Expand Up @@ -829,6 +836,11 @@ private function has_conflict_diff() {
}

private function _check_contacts_last($pj) {
// if creating a paper, user has account here
if ($this->user->has_email()) {
$this->user->ensure_account_here();
}

// if creating a paper, user becomes contact;
// if user removes self from author list, user becomes contact
if ($this->user->contactId > 0) {
Expand Down
48 changes: 48 additions & 0 deletions test/t_cdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,4 +698,52 @@ function test_updatecontactdb_authors() {
xassert_eqq($u->affiliation, "Nonsense University");
xassert_eqq($u->disablement, Contact::DISABLEMENT_PLACEHOLDER);
}

function test_cdb_user_new_paper() {
$u = $this->conf->fresh_cdb_user_by_email("newuser@_.com");
xassert(!$u);

$result = Dbl::qe($this->conf->contactdb(), "insert into ContactInfo set firstName='Te', lastName='Thamrongrattanarit', email='newuser@_.com', affiliation='Brandeis University', collaborators='Computational Linguistics Magazine', password=' $$2y$10$/URgqlFgQHpfE6mg4NzJhOZbg9Cc2cng58pA4cikzRD9F0qIuygnm'");
$u = $this->conf->fresh_cdb_user_by_email("newuser@_.com");
xassert(!!$u);
xassert(!$this->conf->fresh_user_by_email("newuser@_.com"));

$so = $this->conf->setting("sub_open");
$ss = $this->conf->setting("sub_sub");
$this->conf->save_setting("sub_open", 1);
$this->conf->save_refresh_setting("sub_sub", Conf::$now + 10);
$mu = Contact::$main_user;
Contact::$main_user = $u;
xassert(!$u->has_account_here());

$p = PaperInfo::make_new($u, null);
$ps = new PaperStatus($u);
$pid = $ps->save_paper_web(new Qrequest("POST", [
"title" => "A Systematic Study of Neural Discourse Models for Implicit Discourse Relation",
"has_authors" => 1,
"authors:1:name" => "Attapol T. Rutherford",
"authors:1:affiliation" => "Yelp",
"authors:1:email" => "newuser@_.com",
"authors:2:name" => "Vera Demberg",
"authors:2:affiliation" => "Saarland University",
"authors:2:email" => "[email protected]",
"authors:3:name" => "Nianwen Xue",
"authors:3:affiliation" => "Brandeis University",
"authors:3:email" => "[email protected]",
"abstract" => "Inferring implicit discourse relations in natural language text is the most difficult subtask in discourse parsing. Many neural network models have been proposed to tackle this problem."
]), $p, "update");
xassert_gt($pid, 0);
xassert($u->has_account_here());

$p1 = $this->conf->checked_paper_by_id($pid);
xassert($p1->has_author($u));
$u1 = $this->conf->fresh_user_by_email("newuser@_.com");
xassert(!$u1->is_dormant());
xassert_eqq($p1->conflict_type($u1), CONFLICT_CONTACTAUTHOR | CONFLICT_AUTHOR);
xassert(!empty($p1->conflict_type_list()));

$this->conf->save_setting("sub_open", $so);
$this->conf->save_refresh_setting("sub_sub", $ss);
Contact::$main_user = $mu;
}
}

0 comments on commit 83a30ce

Please sign in to comment.