[vhffs-dev] [1198] Start implementing tag requests (task #239).

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1198
Author:   beuss
Date:     2008-05-21 23:46:32 +0200 (Wed, 21 May 2008)

Log Message:
-----------
Start implementing tag requests (task #239).

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Makefile.am
    trunk/vhffs-api/src/Vhffs/Panel/Admin.pm
    trunk/vhffs-api/src/Vhffs/Tag.pm
    trunk/vhffs-backend/src/pgsql/initdb.sql.in
    trunk/vhffs-panel/Makefile.am
    trunk/vhffs-panel/group/prefs.pl
    trunk/vhffs-panel/templates/Makefile.am
    trunk/vhffs-panel/templates/group/tags.tmpl

Added Paths:
-----------
    trunk/vhffs-api/src/Vhffs/Tag/Request.pm
    trunk/vhffs-panel/admin/tag/request/
    trunk/vhffs-panel/templates/admin/tag/request/


Modified: trunk/vhffs-api/src/Vhffs/Makefile.am
===================================================================
--- trunk/vhffs-api/src/Vhffs/Makefile.am	2008-05-19 11:47:34 UTC (rev 1197)
+++ trunk/vhffs-api/src/Vhffs/Makefile.am	2008-05-21 21:46:32 UTC (rev 1198)
@@ -64,7 +64,8 @@
 	Services/Svn.pm \
 	Services/Git.pm \
 	Services/Cron.pm \
-	Tag/Category.pm
+	Tag/Category.pm \
+	Tag/Request.pm
 
 # Define the substitution we need to point perl script at correct location
 do_sed = $(SED) --in-place \

Modified: trunk/vhffs-api/src/Vhffs/Panel/Admin.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Admin.pm	2008-05-19 11:47:34 UTC (rev 1197)
+++ trunk/vhffs-api/src/Vhffs/Panel/Admin.pm	2008-05-21 21:46:32 UTC (rev 1198)
@@ -151,7 +151,7 @@
 		{ LINK => '/admin/tag/list.pl',	LABEL => gettext( 'Manage existing tags' )},
 		{ LINK => '/admin/tag/category/create.pl',	LABEL => gettext( 'Create new category' )},
 		{ LINK => '/admin/tag/category/list.pl',	LABEL => gettext( 'Manage existing categories' )},
-		{ LINK => '/admin/tag/request.pl',			LABEL => gettext('Manage requests')}
+		{ LINK => '/admin/tag/request/list.pl',			LABEL => gettext('Manage requests')}
 	];
 	return { CATNAME => gettext( 'Tags Admin'),		ITEMS => $items, CATTYPE => 'tags' };
 }

