Re: [aur-dev] [PATCH 1/7] Allow for setting an account's inactivity status

2013-08-05 Thread canyonknight
On Mon, Aug 5, 2013 at 4:10 AM, Lukas Fleischer
 wrote:
> This adds a field to the users table and corresponding fields to the
> account edit and display forms that allow for setting an (in-)activity
> status.
>
> This might turn out to be useful if a user is on vacation and can not
> respond to update/orphan/deletion requests. It will also be used for
> automated participation calculation later.
>
> Signed-off-by: Lukas Fleischer 
> ---
>  UPGRADING  |  9 +
>  support/schema/aur-schema.sql  |  1 +
>  web/html/account.php   |  5 +++--
>  web/lib/acctfuncs.inc.php  | 28 ++--
>  web/template/account_details.php   |  6 ++
>  web/template/account_edit_form.php |  5 +
>  6 files changed, 46 insertions(+), 8 deletions(-)
>
> diff --git a/UPGRADING b/UPGRADING
> index a04471f..d8527e3 100644
> --- a/UPGRADING
> +++ b/UPGRADING
> @@ -1,6 +1,15 @@
>  Upgrading
>  =
>
> +From 2.2.0 to 2.3.0
> +---
> +
> +1. Add an inactivity time stamp to the "Users" table:
> +
> +
> +ALTER TABLE Users ADD COLUMN InactivityTS BIGINT NOT NULL DEFAULT 0;
> +
> +
>  From 2.1.0 to 2.2.0
>  ---
>
> diff --git a/support/schema/aur-schema.sql b/support/schema/aur-schema.sql
> index 0d04f12..68db93f 100644
> --- a/support/schema/aur-schema.sql
> +++ b/support/schema/aur-schema.sql
> @@ -35,6 +35,7 @@ CREATE TABLE Users (
> LastVoted BIGINT UNSIGNED NOT NULL DEFAULT 0,
> LastLogin BIGINT UNSIGNED NOT NULL DEFAULT 0,
> LastLoginIPAddress INTEGER UNSIGNED NOT NULL DEFAULT 0,
> +   InactivityTS BIGINT UNSIGNED NOT NULL DEFAULT 0,
> PRIMARY KEY (ID),
> UNIQUE (Username),
> UNIQUE (Email),
> diff --git a/web/html/account.php b/web/html/account.php
> index 4af3043..79b5eeb 100644
> --- a/web/html/account.php
> +++ b/web/html/account.php
> @@ -52,7 +52,8 @@ if (isset($_COOKIE["AURSID"])) {
> display_account_form($atype, "UpdateAccount", 
> $row["Username"],
> $row["AccountTypeID"], 
> $row["Suspended"], $row["Email"],
> "", "", $row["RealName"], 
> $row["LangPreference"],
> -   $row["IRCNick"], $row["PGPKey"], 
> $row["ID"]);
> +   $row["IRCNick"], $row["PGPKey"],
> +   $row["InactivityTS"] ? 1 : 0, 
> $row["ID"]);
> } else {
> print __("You do not have permission to edit 
> this account.");
> }
> @@ -81,7 +82,7 @@ if (isset($_COOKIE["AURSID"])) {
> in_request("U"), in_request("T"), 
> in_request("S"),
> in_request("E"), in_request("P"), 
> in_request("C"),
> in_request("R"), in_request("L"), 
> in_request("I"),
> -   in_request("K"), in_request("ID"));
> +   in_request("K"), in_request("J"), 
> in_request("ID"));
> }
> } else {
> if ($atype == "Trusted User" || $atype == "Developer") {
> diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
> index 1deeac5..7602ec2 100644
> --- a/web/lib/acctfuncs.inc.php
> +++ b/web/lib/acctfuncs.inc.php
> @@ -54,12 +54,13 @@ function html_format_pgp_fingerprint($fingerprint) {
>   * @param string $L The language preference of the displayed user
>   * @param string $I The IRC nickname of the displayed user
>   * @param string $K The PGP key fingerprint of the displayed user
> + * @param string $J The inactivity status of the displayed user
>   * @param string $UID The user ID of the displayed user
>   *
>   * @return void
>   */
>  function display_account_form($UTYPE,$A,$U="",$T="",$S="",
> -   $E="",$P="",$C="",$R="",$L="",$I="",$K="",$UID=0) {
> +   $E="",$P="",$C="",$R="",$L="",$I="",$K="",$J="", $UID=0) {
> global $SUPPORTED_LANGS;
>
> include("account_edit_form.php");
> @@ -83,12 +84,13 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="",
>   * @param string $L The language preference of the user
>   * @param string $I The IRC nickname of the user
>   * @param string $K The PGP fingerprint of the user
> + * @param string $J The inactivity status of the user
>   * @param string $UID The user ID of the modified account
>   *
>   * @return string|void Return void if successful, otherwise return error
>   */
>  function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
> -   $P="",$C="",$R="",$L="",$I="",$K="",$UID=0) {
> +   $P="",$C="",$R="",$L="",$I="",$K="",$J="",$UID=0) {
>
> # error check and process request for a new/modified account
> global $SUPPORTED_LANGS, $A

Re: [aur-dev] [PATCH 1/2] Store active TUs for each vote

2013-08-05 Thread canyonknight
On Mon, Aug 5, 2013 at 5:43 PM, Lukas Fleischer
 wrote:
> This allows for easily keeping track of TUs that become active during a
> voting period later.
>
> Signed-off-by: Lukas Fleischer 
> ---
>  UPGRADING | 18 +-
>  support/schema/aur-schema.sql | 10 +-
>  web/lib/acctfuncs.inc.php | 23 ++-
>  3 files changed, 36 insertions(+), 15 deletions(-)
>
> diff --git a/UPGRADING b/UPGRADING
> index a300a91..740078c 100644
> --- a/UPGRADING
> +++ b/UPGRADING
> @@ -10,13 +10,21 @@ From 2.2.0 to 2.3.0
>  ALTER TABLE Users ADD COLUMN InactivityTS BIGINT NOT NULL DEFAULT 0;
>  
>
> -2. Add fields to store the number of active TUs and the quorum to the
> -   "TU_VoteInfo" table:
> +2. Add a field to store the quorum to the "TU_VoteInfo" table:
>
>  
> -ALTER TABLE TU_VoteInfo
> -   ADD COLUMN ActiveTUs tinyint(3) unsigned NOT NULL default '0',
> -   ADD COLUMN Quorum decimal(2, 2) unsigned NOT NULL;

I see this patch is based against "[PATCH 2/3] Store the number of
active TUs when starting a vote". Are you going to drop that patch
since this patch looks to supersede it?

> +ALTER TABLE TU_VoteInfo ADD COLUMN Quorum decimal(2, 2) unsigned NOT NULL;
> +
> +
> +3. Create the "TU_VoteActive" table:
> +
> +
> +CREATE TABLE IF NOT EXISTS TU_VoteActive (
> +  VoteID int(10) unsigned NOT NULL,
> +  UserID int(10) unsigned NOT NULL,
> +  FOREIGN KEY (VoteID) REFERENCES TU_VoteInfo(ID) ON DELETE CASCADE,
> +  FOREIGN KEY (UserID) REFERENCES Users(ID) ON DELETE CASCADE
> +) ENGINE = InnoDB;
>  
>
>  From 2.1.0 to 2.2.0
> diff --git a/support/schema/aur-schema.sql b/support/schema/aur-schema.sql
> index 59da3aa..6efe91c 100644
> --- a/support/schema/aur-schema.sql
> +++ b/support/schema/aur-schema.sql
> @@ -203,11 +203,19 @@ CREATE TABLE IF NOT EXISTS TU_VoteInfo (
>Yes tinyint(3) unsigned NOT NULL default '0',
>No tinyint(3) unsigned NOT NULL default '0',
>Abstain tinyint(3) unsigned NOT NULL default '0',
> -  ActiveTUs tinyint(3) unsigned NOT NULL default '0',
>PRIMARY KEY  (ID),
>FOREIGN KEY (SubmitterID) REFERENCES Users(ID) ON DELETE CASCADE
>  ) ENGINE = InnoDB;
>
> +-- TUs being active during a specific voting period
> +--
> +CREATE TABLE IF NOT EXISTS TU_VoteActive (
> +  VoteID int(10) unsigned NOT NULL,
> +  UserID int(10) unsigned NOT NULL,
> +  FOREIGN KEY (VoteID) REFERENCES TU_VoteInfo(ID) ON DELETE CASCADE,
> +  FOREIGN KEY (UserID) REFERENCES Users(ID) ON DELETE CASCADE
> +) ENGINE = InnoDB;
> +
>  -- Individual vote records
>  --
>  CREATE TABLE IF NOT EXISTS TU_Votes (
> diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
> index 9df1856..3f7b595 100644
> --- a/web/lib/acctfuncs.inc.php
> +++ b/web/lib/acctfuncs.inc.php
> @@ -618,19 +618,18 @@ function open_user_proposals($user) {
>  function add_tu_proposal($agenda, $user, $votelength, $quorum, 
> $submitteruid) {
> $dbh = DB::connect();
>
> -   $q = "SELECT COUNT(*) FROM Users WHERE AccountTypeID = 2 AND ";
> -   $q.= "InactivityTS = 0";
> -   $result = $dbh->query($q);
> -   $row = $result->fetch(PDO::FETCH_NUM);
> -   $active_tus = $row[0];
> -
> $q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, Quorum, 
> ";
> -   $q.= "SubmitterID, ActiveTUs) VALUES ";
> +   $q.= "SubmitterID) VALUES ";
> $q.= "(" . $dbh->quote($agenda) . ", " . $dbh->quote($user) . ", ";
> $q.= "UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + " . 
> $dbh->quote($votelength);
> -   $q.= ", " . $dbh->quote($quorum) . ", " . $submitteruid . ", ";
> -   $q.= $active_tus . ")";
> +   $q.= ", " . $dbh->quote($quorum) . ", " . $submitteruid . ")";
> $result = $dbh->exec($q);
> +   $vote_id = last_insert_id();
> +
> +   $q = "INSERT INTO TU_VoteActive (VoteID, UserID) SELECT ";
> +   $q.= $vote_id . " AS VoteID, ID AS UserID FROM Users WHERE ";
> +   $q.= "AccountTypeID = 2 AND InactivityTS = 0";
> +   $dbh->exec($q);
>  }
>
>  /**
> @@ -1026,6 +1025,12 @@ function vote_details($voteid) {
> $result = $dbh->query($q);
> $row = $result->fetch(PDO::FETCH_ASSOC);
>
> +   $q = "SELECT COUNT(*) FROM TU_VoteActive WHERE VoteID = ";
> +   $q.= intval($voteid);
> +   $result = $dbh->query($q);
> +   $row_ = $result->fetch(PDO::FETCH_NUM);
> +   $row['ActiveTUs'] = $row_[0];

To avoid dealing with the array like above, could we do this?:

$row['ActiveTUs'] = $result->fetchColumn();

> +
> return $row;
>  }
>
> --
> 1.8.4.rc1.383.g13e9f3f
>


[aur-dev] [PATCH 2/2] Update vote participation if a TU becomes active

2013-08-05 Thread Lukas Fleischer
Instead of computing vote participation at the beginning of a vote only,
update the number of active TUs whenever a TU becomes active during the
voting period.

A TU is considered active (with regard to a specific vote) if there
exists a point in time during the voting period when he is active.

Signed-off-by: Lukas Fleischer 
---
 web/lib/acctfuncs.inc.php | 17 +
 1 file changed, 17 insertions(+)

diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index 3f7b595..3a4ff51 100644
--- a/web/lib/acctfuncs.inc.php
+++ b/web/lib/acctfuncs.inc.php
@@ -287,6 +287,23 @@ function 
process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
print __("The account, %s%s%s, has been 
successfully modified.",
"", 
htmlspecialchars($U,ENT_QUOTES), "");
}
+
+   if ($T == 2 && $inactivity_ts == 0) {
+   /*
+* A (new) TU became active -- add him to the
+* active TU list for all running votes.
+*/
+   $q = "INSERT INTO TU_VoteActive (UserID, ";
+   $q.= "VoteID) SELECT " . intval($UID) . " ";
+   $q.= "AS UserID, ID AS VoteID FROM ";
+   $q.= "TU_VoteInfo WHERE End >= ";
+   $q.= "UNIX_TIMESTAMP() AND NOT EXISTS (";
+   $q.= "SELECT * FROM TU_VoteActive WHERE ";
+   $q.= "TU_VoteActive.UserID = " . intval($UID);
+   $q.= " AND TU_VoteActive.VoteID = ";
+   $q.= "TU_VoteInfo.ID)";
+   $dbh->exec($q);
+   }
}
}
return;
-- 
1.8.4.rc1.383.g13e9f3f



[aur-dev] [PATCH 1/2] Store active TUs for each vote

2013-08-05 Thread Lukas Fleischer
This allows for easily keeping track of TUs that become active during a
voting period later.

Signed-off-by: Lukas Fleischer 
---
 UPGRADING | 18 +-
 support/schema/aur-schema.sql | 10 +-
 web/lib/acctfuncs.inc.php | 23 ++-
 3 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/UPGRADING b/UPGRADING
index a300a91..740078c 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -10,13 +10,21 @@ From 2.2.0 to 2.3.0
 ALTER TABLE Users ADD COLUMN InactivityTS BIGINT NOT NULL DEFAULT 0;
 
 
-2. Add fields to store the number of active TUs and the quorum to the
-   "TU_VoteInfo" table:
+2. Add a field to store the quorum to the "TU_VoteInfo" table:
 
 
-ALTER TABLE TU_VoteInfo
-   ADD COLUMN ActiveTUs tinyint(3) unsigned NOT NULL default '0',
-   ADD COLUMN Quorum decimal(2, 2) unsigned NOT NULL;
+ALTER TABLE TU_VoteInfo ADD COLUMN Quorum decimal(2, 2) unsigned NOT NULL;
+
+
+3. Create the "TU_VoteActive" table:
+
+
+CREATE TABLE IF NOT EXISTS TU_VoteActive (
+  VoteID int(10) unsigned NOT NULL,
+  UserID int(10) unsigned NOT NULL,
+  FOREIGN KEY (VoteID) REFERENCES TU_VoteInfo(ID) ON DELETE CASCADE,
+  FOREIGN KEY (UserID) REFERENCES Users(ID) ON DELETE CASCADE
+) ENGINE = InnoDB;
 
 
 From 2.1.0 to 2.2.0
diff --git a/support/schema/aur-schema.sql b/support/schema/aur-schema.sql
index 59da3aa..6efe91c 100644
--- a/support/schema/aur-schema.sql
+++ b/support/schema/aur-schema.sql
@@ -203,11 +203,19 @@ CREATE TABLE IF NOT EXISTS TU_VoteInfo (
   Yes tinyint(3) unsigned NOT NULL default '0',
   No tinyint(3) unsigned NOT NULL default '0',
   Abstain tinyint(3) unsigned NOT NULL default '0',
-  ActiveTUs tinyint(3) unsigned NOT NULL default '0',
   PRIMARY KEY  (ID),
   FOREIGN KEY (SubmitterID) REFERENCES Users(ID) ON DELETE CASCADE
 ) ENGINE = InnoDB;
 
+-- TUs being active during a specific voting period
+--
+CREATE TABLE IF NOT EXISTS TU_VoteActive (
+  VoteID int(10) unsigned NOT NULL,
+  UserID int(10) unsigned NOT NULL,
+  FOREIGN KEY (VoteID) REFERENCES TU_VoteInfo(ID) ON DELETE CASCADE,
+  FOREIGN KEY (UserID) REFERENCES Users(ID) ON DELETE CASCADE
+) ENGINE = InnoDB;
+
 -- Individual vote records
 --
 CREATE TABLE IF NOT EXISTS TU_Votes (
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index 9df1856..3f7b595 100644
--- a/web/lib/acctfuncs.inc.php
+++ b/web/lib/acctfuncs.inc.php
@@ -618,19 +618,18 @@ function open_user_proposals($user) {
 function add_tu_proposal($agenda, $user, $votelength, $quorum, $submitteruid) {
$dbh = DB::connect();
 
-   $q = "SELECT COUNT(*) FROM Users WHERE AccountTypeID = 2 AND ";
-   $q.= "InactivityTS = 0";
-   $result = $dbh->query($q);
-   $row = $result->fetch(PDO::FETCH_NUM);
-   $active_tus = $row[0];
-
$q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, Quorum, ";
-   $q.= "SubmitterID, ActiveTUs) VALUES ";
+   $q.= "SubmitterID) VALUES ";
$q.= "(" . $dbh->quote($agenda) . ", " . $dbh->quote($user) . ", ";
$q.= "UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + " . $dbh->quote($votelength);
-   $q.= ", " . $dbh->quote($quorum) . ", " . $submitteruid . ", ";
-   $q.= $active_tus . ")";
+   $q.= ", " . $dbh->quote($quorum) . ", " . $submitteruid . ")";
$result = $dbh->exec($q);
+   $vote_id = last_insert_id();
+
+   $q = "INSERT INTO TU_VoteActive (VoteID, UserID) SELECT ";
+   $q.= $vote_id . " AS VoteID, ID AS UserID FROM Users WHERE ";
+   $q.= "AccountTypeID = 2 AND InactivityTS = 0";
+   $dbh->exec($q);
 }
 
 /**
@@ -1026,6 +1025,12 @@ function vote_details($voteid) {
$result = $dbh->query($q);
$row = $result->fetch(PDO::FETCH_ASSOC);
 
+   $q = "SELECT COUNT(*) FROM TU_VoteActive WHERE VoteID = ";
+   $q.= intval($voteid);
+   $result = $dbh->query($q);
+   $row_ = $result->fetch(PDO::FETCH_NUM);
+   $row['ActiveTUs'] = $row_[0];
+
return $row;
 }
 
-- 
1.8.4.rc1.383.g13e9f3f



[aur-dev] [PATCH 0/7] Display vote results on the Proposal Details page

2013-08-05 Thread Lukas Fleischer
This is a resubmission of the two patch series I submitted yesterday
with Florian's suggestions incorporated. Further comments welcome.

Lukas Fleischer (7):
  Allow for setting an account's inactivity status
  Store the number of active TUs when starting a vote
  Show participation in vote details
  Add a quorum column to TU_VoteInfo
  Add a vote type to the TU proposal form
  tu_details.php: Avoid inline computations
  tu_details.php: Display vote result

 UPGRADING  | 18 +++
 support/schema/aur-schema.sql  |  3 +++
 web/html/account.php   |  5 +++--
 web/html/addvote.php   | 46 --
 web/lib/acctfuncs.inc.php  | 42 ++
 web/template/account_details.php   |  6 +
 web/template/account_edit_form.php |  5 +
 web/template/tu_details.php| 43 +++
 8 files changed, 141 insertions(+), 27 deletions(-)

-- 
1.8.4.rc1.383.g13e9f3f



[aur-dev] [PATCH 5/7] Add a vote type to the TU proposal form

2013-08-05 Thread 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 
---
 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..3ce99c0 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 "add_tu":
+   /* Addition of a TU */
+   $len = 7 * 24 * 60 * 60;
+   $quorum = 0.66;
+   break;
+   case "remove_tu":
+   /* Removal of a TU */
+   $len = 7 * 24 * 60 * 60;
+   $quorum = 0.75;
+   break;
+   case "remove_inactive_tu":
+   /* Removal of a TU (undeclared inactivity) */
+   $len = 5 * 24 * 60 * 60;
+   $quorum = 0.66;
+   break;
+   case "bylaws":
+   /* 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.") 
. "\n";
} else {
@@ -75,9 +93,13 @@ if ($atype == "Trusted User" || $atype == "Developer") {



-   
-   
-   
+   
+   
+   
+   
+   
+   
+   



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



[aur-dev] [PATCH 3/7] Show participation in vote details

2013-08-05 Thread Lukas Fleischer
This is calculated by dividing the sum of all votes by the number of
active TUs (where the number of active TUs is measured when the vote
starts).

Signed-off-by: Lukas Fleischer 
---
 web/template/tu_details.php | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/web/template/tu_details.php b/web/template/tu_details.php
index be816ce..4f291f0 100644
--- a/web/template/tu_details.php
+++ b/web/template/tu_details.php
@@ -34,6 +34,7 @@



+   



@@ -47,6 +48,11 @@



+0): ?>
+   %
+   
+   
+   


 
-- 
1.8.4.rc1.383.g13e9f3f



[aur-dev] [PATCH 4/7] Add a quorum column to TU_VoteInfo

2013-08-05 Thread Lukas Fleischer
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 
---
 UPGRADING | 6 --
 support/schema/aur-schema.sql | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/UPGRADING b/UPGRADING
index 307ed8d..a300a91 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -10,11 +10,13 @@ From 2.2.0 to 2.3.0
 ALTER TABLE Users ADD COLUMN InactivityTS BIGINT NOT NULL DEFAULT 0;
 
 
-2. Add a field to store the number of active TUs to the "TU_VoteInfo" table:
+2. Add fields to store the number of active TUs and the quorum to the
+   "TU_VoteInfo" table:
 
 
 ALTER TABLE TU_VoteInfo
-   ADD COLUMN ActiveTUs tinyint(3) unsigned NOT NULL default '0';
+   ADD COLUMN ActiveTUs tinyint(3) unsigned NOT NULL default '0',
+   ADD COLUMN Quorum decimal(2, 2) unsigned NOT NULL;
 
 
 From 2.1.0 to 2.2.0
diff --git a/support/schema/aur-schema.sql b/support/schema/aur-schema.sql
index 51f9601..59da3aa 100644
--- a/support/schema/aur-schema.sql
+++ b/support/schema/aur-schema.sql
@@ -198,6 +198,7 @@ CREATE TABLE IF NOT EXISTS TU_VoteInfo (
   User VARCHAR(32) NOT NULL,
   Submitted bigint(20) unsigned NOT NULL,
   End bigint(20) unsigned NOT NULL,
+  Quorum decimal(2, 2) unsigned NOT NULL,
   SubmitterID int(10) unsigned NOT NULL,
   Yes tinyint(3) unsigned NOT NULL default '0',
   No tinyint(3) unsigned NOT NULL default '0',
-- 
1.8.4.rc1.383.g13e9f3f



[aur-dev] [PATCH 7/7] tu_details.php: Display vote result

2013-08-05 Thread Lukas Fleischer
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 | 20 
 1 file changed, 20 insertions(+)

diff --git a/web/template/tu_details.php b/web/template/tu_details.php
index 61abab7..c09e30c 100644
--- a/web/template/tu_details.php
+++ b/web/template/tu_details.php
@@ -3,9 +3,18 @@ $yes = $row["Yes"];
 $no = $row["No"];
 $abstain = $row["Abstain"];
 $active_tus = $row["ActiveTUs"];
+$quorum = $row["Quorum"];
 
 $total = $yes + $no + $abstain;
 $participation = $total / $active_tus;
+
+if ($yes > $active_tus / 2) {
+   $vote_accepted = true;
+} elseif ($participation > $quorum && $yes > $no) {
+   $vote_accepted = true;
+} else {
+   $vote_accepted = false;
+}
 ?>
 

@@ -30,6 +39,17 @@ $participation = $total / $active_tus;

:

+   
+   
+   :
+   
+   
+   
+   
+   
+   
+   
+   

 

-- 
1.8.4.rc1.383.g13e9f3f



[aur-dev] [PATCH 1/7] Allow for setting an account's inactivity status

2013-08-05 Thread Lukas Fleischer
This adds a field to the users table and corresponding fields to the
account edit and display forms that allow for setting an (in-)activity
status.

This might turn out to be useful if a user is on vacation and can not
respond to update/orphan/deletion requests. It will also be used for
automated participation calculation later.

Signed-off-by: Lukas Fleischer 
---
 UPGRADING  |  9 +
 support/schema/aur-schema.sql  |  1 +
 web/html/account.php   |  5 +++--
 web/lib/acctfuncs.inc.php  | 28 ++--
 web/template/account_details.php   |  6 ++
 web/template/account_edit_form.php |  5 +
 6 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/UPGRADING b/UPGRADING
index a04471f..d8527e3 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -1,6 +1,15 @@
 Upgrading
 =
 
+From 2.2.0 to 2.3.0
+---
+
+1. Add an inactivity time stamp to the "Users" table:
+
+
+ALTER TABLE Users ADD COLUMN InactivityTS BIGINT NOT NULL DEFAULT 0;
+
+
 From 2.1.0 to 2.2.0
 ---
 
diff --git a/support/schema/aur-schema.sql b/support/schema/aur-schema.sql
index 0d04f12..68db93f 100644
--- a/support/schema/aur-schema.sql
+++ b/support/schema/aur-schema.sql
@@ -35,6 +35,7 @@ CREATE TABLE Users (
LastVoted BIGINT UNSIGNED NOT NULL DEFAULT 0,
LastLogin BIGINT UNSIGNED NOT NULL DEFAULT 0,
LastLoginIPAddress INTEGER UNSIGNED NOT NULL DEFAULT 0,
+   InactivityTS BIGINT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (ID),
UNIQUE (Username),
UNIQUE (Email),
diff --git a/web/html/account.php b/web/html/account.php
index 4af3043..79b5eeb 100644
--- a/web/html/account.php
+++ b/web/html/account.php
@@ -52,7 +52,8 @@ if (isset($_COOKIE["AURSID"])) {
display_account_form($atype, "UpdateAccount", 
$row["Username"],
$row["AccountTypeID"], 
$row["Suspended"], $row["Email"],
"", "", $row["RealName"], 
$row["LangPreference"],
-   $row["IRCNick"], $row["PGPKey"], 
$row["ID"]);
+   $row["IRCNick"], $row["PGPKey"],
+   $row["InactivityTS"] ? 1 : 0, 
$row["ID"]);
} else {
print __("You do not have permission to edit 
this account.");
}
@@ -81,7 +82,7 @@ if (isset($_COOKIE["AURSID"])) {
in_request("U"), in_request("T"), 
in_request("S"),
in_request("E"), in_request("P"), 
in_request("C"),
in_request("R"), in_request("L"), 
in_request("I"),
-   in_request("K"), in_request("ID"));
+   in_request("K"), in_request("J"), 
in_request("ID"));
}
} else {
if ($atype == "Trusted User" || $atype == "Developer") {
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index 1deeac5..7602ec2 100644
--- a/web/lib/acctfuncs.inc.php
+++ b/web/lib/acctfuncs.inc.php
@@ -54,12 +54,13 @@ function html_format_pgp_fingerprint($fingerprint) {
  * @param string $L The language preference of the displayed user
  * @param string $I The IRC nickname of the displayed user
  * @param string $K The PGP key fingerprint of the displayed user
+ * @param string $J The inactivity status of the displayed user
  * @param string $UID The user ID of the displayed user
  *
  * @return void
  */
 function display_account_form($UTYPE,$A,$U="",$T="",$S="",
-   $E="",$P="",$C="",$R="",$L="",$I="",$K="",$UID=0) {
+   $E="",$P="",$C="",$R="",$L="",$I="",$K="",$J="", $UID=0) {
global $SUPPORTED_LANGS;
 
include("account_edit_form.php");
@@ -83,12 +84,13 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="",
  * @param string $L The language preference of the user
  * @param string $I The IRC nickname of the user
  * @param string $K The PGP fingerprint of the user
+ * @param string $J The inactivity status of the user
  * @param string $UID The user ID of the modified account
  *
  * @return string|void Return void if successful, otherwise return error
  */
 function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
-   $P="",$C="",$R="",$L="",$I="",$K="",$UID=0) {
+   $P="",$C="",$R="",$L="",$I="",$K="",$J="",$UID=0) {
 
# error check and process request for a new/modified account
global $SUPPORTED_LANGS, $AUR_LOCATION;
@@ -185,7 +187,7 @@ function 
process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
if ($error) {
print "".$error."\n";
display_account_form($UTYPE, $A, $U, $T, $S, $E, "", "",
-   $R, $L, $

[aur-dev] [PATCH 6/7] tu_details.php: Avoid inline computations

2013-08-05 Thread Lukas Fleischer
Compute the total number of votes and the participation at the beginning
of the template instead of doing it inside the template itself.

Signed-off-by: Lukas Fleischer 
---
 web/template/tu_details.php | 21 +++--
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/web/template/tu_details.php b/web/template/tu_details.php
index 4f291f0..61abab7 100644
--- a/web/template/tu_details.php
+++ b/web/template/tu_details.php
@@ -1,3 +1,12 @@
+
 

 
@@ -37,10 +46,10 @@



-   
-   
-   
-   
+   
+   
+   
+   



@@ -48,8 +57,8 @@



-0): ?>
-   %
+0): ?>
+   %



-- 
1.8.4.rc1.383.g13e9f3f



[aur-dev] [PATCH 2/7] Store the number of active TUs when starting a vote

2013-08-05 Thread Lukas Fleischer
This will be used for automated calculation of vote participation later.

Signed-off-by: Lukas Fleischer 
---
 UPGRADING |  7 +++
 support/schema/aur-schema.sql |  1 +
 web/lib/acctfuncs.inc.php | 11 +--
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/UPGRADING b/UPGRADING
index d8527e3..307ed8d 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -10,6 +10,13 @@ From 2.2.0 to 2.3.0
 ALTER TABLE Users ADD COLUMN InactivityTS BIGINT NOT NULL DEFAULT 0;
 
 
+2. Add a field to store the number of active TUs to the "TU_VoteInfo" table:
+
+
+ALTER TABLE TU_VoteInfo
+   ADD COLUMN ActiveTUs tinyint(3) unsigned NOT NULL default '0';
+
+
 From 2.1.0 to 2.2.0
 ---
 
diff --git a/support/schema/aur-schema.sql b/support/schema/aur-schema.sql
index 68db93f..51f9601 100644
--- a/support/schema/aur-schema.sql
+++ b/support/schema/aur-schema.sql
@@ -202,6 +202,7 @@ CREATE TABLE IF NOT EXISTS TU_VoteInfo (
   Yes tinyint(3) unsigned NOT NULL default '0',
   No tinyint(3) unsigned NOT NULL default '0',
   Abstain tinyint(3) unsigned NOT NULL default '0',
+  ActiveTUs tinyint(3) unsigned NOT NULL default '0',
   PRIMARY KEY  (ID),
   FOREIGN KEY (SubmitterID) REFERENCES Users(ID) ON DELETE CASCADE
 ) ENGINE = InnoDB;
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index 7602ec2..6fe70af 100644
--- a/web/lib/acctfuncs.inc.php
+++ b/web/lib/acctfuncs.inc.php
@@ -618,10 +618,17 @@ function open_user_proposals($user) {
 function add_tu_proposal($agenda, $user, $votelength, $submitteruid) {
$dbh = DB::connect();
 
-   $q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, 
SubmitterID) VALUES ";
+   $q = "SELECT COUNT(*) FROM Users WHERE AccountTypeID = 2 AND ";
+   $q.= "InactivityTS = 0";
+   $result = $dbh->query($q);
+   $row = $result->fetch(PDO::FETCH_NUM);
+   $active_tus = $row[0];
+
+   $q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, ";
+   $q.= "SubmitterID, ActiveTUs) VALUES ";
$q.= "(" . $dbh->quote($agenda) . ", " . $dbh->quote($user) . ", ";
$q.= "UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + " . $dbh->quote($votelength);
-   $q.= ", " . $submitteruid . ")";
+   $q.= ", " . $submitteruid . ", " . $active_tus . ")";
$result = $dbh->exec($q);
 }
 
-- 
1.8.4.rc1.383.g13e9f3f