Skip to content

Commit

Permalink
Sfnetadmin commands
Browse files Browse the repository at this point in the history
Allow sf.net project admins to issue '_' commands which set
tag_clouts to 0 for projects they administer.  Also fix a
very minor unrelated score-recalc bug.
  • Loading branch information
jamiemccarthy committed Sep 25, 2008
1 parent e000296 commit e4392b2
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 6 deletions.
75 changes: 70 additions & 5 deletions plugins/Tags/Tags.pm
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ sub createTag {
# a tag_clout in tagname_params.
my $admincmds_ar = $self->getTagnameAdmincmds(
$tag->{tagnameid}, $tag->{globjid});
# XXX Also, if the tag is on a project, check
# getTagnameSfnetadmincmds();
# Any negative admin command means clout must be set to 0.
if (grep { $_->{cmdtype} =~ /^[_#]/ } @$admincmds_ar) {
my $count = $self->sqlInsert('tag_params', {
Expand Down Expand Up @@ -908,6 +910,17 @@ sub getTagnameAdmincmds {
$where_clause);
}

sub getTagnameSfnetadmincmds {
my($self, $tagnameid, $globjid) = @_;
return [ ] if !$tagnameid || !$globjid;
my $where_clause = "tagnameid=$tagnameid AND globjid=$globjid";
return $self->sqlSelectAllHashrefArray(
"tagnameid, globjid, cmdtype, created_at,
UNIX_TIMESTAMP(created_at) AS created_at_ut",
'tagcommand_adminlog_sfnet',
$where_clause);
}

sub getExampleTagsForStory {
my($self, $story) = @_;
my $slashdb = getCurrentDB();
Expand Down Expand Up @@ -961,7 +974,7 @@ sub adminPseudotagnameSyntaxOK {
sub sfnetadminPseudotagnameSyntaxOK {
my($self, $command) = @_;
my($type, $tagname) = $self->getTypeAndTagnameFromAdminCommand($command);
return 0 if !$type || $type ne '_'; # only command sfnetadmins get is '_'
return 0 if !$type || $type ne '_'; # only command sfnetadmins get is '_', for now
return $self->tagnameSyntaxOK($tagname);
}

Expand Down Expand Up @@ -1592,9 +1605,6 @@ sub processAdminCommand {

my $new_user_clout = 1-$user_clout_reduction;

my %uid_changed = ( );
my %globjid_changed = ( );

if ($type eq '*') {
# Asterisk means admin is saying this tagname is "OK",
# which (at least so far, 2007/12) means it is not
Expand Down Expand Up @@ -1675,7 +1685,7 @@ sub processAdminCommand {
my $tagboxes = $tagboxdb->getTagboxes();
for my $tagbox_hr (@$tagboxes) {
my $field = $tagbox_hr->{affected_type} . 'id';
$tagbox_hr->{object}->forceFeederRecalc($tagbox_hr->{$field});
$tagbox_hr->{object}->forceFeederRecalc($globjid);
}

return $tagnameid;
Expand Down Expand Up @@ -1709,8 +1719,50 @@ sub getAdminCommandMaxClout {
return $max_clout;
}

sub processSfnetadminCommand {
my($self, $c, $id, $table) = @_;

return 0 if $table ne 'projects';

my($type, $tagname) = $self->getTypeAndTagnameFromAdminCommand($c);
return 0 if !$type || $type ne '_';

my $user = getCurrentUser();
return 0 if ! $self->sfuserIsAdminOnProject($user->{uid}, $id);

my $constants = getCurrentStatic();
my $tagnameid = $self->getTagnameidCreate($tagname);

my $globjid = $self->getGlobjidCreate($table, $id);

my $tags_ar = $self->getTagsByNameAndIdArrayref($table, $id, { include_private => 1 });
my @tags = grep { $_->{tagnameid} == $tagnameid } @$tags_ar;
for my $tag (@tags) {
$self->setTag($tag->{tagid}, { tag_clout => 0 });
}
$self->logSfnetadminCommand($type, $tagname, $globjid);
my $tagboxes = $tagboxdb->getTagboxes();
for my $tagbox_hr (@$tagboxes) {
my $field = $tagbox_hr->{affected_type} . 'id';
$tagbox_hr->{object}->forceFeederRecalc($globjid);
}
}

} # closure

sub sfuserIsAdminOnProject {
my($self, $uid, $project_id) = @_;

# XXX For now, my belief is that only sf.net project admins
# will be allowed to submit _ commands, and only on their
# own projects, so any such commands by definition will be
# authorized. There's no great way to fill in the logic of
# this method at the moment, but in the future we may need
# to find a way. - Jamie 2008-09-25

return 1;
}

sub getTypeAndTagnameFromAdminCommand {
my($self, $c) = @_;
my($type, $tagname) = $c =~ /^(\^|\*|\)|\$?\_|\$?\#{1,5})(.+)$/;
Expand All @@ -1734,6 +1786,19 @@ sub logAdminCommand {
});
}

sub logSfnetadminCommand {
my($self, $type, $tagname, $globjid) = @_;
return 0 if !$globjid;
my $tagnameid = $self->getTagnameidFromNameIfExists($tagname);
$self->sqlInsert('tagcommand_adminlog_sfnet', {
cmdtype => $type,
tagnameid => $tagnameid,
globjid => $globjid || undef,
sfnetadminuid => getCurrentUser('uid'),
-created_at => 'NOW()',
});
}

sub getAdminCommandCountAffectingUID {
my($self, $uid) = @_;
my $cmdtype_ar = $self->sqlSelectColArrayref(
Expand Down
13 changes: 13 additions & 0 deletions plugins/Tags/mysql_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ CREATE TABLE tagcommand_adminlog (
KEY tagnameid_globjid (tagnameid, globjid)
) TYPE=InnoDB;

DROP TABLE IF EXISTS tagcommand_adminlog_sfnet;
CREATE TABLE tagcommand_adminlog_sfnet (
id int UNSIGNED NOT NULL AUTO_INCREMENT,
cmdtype VARCHAR(6) NOT NULL,
tagnameid int UNSIGNED NOT NULL,
globjid int UNSIGNED DEFAULT NULL,
sfnetadminuid mediumint UNSIGNED NOT NULL,
created_at datetime NOT NULL,
PRIMARY KEY id (id),
KEY created_at (created_at),
KEY tagnameid_globjid (tagnameid, globjid)
) TYPE=InnoDB;

ALTER TABLE users_info ADD COLUMN tag_clout FLOAT UNSIGNED NOT NULL DEFAULT 1.0 AFTER created_at;

CREATE TABLE tagboxes (
Expand Down
16 changes: 15 additions & 1 deletion sql/mysql/upgrades
Original file line number Diff line number Diff line change
Expand Up @@ -5539,6 +5539,20 @@ UPDATE vars SET value = 'T_2_5_0_221' WHERE name = 'cvs_tag_currentcode';

INSERT INTO vars (name, value, description) VALUES ('index_new_user_beta', '0', 'Use index beta for new users?');

# For plugins/FireHose
# for plugins/FireHose
INSERT INTO vars (name, value, description) VALUES ('firehose_memcached_disp_exptime', '180', 'Seconds to cache firehose display');

# for plugins/Tags
DROP TABLE IF EXISTS tagcommand_adminlog_sfnet;
CREATE TABLE tagcommand_adminlog_sfnet (
id int UNSIGNED NOT NULL AUTO_INCREMENT,
cmdtype VARCHAR(6) NOT NULL,
tagnameid int UNSIGNED NOT NULL,
globjid int UNSIGNED DEFAULT NULL,
sfnetadminuid mediumint UNSIGNED NOT NULL,
created_at datetime NOT NULL,
PRIMARY KEY id (id),
KEY created_at (created_at),
KEY tagnameid_globjid (tagnameid, globjid)
) TYPE=InnoDB;

0 comments on commit e4392b2

Please sign in to comment.