Added: trunk/vhffs-api/src/Vhffs/Tag/Request.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Tag/Request.pm	                        (rev 0)
+++ trunk/vhffs-api/src/Vhffs/Tag/Request.pm	2008-05-21 21:46:32 UTC (rev 1198)
@@ -0,0 +1,131 @@
+# Copyright (c) vhffs project and its contributors
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without 
+# modification, are permitted provided that the following conditions 
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright 
+#   notice, this list of conditions and the following disclaimer.
+#2. Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in 
+#   the documentation and/or other materials provided with the 
+#   distribution.
+#3. Neither the name of vhffs nor the names of its contributors 
+#   may be used to endorse or promote products derived from this 
+#   software without specific prior written permission.
+#
+#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
+#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
+#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
+#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+# POSSIBILITY OF SUCH DAMAGE.
+
+=head1 Vhffs::Tag::Request
+=head2 SYNOPSIS
+
+Manages requests for tags.
+
+=cut
+
+use strict;
+use utf8;
+
+package Vhffs::Tag::Request;
+
+
+sub create {
+	my ($main, $category, $tag, $requester, $tagged) = @_;
+	
+	my $dbh = $main->get_db_object();
+
+	my $sql = q{INSERT INTO vhffs_tag_request(category_label, tag_label, created, requester_id, tagged_id) VALUES (?, ?, ?, ?, ?)};
+	$dbh->do($sql, undef, $category, $tag, time(), $requester->get_uid, $tagged->get_oid);
+	
+	my $request_id = $dbh->last_insert_id(undef, undef, 'vhffs_tag_request', undef);
+	
+	return get_by_request_id($main, $request_id);
+}
+
+sub _new {
+	my($class, $main, $request_id, $category_label, $tag_label, $created, $requester_id, $tagged_id) = @_;
+	
+	my $self = {};
+	
+	bless($self, $class);
+	
+	$self->{main} = $main;
+	$self->{request_id} = $request_id;
+	$self->{category_label} = $category_label;
+	$self->{tag_label} = $tag_label;
+	$self->{created} = $created;
+	$self->{requester_id} = $requester_id;
+	$self->{tagged_id} = $tagged_id;
+	
+	return $self;
+}
+
+sub get_by_request_id {
+	my ($main, $request_id) = @_;
+	
+	my $dbh = $main->get_db_object();
+	
+	my $sql = q{SELECT tag_request_id, category_label, tag_label, created, requester_id, tagged_id
+		FROM vhffs_tag_request WHERE tag_request_id = ?};
+	
+	my $sth = $dbh->prepare($sql);
+	$sth->execute($request_id) or return undef;
+	my @results = $sth->fetchrow_array();
+	return undef unless @results;
+	
+	my $request = _new Vhffs::Tag::Request($main, @results);
+	
+	return $request;
+}
+
+sub get_all {
+	my ($main) = @_;
+	
+	my $requests = [];
+	
+	my $sql = q{SELECT tag_request_id, category_label, tag_label, created, requester_id, tagged_id
+		FROM vhffs_tag_request ORDER BY created};
+	
+	my $dbh = $main->get_db_object();
+	
+	my $sth = $dbh->prepare($sql);
+	$sth->execute() or return undef;
+	
+	while(my $c = $sth->fetchrow_arrayref()) {
+		push @$requests, _new Vhffs::Tag::Request($main, @$c);
+	}
+	
+	return $requests;
+}
+
+sub get_requester {
+	my ($self) = @_;
+	
+	unless( defined $self->{requester} ) {
+		$self->{requester} = Vhffs::User::get_by_uid($self->{main}, $self->{requester_id});
+	}
+	return $self->{requester};
+}
+
+sub get_tagged {
+	my ($self) = @_;
+	
+	unless( defined $self->{tagged} ) {
+		$self->{tagged} = Vhffs::ObjectFactory::fetch_object($self->{main}, $self->{tagged_id});
+	}
+	return $self->{tagged};
+}
+
+1;

Modified: trunk/vhffs-api/src/Vhffs/Tag.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Tag.pm	2008-05-19 11:47:34 UTC (rev 1197)
+++ trunk/vhffs-api/src/Vhffs/Tag.pm	2008-05-21 21:46:32 UTC (rev 1198)
@@ -190,7 +190,7 @@
 			FROM vhffs_tag t INNER JOIN vhffs_tag_category c ON c.tag_category_id = t.category_id
 			INNER JOIN vhffs_object_tag ot ON ot.tag_id = t.tag_id
 			WHERE ot.object_id = ? AND visibility <= ? ORDER BY c.label, t.label};
-	
+			
 	my $sth = $dbh->prepare($sql);
 	$sth->execute($o->get_oid(), $visibility) or return undef;
 

Modified: trunk/vhffs-backend/src/pgsql/initdb.sql.in
===================================================================
--- trunk/vhffs-backend/src/pgsql/initdb.sql.in	2008-05-19 11:47:34 UTC (rev 1197)
+++ trunk/vhffs-backend/src/pgsql/initdb.sql.in	2008-05-21 21:46:32 UTC (rev 1198)
@@ -474,12 +474,13 @@
 -- Tags requested by users
 
 CREATE TABLE vhffs_tag_request (
-    tag_request_id int4 NOT NULL,
+    tag_request_id SERIAL,
 -- Label of the category. We could have a label
 -- and an id and fill in the correct field depending
 -- of the existence of the category
     category_label VARCHAR(30) NOT NULL,
     tag_label VARCHAR(30) NOT NULL,
+    created int8 NOT NULL,
 -- User who requested the tag
     requester_id int4,
 -- For which object

Modified: trunk/vhffs-panel/Makefile.am
===================================================================
--- trunk/vhffs-panel/Makefile.am	2008-05-19 11:47:34 UTC (rev 1197)
+++ trunk/vhffs-panel/Makefile.am	2008-05-21 21:46:32 UTC (rev 1198)
@@ -64,6 +64,7 @@
 	admin/tag/category/create.pl \
 	admin/tag/category/edit.pl \
 	admin/tag/category/list.pl \
+	admin/tag/request/list.pl \
 	admin/git/index.pl \
 	admin/git/list.pl \
 	admin/git/search.pl \

Modified: trunk/vhffs-panel/group/prefs.pl
===================================================================
--- trunk/vhffs-panel/group/prefs.pl	2008-05-19 11:47:34 UTC (rev 1197)
+++ trunk/vhffs-panel/group/prefs.pl	2008-05-21 21:46:32 UTC (rev 1198)
@@ -50,6 +50,7 @@
 use Vhffs::Services::MailGroup;
 use Vhffs::Tag;
 use Vhffs::Tag::Category;
+use Vhffs::Tag::Request;
 use Vhffs::User;
 
 my $panel = new Vhffs::Panel::Main();
@@ -64,6 +65,17 @@
 my $cgi = $panel->{'cgi'};
 my $template;
 
+BEGIN {
+	  ## death handler, presumes no output yet
+  $SIG{'__WARN__'} = sub {
+    my $error = shift;
+    chomp $error;
+    $error =~ s/[<&>]/'&#'.ord($&).';'/ge;
+    print "Content-type: text/html\n\n[$error]\n";
+    exit 0;
+  };
+}
+
 unless( defined $group ) {
 	$template = new HTML::Template( filename => $templatedir.'/panel/misc/simplemsg.tmpl' );
 	$template->param( MESSAGE => gettext( "Error. This group doesn't exists") );
@@ -202,6 +214,8 @@
     	add_tag();
     } elsif( defined( $cgi->param('delete_tag_submit') ) ) {
     	delete_tag();
+    } elsif( defined( $cgi->param('request_tag_submit') ) ) {
+    	request_tag();
     }
 
 
@@ -366,3 +380,36 @@
 	}
 }
 
