Skip to content

Commit

Permalink
Explicit set_disable_users/set_any_content_file.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Jan 12, 2024
1 parent e085943 commit c8887b0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
9 changes: 4 additions & 5 deletions batch/savepapers.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,10 @@ function run_one($index, $j) {
fwrite(STDERR, "{$pidtext}{$titletext}: ");
}

$ps = new PaperStatus($this->user, [
"disable_users" => $this->disable_users,
"any_content_file" => $this->any_content_file
]);
$ps->on_document_import([$this, "on_document_import"]);
$ps = (new PaperStatus($this->user))
->set_disable_users($this->disable_users)
->set_any_content_file($this->any_content_file)
->on_document_import([$this, "on_document_import"]);

if ($ps->prepare_save_paper_json($j)) {
if ($this->dry_run) {
Expand Down
22 changes: 11 additions & 11 deletions src/api/api_paper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Paper_API extends MessageSet {
/** @var Contact
* @readonly */
public $user;
/** @var array<string,mixed> */
private $psargs;
/** @var bool */
private $disable_users = false;
/** @var ?ZipArchive */
private $ziparchive;
/** @var ?string */
Expand All @@ -22,11 +22,6 @@ class Paper_API extends MessageSet {
function __construct(Contact $user) {
$this->conf = $user->conf;
$this->user = $user;
$this->psargs = [
"disable_users" => false,
"add_topics" => false,
"any_content_file" => true
];
}

static function run_get(Contact $user, Qrequest $qreq, PaperInfo $prow = null) {
Expand Down Expand Up @@ -139,10 +134,13 @@ private function run_post(Qrequest $qreq, PaperInfo $prow = null) {

if ($this->user->privChair) {
if ($qreq->disable_users) {
$this->psargs["disable_users"] = true;
$this->disable_users = true;
}
if ($qreq->add_topics) {
$this->psargs["add_topics"] = true;
foreach ($this->conf->options()->form_fields() as $opt) {
if ($opt instanceof Topics_PaperOption)
$opt->allow_new_topics(true);
}
}
}

Expand Down Expand Up @@ -240,8 +238,10 @@ private function run_one_post($index, $j) {
return false;
}

$ps = new PaperStatus($this->user, $this->psargs);
$ps->on_document_import([$this, "on_document_import"]);
$ps = (new PaperStatus($this->user))
->set_disable_users($this->disable_users)
->set_any_content_file(true)
->on_document_import([$this, "on_document_import"]);
$pid = $ps->save_paper_json($j);

foreach ($ps->decorated_message_list() as $mi) {
Expand Down
18 changes: 15 additions & 3 deletions src/paperstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PaperStatus extends MessageSet {
* @readonly */
public $user;
/** @var bool */
private $disable_users;
private $disable_users = false;
/** @var bool */
private $any_content_file = false;
/** @var bool */
Expand Down Expand Up @@ -70,8 +70,6 @@ class PaperStatus extends MessageSet {
function __construct(Contact $user, $options = []) {
$this->conf = $user->conf;
$this->user = $user;
$this->disable_users = $options["disable_users"] ?? false;
$this->any_content_file = $options["any_content_file"] ?? false;
$this->allow_hash_without_content = $user->privChair;
$this->set_want_ftext(true, 5);
$this->set_ignore_duplicates(true);
Expand All @@ -84,6 +82,20 @@ static function make_prow(Contact $user, PaperInfo $prow) {
return $ps;
}

/** @param bool $x
* @return $this */
function set_disable_users($x) {
$this->disable_users = $x;
return $this;
}

/** @param bool $x
* @return $this */
function set_any_content_file($x) {
$this->any_content_file = $x;
return $this;
}

/** @param callable(object,PaperOption,PaperStatus):(?bool) $cb
* @return $this */
function on_document_import($cb) {
Expand Down
2 changes: 1 addition & 1 deletion test/t_cdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ function test_cdb_new_locally_disabled_user() {
$this->conf->refresh_options();

$p = PaperInfo::make_new($this->conf->root_user(), null);
$ps = new PaperStatus($this->conf->root_user(), ["disable_users" => true]);
$ps = (new PaperStatus($this->conf->root_user()))->set_disable_users(true);
$pid = $ps->save_paper_web(new Qrequest("POST", [
"title" => "A Systematic Sterdy of Neural Discourse Models for Implicit Discourse Relation",
"has_authors" => 1,
Expand Down

0 comments on commit c8887b0

Please sign in to comment.