[aur-dev] [PATCH 1/3] Add a quorum column to TU_VoteInfo
This allows for specifying a quorum per vote and sets a basis for
implementing automated acceptance/rejection of TU votes later.
Signed-off-by: Lukas Fleischer
There are only four valid reasons for starting a TU vote, so instead of
letting the user choose a vote length, let her pick a reason and set
vote length and quorum based on that selection.
Signed-off-by: Lukas Fleischer " . __("New proposal submitted.") . "</p>\n";
} else {
@@ -75,9 +93,13 @@ if ($atype == "Trusted User" || $atype == "Developer") {
<?= __("(empty if not applicable)") ?>
</p>
<p>
- <label for="id_length"><?= __("Length in days") ?></label>
- <input type="text" name="length" id="id_length" value="<?php if (!empty($_POST['length'])) { print htmlentities($_POST['length'], ENT_QUOTES); } ?>" />
- <?= __("(defaults to 7 if empty)") ?>
+ <label for="id_type"><?= __("Type") ?></label>
+ <select name="type" id="id_type">
+ <option value="1"><?= __("Addition of a TU") ?></option>
+ <option value="2"><?= __("Removal of a TU") ?></option>
+ <option value="3"><?= __("Removal of a TU (undeclared inactivity)") ?></option>
+ <option value="4"><?= __("Amendment of Bylaws") ?></option>
+ </select>
</p>
<p>
<label for="id_agenda"><?= __("Proposal") ?></label><br />
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index 6fe70af..9df1856 100644
--- a/web/lib/acctfuncs.inc.php
+++ b/web/lib/acctfuncs.inc.php
@@ -615,7 +615,7 @@ function open_user_proposals($user) {
*
* @return void
*/
-function add_tu_proposal($agenda, $user, $votelength, $submitteruid) {
+function add_tu_proposal($agenda, $user, $votelength, $quorum, $submitteruid) {
$dbh = DB::connect();
$q = "SELECT COUNT(*) FROM Users WHERE AccountTypeID = 2 AND ";
@@ -624,11 +624,12 @@ function add_tu_proposal($agenda, $user, $votelength, $submitteruid) {
$row = $result->fetch(PDO::FETCH_NUM);
$active_tus = $row[0];
- $q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, ";
+ $q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, Quorum, ";
$q.= "SubmitterID, ActiveTUs) VALUES ";
$q.= "(" . $dbh->quote($agenda) . ", " . $dbh->quote($user) . ", ";
$q.= "UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + " . $dbh->quote($votelength);
- $q.= ", " . $submitteruid . ", " . $active_tus . ")";
+ $q.= ", " . $dbh->quote($quorum) . ", " . $submitteruid . ", ";
+ $q.= $active_tus . ")";
$result = $dbh->exec($q);
}
--
1.8.4.rc1.383.g13e9f3f
On 04.08.2013 17:43, Lukas Fleischer wrote:
There are only four valid reasons for starting a TU vote, so instead of letting the user choose a vote length, let her pick a reason and set vote length and quorum based on that selection.
Signed-off-by: Lukas Fleischer
--- web/html/addvote.php | 46 ++++++++++++++++++++++++++++++++++------------ web/lib/acctfuncs.inc.php | 7 ++++--- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/web/html/addvote.php b/web/html/addvote.php index 43973f3..d744f2f 100644 --- a/web/html/addvote.php +++ b/web/html/addvote.php @@ -37,16 +37,34 @@ if ($atype == "Trusted User" || $atype == "Developer") { } }
- if (!empty($_POST['length'])) { - if (!is_numeric($_POST['length'])) { - $error.= __("Length must be a number.") ; - } else if ($_POST['length'] < 1) { - $error.= __("Length must be at least 1."); - } else { - $len = (60*60*24)*$_POST['length']; + if (!empty($_POST['type'])) { + switch ($_POST['type']) { + case 1: + /* Addition of a TU */ + $len = 7 * 24 * 60 * 60; + $quorum = 0.66; + break; + case 2: + /* Removal of a TU */ + $len = 7 * 24 * 60 * 60; + $quorum = 0.75; + break; + case 3: + /* Removal of a TU (undeclared inactivity) */ + $len = 5 * 24 * 60 * 60; + $quorum = 0.66; + break; + case 4: + /* Amendment of Bylaws */ + $len = 7 * 24 * 60 * 60; + $quorum = 0.75; + break; + default: + $error.= __("Invalid type.") ; + break; } } else { - $len = 60*60*24*7; + $error.= __("Invalid type.") ; }
if (empty($_POST['agenda'])) { @@ -55,7 +73,7 @@ if ($atype == "Trusted User" || $atype == "Developer") { }
if (!empty($_POST['addVote']) && empty($error)) { - add_tu_proposal($_POST['agenda'], $_POST['user'], $len, $uid); + add_tu_proposal($_POST['agenda'], $_POST['user'], $len, $quorum, $uid);
print "
" . __("New proposal submitted.") . "</p>\n"; } else { @@ -75,9 +93,13 @@ if ($atype == "Trusted User" || $atype == "Developer") { <?= __("(empty if not applicable)") ?> </p> <p> - <label for="id_length"><?= __("Length in days") ?></label> - <input type="text" name="length" id="id_length" value="<?php if (!empty($_POST['length'])) { print htmlentities($_POST['length'], ENT_QUOTES); } ?>" /> - <?= __("(defaults to 7 if empty)") ?> + <label for="id_type"><?= __("Type") ?></label> + <select name="type" id="id_type"> + <option value="1"><?= __("Addition of a TU") ?></option> + <option value="2"><?= __("Removal of a TU") ?></option> + <option value="3"><?= __("Removal of a TU (undeclared inactivity)") ?></option> + <option value="4"><?= __("Amendment of Bylaws") ?></option>
Could you change those to string values so the switch/case above is easier to read? Ymmv.
+ </select> </p> <p> <label for="id_agenda"><?= __("Proposal") ?></label><br /> diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 6fe70af..9df1856 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -615,7 +615,7 @@ function open_user_proposals($user) { * * @return void */ -function add_tu_proposal($agenda, $user, $votelength, $submitteruid) { +function add_tu_proposal($agenda, $user, $votelength, $quorum, $submitteruid) { $dbh = DB::connect();
$q = "SELECT COUNT(*) FROM Users WHERE AccountTypeID = 2 AND "; @@ -624,11 +624,12 @@ function add_tu_proposal($agenda, $user, $votelength, $submitteruid) { $row = $result->fetch(PDO::FETCH_NUM); $active_tus = $row[0];
- $q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, "; + $q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, Quorum, "; $q.= "SubmitterID, ActiveTUs) VALUES "; $q.= "(" . $dbh->quote($agenda) . ", " . $dbh->quote($user) . ", "; $q.= "UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + " . $dbh->quote($votelength); - $q.= ", " . $submitteruid . ", " . $active_tus . ")"; + $q.= ", " . $dbh->quote($quorum) . ", " . $submitteruid . ", "; + $q.= $active_tus . ")"; $result = $dbh->exec($q); }
On Sun, Aug 04, 2013 at 09:51:17PM +0200, Florian Pritz wrote:
On 04.08.2013 17:43, Lukas Fleischer wrote:
There are only four valid reasons for starting a TU vote, so instead of letting the user choose a vote length, let her pick a reason and set vote length and quorum based on that selection.
Signed-off-by: Lukas Fleischer
--- web/html/addvote.php | 46 ++++++++++++++++++++++++++++++++++------------ web/lib/acctfuncs.inc.php | 7 ++++--- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/web/html/addvote.php b/web/html/addvote.php index 43973f3..d744f2f 100644 --- a/web/html/addvote.php +++ b/web/html/addvote.php @@ -37,16 +37,34 @@ if ($atype == "Trusted User" || $atype == "Developer") { } }
- if (!empty($_POST['length'])) { - if (!is_numeric($_POST['length'])) { - $error.= __("Length must be a number.") ; - } else if ($_POST['length'] < 1) { - $error.= __("Length must be at least 1."); - } else { - $len = (60*60*24)*$_POST['length']; + if (!empty($_POST['type'])) { + switch ($_POST['type']) { + case 1: + /* Addition of a TU */ + $len = 7 * 24 * 60 * 60; + $quorum = 0.66; + break; + case 2: + /* Removal of a TU */ + $len = 7 * 24 * 60 * 60; + $quorum = 0.75; + break; + case 3: + /* Removal of a TU (undeclared inactivity) */ + $len = 5 * 24 * 60 * 60; + $quorum = 0.66; + break; + case 4: + /* Amendment of Bylaws */ + $len = 7 * 24 * 60 * 60; + $quorum = 0.75; + break; + default: + $error.= __("Invalid type.") ; + break; } } else { - $len = 60*60*24*7; + $error.= __("Invalid type.") ; }
if (empty($_POST['agenda'])) { @@ -55,7 +73,7 @@ if ($atype == "Trusted User" || $atype == "Developer") { }
if (!empty($_POST['addVote']) && empty($error)) { - add_tu_proposal($_POST['agenda'], $_POST['user'], $len, $uid); + add_tu_proposal($_POST['agenda'], $_POST['user'], $len, $quorum, $uid);
print "
" . __("New proposal submitted.") . "</p>\n"; } else { @@ -75,9 +93,13 @@ if ($atype == "Trusted User" || $atype == "Developer") { <?= __("(empty if not applicable)") ?> </p> <p> - <label for="id_length"><?= __("Length in days") ?></label> - <input type="text" name="length" id="id_length" value="<?php if (!empty($_POST['length'])) { print htmlentities($_POST['length'], ENT_QUOTES); } ?>" /> - <?= __("(defaults to 7 if empty)") ?> + <label for="id_type"><?= __("Type") ?></label> + <select name="type" id="id_type"> + <option value="1"><?= __("Addition of a TU") ?></option> + <option value="2"><?= __("Removal of a TU") ?></option> + <option value="3"><?= __("Removal of a TU (undeclared inactivity)") ?></option> + <option value="4"><?= __("Amendment of Bylaws") ?></option>
Could you change those to string values so the switch/case above is easier to read? Ymmv.
Yeah, sounds like a good idea :)
+ </select> </p> <p> <label for="id_agenda"><?= __("Proposal") ?></label><br /> diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 6fe70af..9df1856 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -615,7 +615,7 @@ function open_user_proposals($user) { * * @return void */ -function add_tu_proposal($agenda, $user, $votelength, $submitteruid) { +function add_tu_proposal($agenda, $user, $votelength, $quorum, $submitteruid) { $dbh = DB::connect();
$q = "SELECT COUNT(*) FROM Users WHERE AccountTypeID = 2 AND "; @@ -624,11 +624,12 @@ function add_tu_proposal($agenda, $user, $votelength, $submitteruid) { $row = $result->fetch(PDO::FETCH_NUM); $active_tus = $row[0];
- $q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, "; + $q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, Quorum, "; $q.= "SubmitterID, ActiveTUs) VALUES "; $q.= "(" . $dbh->quote($agenda) . ", " . $dbh->quote($user) . ", "; $q.= "UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + " . $dbh->quote($votelength); - $q.= ", " . $submitteruid . ", " . $active_tus . ")"; + $q.= ", " . $dbh->quote($quorum) . ", " . $submitteruid . ", "; + $q.= $active_tus . ")"; $result = $dbh->exec($q); }
This adds an field that indicates whether the vote was accepted or
rejected, based on the rules specified in the TU Bylaws.
Signed-off-by: Lukas Fleischer
On 04.08.2013 17:43, Lukas Fleischer wrote:
This adds an field that indicates whether the vote was accepted or rejected, based on the rules specified in the TU Bylaws.
Signed-off-by: Lukas Fleischer
--- web/template/tu_details.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/web/template/tu_details.php b/web/template/tu_details.php index 4f291f0..6ed6efd 100644 --- a/web/template/tu_details.php +++ b/web/template/tu_details.php @@ -21,6 +21,17 @@ <br /> <?= __("End") ?>: <strong><?= gmdate("Y-m-d H:i", $row['End']) ?></strong> + <?php if ($isrunning == 0): ?> + <br /> + <?= __("Result") ?>: + <?php if ($row['Quorum'] == 0): ?> + <span><?= __("unknown") ?></span> + <?php elseif (($row['Yes'] > $row['ActiveTUs'] / 2) || (($row['Yes'] + $row['No'] + $row['Abstain']) / $row['ActiveTUs'] >= $row['Quorum'] && $row['Yes'] > $row['No'])): ?>
This is rather long and probably better written this way: $yes = $row["Yes"]; $active = $row["ActiveTUs"]; $no = $row["No"]; $abstain = $row["Abstain"]; $quorum = $row["Quorum"]; $total = $yes + $no + $abstain; $vote_accepted = false; if ($yes > $active / 2) { $vote_accepted = true; } if ($total / $active >= $quorum && $yes > $no) { $vote_accepted = true; } if ($vote_accepted) { ... }
+ <span style="color: green; font-weight: bold"><?= __("Accepted") ?></span> + <?php else: ?> + <span style="color: red; font-weight: bold"><?= __("Rejected") ?></span> + <?php endif; ?> + <?php endif; ?>
Also the inner if is not indented so the endifs end up at the same level. I don't care about indentation in the resulting HTML, ymmv.
</p>
<p>
On Sun, Aug 04, 2013 at 10:00:05PM +0200, Florian Pritz wrote:
On 04.08.2013 17:43, Lukas Fleischer wrote:
This adds an field that indicates whether the vote was accepted or rejected, based on the rules specified in the TU Bylaws.
Signed-off-by: Lukas Fleischer
--- web/template/tu_details.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/web/template/tu_details.php b/web/template/tu_details.php index 4f291f0..6ed6efd 100644 --- a/web/template/tu_details.php +++ b/web/template/tu_details.php @@ -21,6 +21,17 @@ <br /> <?= __("End") ?>: <strong><?= gmdate("Y-m-d H:i", $row['End']) ?></strong> + <?php if ($isrunning == 0): ?> + <br /> + <?= __("Result") ?>: + <?php if ($row['Quorum'] == 0): ?> + <span><?= __("unknown") ?></span> + <?php elseif (($row['Yes'] > $row['ActiveTUs'] / 2) || (($row['Yes'] + $row['No'] + $row['Abstain']) / $row['ActiveTUs'] >= $row['Quorum'] && $row['Yes'] > $row['No'])): ?>
This is rather long and probably better written this way:
$yes = $row["Yes"]; $active = $row["ActiveTUs"]; $no = $row["No"]; $abstain = $row["Abstain"]; $quorum = $row["Quorum"];
$total = $yes + $no + $abstain;
$vote_accepted = false;
if ($yes > $active / 2) { $vote_accepted = true; }
if ($total / $active >= $quorum && $yes > $no) { $vote_accepted = true; }
if ($vote_accepted) { ... }
Yes, I didn't do it like this in the first place because everything else directly uses $row[] and inline computations. If we want to do it right, we refactor the current code, set $yes, $no, etc. at the beginning of the file, then add the $vote_accepted conditions in a second patch (a rebased version of this one, basically). It's a routine piece of work... I might do it tomorrow.
+ <span style="color: green; font-weight: bold"><?= __("Accepted") ?></span> + <?php else: ?> + <span style="color: red; font-weight: bold"><?= __("Rejected") ?></span> + <?php endif; ?> + <?php endif; ?>
Also the inner if is not indented so the endifs end up at the same level. I don't care about indentation in the resulting HTML, ymmv.
We do not indent these throughout the whole code base. Not changing this here since having different styles is even more questionable than not indenting. And unfortunately, I do not have the time to refactor all of them now...
</p>
<p>
participants (2)
-
Florian Pritz
-
Lukas Fleischer