+sub request_tag {
+	unless( $user->can_modify( $group ) ) {
+		$panel->add_error( gettext( 'You\'re not allowed to do this (ACL rights)' ) );
+		return 0;
+	}
+	
+	my $category_label = $cgi->param('category');
+	my $tag_label = $cgi->param('tag');
+	
+	unless(defined $category_label && defined $tag_label) {
+		$panel->add_error( gettext('CGI error') );
+		return 0;
+	}
+	
+	if($category_label =~ /^\s*$/) {
+		$panel->add_error( gettext('Category can\'t be empty') );
+		return 0;
+	}
+	
+	if($tag_label =~ /^\s*$/) {
+		$panel->add_error( gettext('Tag name can\'t be empty') );
+		return 0;
+	}
+	
+	unless( defined(Vhffs::Tag::Request::create($vhffs, $category_label, $tag_label, $user, $group) ) ) {
+		$panel->add_error( gettext('An error occured while saving your request') );
+		return;
+	}
+	
+	$panel->add_info( gettext('Tag request saved, please wait while a moderator approve it') );
+	
+}
+

Modified: trunk/vhffs-panel/templates/Makefile.am
===================================================================
--- trunk/vhffs-panel/templates/Makefile.am	2008-05-19 11:47:34 UTC (rev 1197)
+++ trunk/vhffs-panel/templates/Makefile.am	2008-05-21 21:46:32 UTC (rev 1198)
@@ -44,6 +44,7 @@
 	admin/tag/category/create.tmpl \
 	admin/tag/category/edit.tmpl \ 
 	admin/tag/category/list.tmpl \
+	admin/tag/request/list.tmpl \
 	admin/git/part.tmpl \
 	admin/git/search.tmpl \
 	admin/user/part.tmpl \

Modified: trunk/vhffs-panel/templates/group/tags.tmpl
===================================================================
--- trunk/vhffs-panel/templates/group/tags.tmpl	2008-05-19 11:47:34 UTC (rev 1197)
+++ trunk/vhffs-panel/templates/group/tags.tmpl	2008-05-21 21:46:32 UTC (rev 1198)
@@ -13,7 +13,7 @@
 </TMPL_LOOP>
 </ul>
 </TMPL_IF>
-<h3><TMPL_I18N KEY="Add a new tag"></h3>
+<h3><TMPL_I18N KEY="Add a tag"></h3>
 <ul>
 <TMPL_LOOP NAME="CATEGORIES">
 <li><TMPL_VAR NAME="LABEL">:
@@ -24,4 +24,14 @@
 </ul>
 </li>
 </TMPL_LOOP>
-</ul>
\ No newline at end of file
+</ul>
+<h3><TMPL_I18N KEY="Request new tag"></h3>
+<form name="requestTagForm" action="#" method="post">
+<p><label for="requestTagCategory"><TMPL_I18N KEY="Category">:</label>
+<input type="text" name="category" id="requestTagCategory"/>
+</p>
+<p><label for="requestTagTag"><TMPL_I18N KEY="Label">:</label>
+<input type="text" name="tag" id="requestTagTag"/>
+</p>
+<p class="button"><input type="submit" name="request_tag_submit" value="<TMPL_I18N KEY="OK">"/></p>
+</form>


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/