renamed 'sysadmin_userid' to 'sysadmin_userids' to support multiple sysadmin ids.

added svn commit history to the project home page
This commit is contained in:
hyung-hwan 2010-02-26 14:41:56 +00:00
parent 7af7fff45c
commit ebeb0481ce
20 changed files with 168 additions and 68 deletions

View File

@ -3,7 +3,7 @@ Version: @VERSION@
Maintainer: @PACKAGE_BUGREPORT@ Maintainer: @PACKAGE_BUGREPORT@
Homepage: @PACKAGE_URL@ Homepage: @PACKAGE_URL@
Depends: subversion, apache2-mpm-prefork, libapache2-svn, php5, php5-ldap, wget Depends: subversion, apache2-mpm-prefork, libapache2-svn, php5, php5-ldap, wget
Recommends: php5-mysql, php5-svn Recommends: php5-mysql, php5-svn (>= 0.5.1)
Suggests: slapd, mysql-server Suggests: slapd, mysql-server
Section: web Section: web
Priority: optional Priority: optional

10
codepot/configure vendored
View File

@ -2,7 +2,7 @@
# Guess values for system-dependent variables and create Makefiles. # Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.64 for codepot 0.1.0. # Generated by GNU Autoconf 2.64 for codepot 0.1.0.
# #
# Report bugs to <Chung, Hyung-Hwan <hyunghwan.chung@gmail.com>>. # Report bugs to <Hyung-Hwan Chung <hyunghwan.chung@gmail.com>>.
# #
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software # 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software
@ -227,7 +227,7 @@ fi
$as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
$as_echo "$0: be upgraded to zsh 4.3.4 or later." $as_echo "$0: be upgraded to zsh 4.3.4 or later."
else else
$as_echo "$0: Please tell bug-autoconf@gnu.org and Chung, Hyung-Hwan $as_echo "$0: Please tell bug-autoconf@gnu.org and Hyung-Hwan Chung
$0: <hyunghwan.chung@gmail.com> about your system, $0: <hyunghwan.chung@gmail.com> about your system,
$0: including any error possibly output before this $0: including any error possibly output before this
$0: message. Then install a modern shell, or manually run $0: message. Then install a modern shell, or manually run
@ -550,7 +550,7 @@ PACKAGE_NAME='codepot'
PACKAGE_TARNAME='codepot' PACKAGE_TARNAME='codepot'
PACKAGE_VERSION='0.1.0' PACKAGE_VERSION='0.1.0'
PACKAGE_STRING='codepot 0.1.0' PACKAGE_STRING='codepot 0.1.0'
PACKAGE_BUGREPORT='Chung, Hyung-Hwan <hyunghwan.chung@gmail.com>' PACKAGE_BUGREPORT='Hyung-Hwan Chung <hyunghwan.chung@gmail.com>'
PACKAGE_URL='http://www.abiyo.net/codepot' PACKAGE_URL='http://www.abiyo.net/codepot'
ac_subst_vars='LTLIBOBJS ac_subst_vars='LTLIBOBJS
@ -1270,7 +1270,7 @@ Optional Packages:
--with-logdir directory for log files --with-logdir directory for log files
--with-cachedir directory for cache files --with-cachedir directory for cache files
Report bugs to <Chung, Hyung-Hwan <hyunghwan.chung@gmail.com>>. Report bugs to <Hyung-Hwan Chung <hyunghwan.chung@gmail.com>>.
codepot home page: <http://www.abiyo.net/codepot>. codepot home page: <http://www.abiyo.net/codepot>.
_ACEOF _ACEOF
ac_status=$? ac_status=$?
@ -3532,7 +3532,7 @@ $config_files
Configuration headers: Configuration headers:
$config_headers $config_headers
Report bugs to <Chung, Hyung-Hwan <hyunghwan.chung@gmail.com>>. Report bugs to <Hyung-Hwan Chung <hyunghwan.chung@gmail.com>>.
codepot home page: <http://www.abiyo.net/codepot>." codepot home page: <http://www.abiyo.net/codepot>."
_ACEOF _ACEOF

View File

@ -1,7 +1,7 @@
dnl AC_PREREQ(2.59) dnl AC_PREREQ(2.59)
AC_INIT([codepot],[0.1.0],[Chung, Hyung-Hwan <hyunghwan.chung@gmail.com>],,[http://www.abiyo.net/codepot]) AC_INIT([codepot],[0.1.0],[Hyung-Hwan Chung <hyunghwan.chung@gmail.com>],,[http://www.abiyo.net/codepot])
AC_CONFIG_HEADER([./config.h]) AC_CONFIG_HEADER([./config.h])
AC_CONFIG_AUX_DIR([ac/aux]) AC_CONFIG_AUX_DIR([ac/aux])
AC_CONFIG_MACRO_DIR([ac/m4]) AC_CONFIG_MACRO_DIR([ac/m4])

View File

@ -1,7 +1,7 @@
cfgdir=$(CFGDIR) cfgdir=$(CFGDIR)
cfg_DATA = codepot.ini codepot.sql codepot.a2ldap cfg_DATA = codepot.ini codepot.sql codepot.a2ldap
cfg_SCRIPTS = repo.sh start-commit post-commit cfg_SCRIPTS = repo.sh start-commit pre-commit post-commit
EXTRA_DIST = $(cfg_DATA) $(cfg_SCRIPTS) EXTRA_DIST = $(cfg_DATA) $(cfg_SCRIPTS)

View File

@ -166,7 +166,7 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
wwwdir = @wwwdir@ wwwdir = @wwwdir@
cfg_DATA = codepot.ini codepot.sql codepot.a2ldap cfg_DATA = codepot.ini codepot.sql codepot.a2ldap
cfg_SCRIPTS = repo.sh start-commit post-commit cfg_SCRIPTS = repo.sh start-commit pre-commit post-commit
EXTRA_DIST = $(cfg_DATA) $(cfg_SCRIPTS) EXTRA_DIST = $(cfg_DATA) $(cfg_SCRIPTS)
all: all-am all: all-am

View File

@ -75,9 +75,11 @@ svn_base_url = "http://${SERVER_NAME}:${SERVER_PORT}/svn"
login_model = "LdapLoginModel" login_model = "LdapLoginModel"
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; System administrator ID ; Comma separated list of system administrator IDs
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
sysadmin_userid = ; sysadmin_userids = tom, dick, jane
;------------------------------------------------------------------------------
sysadmin_userids =
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; Maximum file upload size in Kbytes ; Maximum file upload size in Kbytes
@ -94,6 +96,10 @@ max_latest_projects = "10"
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
max_svn_commits = "10" max_svn_commits = "10"
;------------------------------------------------------------------------------
; Maximum number of svn commits to show in the project home page
;------------------------------------------------------------------------------
max_svn_commits_in_project = "5"
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; directory to accomodate subversion repositories ; directory to accomodate subversion repositories

View File

@ -76,7 +76,8 @@ CREATE TABLE file (
CREATE TABLE log ( CREATE TABLE log (
id BIGINT PRIMARY KEY AUTO_INCREMENT, id BIGINT PRIMARY KEY AUTO_INCREMENT,
type VARCHAR(16) NOT NULL, type VARCHAR(16) NOT NULL,
projectid VARCHAR(32) NOT NULL,
message TEXT NOT NULL, message TEXT NOT NULL,
createdon DATETIME NOT NULL, createdon DATETIME NOT NULL,
INDEX timed_type (createdon, type) INDEX timed_type_project (createdon, type, projectid)
) charset=utf8 engine=InnoDB; ) charset=utf8 engine=InnoDB;

View File

@ -1,13 +1,8 @@
#!/bin/sh #!/bin/sh
post_commit() { REPOBASE="`basename "${1}"`"
local repo_path="$1" REV="${2}"
local rev="$2"
local repo="`basename "${repo_path}"`"
ans="`wget -q -O- "%API%/logSvnCommit/${repo}/${rev}" 2>/dev/null`" # does not care if logging has failed.
return 0 wget -q -O- "%API%/logSvnCommit/${REPOBASE}/${REV}" 2>/dev/null
} exit 0
post_commit "$1" "$2"
exit $?

29
codepot/etc/pre-commit Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
REPO="$1"
TXN="$2"
# TODO: need to check the policy on a commit message
# wget ... %API%/svnPolicy/ ...
# once done, update repo.sh to include pre-commit
svnlook log -t "$TXN" "$REPO" | grep "[a-zA-Z0-9]" >/dev/null || {
echo "---------------------------------------------------------" >&2
echo " Your commit message do not contain any meaningful text. " >&2
echo "---------------------------------------------------------" >&2
exit 1
}
#
# Subversion problem:
# Hard to detect the tagging patterns and update patterns on a tag.
#
#svnlook changed -t "$TXN" "$REPO" | grep '^tags/' >/dev/null && {
# echo "----------------------------------------------------" >&2
# echo " You are not allowed to change tags/* " >&2
# echo "----------------------------------------------------" >&2
# exit 1
#}
#
exit 0

View File

@ -29,6 +29,14 @@ make_repo() {
chmod 0755 "${repodir}/start-commit" chmod 0755 "${repodir}/start-commit"
#} #}
#[ -f "${repodir}/pre-commit" ] || {
# sed "s|%API%|${api}|g" "${cfgdir}/pre-commit" > "${repodir}/pre-commit" || {
# echo "ERROR: cannot install pre-commit to ${repodir}"
# return 1;
# }
# chmod 0755 "${repodir}/pre-commit"
#}
#[ -f "${repodir}/post-commit" ] || { #[ -f "${repodir}/post-commit" ] || {
sed "s|%API%|${api}|g" "${cfgdir}/post-commit" > "${repodir}/post-commit" || { sed "s|%API%|${api}|g" "${cfgdir}/post-commit" > "${repodir}/post-commit" || {
echo "ERROR: cannot install post-commit to ${repodir}" echo "ERROR: cannot install post-commit to ${repodir}"

View File

@ -1,21 +1,19 @@
#!/bin/sh #!/bin/sh
start_commit() { REPOBASE="`basename "${1}"`"
local repo_path="$1" USER="${2}"
local user="$2"
local repo="`basename "${repo_path}"`"
ans="`wget -q -O- "%API%/projectHasMember/${repo}/${user}" 2>/dev/null`" ans="`wget -q -O- "%API%/projectHasMember/${REPOBASE}/${USER}" 2>/dev/null`"
[ "${ans}" = "YES" ] && return 0; [ "${ans}" = "YES" ] && exit 0
[ "${ans}" = "NO" ] && { [ "${ans}" = "NO" ] && {
echo "${user} is not a member of ${repo}" >&2 echo "-------------------------------------------------------------" >&2
return 1 echo " ${USER} is not a member of ${REPOBASE}" >&2
echo "-------------------------------------------------------------" >&2
exit 1
} }
echo "Critical error occurred while checking project membership of ${repo} for ${user}" >&2 echo "---------------------------------------------------------------------" >&2
return 1 echo " Failed to check membership of ${REPOBASE} for ${USER}" >&2
} echo "---------------------------------------------------------------------" >&2
exit 1
start_commit "$1" "$2"
exit $?

View File

@ -9,6 +9,8 @@ class API extends Controller
function projectHasMember ($projectid, $userid) function projectHasMember ($projectid, $userid)
{ {
if (!isset($projectid) || !isset($userid)) return 'NO';
// TODO: access control - may allow localhost only // TODO: access control - may allow localhost only
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');
print ($this->projects->projectHasMember ($projectid, $userid) === FALSE)? 'NO': 'YES'; print ($this->projects->projectHasMember ($projectid, $userid) === FALSE)? 'NO': 'YES';
@ -16,6 +18,8 @@ class API extends Controller
function projectIsOwnedBy ($projectid, $userid) function projectIsOwnedBy ($projectid, $userid)
{ {
if (!isset($projectid) || !isset($userid)) return 'NO';
// TODO: access control - may allow localhost only // TODO: access control - may allow localhost only
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');
print ($this->projects->projectIsOwnedBy ($projectid, $userid) === FALSE)? 'NO': 'YES'; print ($this->projects->projectIsOwnedBy ($projectid, $userid) === FALSE)? 'NO': 'YES';
@ -23,6 +27,8 @@ class API extends Controller
function logSvnCommit ($repo, $rev) function logSvnCommit ($repo, $rev)
{ {
if (!isset($repo) || !isset($rev)) return;
// TODO: access control - may allow localhost only // TODO: access control - may allow localhost only
$this->load->model ('LogModel', 'logs'); $this->load->model ('LogModel', 'logs');
$this->logs->writeSvnCommit ($repo, $rev); $this->logs->writeSvnCommit ($repo, $rev);

View File

@ -23,6 +23,7 @@ class Project extends Controller
function home ($projectid = "") function home ($projectid = "")
{ {
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');
$this->load->model ('LogModel', 'logs');
$login = $this->login->getUser (); $login = $this->login->getUser ();
if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '')
@ -42,11 +43,22 @@ class Project extends Controller
$this->load->view ($this->VIEW_ERROR, $data); $this->load->view ($this->VIEW_ERROR, $data);
} }
else else
{
$svn_commits = $this->logs->getSvnCommits (
CODEPOT_MAX_SVN_COMMITS_IN_PROJECT, $projectid);
if ($svn_commits === FALSE)
{
$data['message'] = 'DATABASE ERROR';
$this->load->view ($this->VIEW_ERROR, $data);
}
else
{ {
$data['project'] = $project; $data['project'] = $project;
$data['svn_commits'] = $svn_commits;
$this->load->view ($this->VIEW_HOME, $data); $this->load->view ($this->VIEW_HOME, $data);
} }
} }
}
function _edit_project ($project, $mode, $login) function _edit_project ($project, $mode, $login)
{ {

View File

@ -42,11 +42,23 @@ class LoginModel extends Model
function authenticate ($userid, $password) function authenticate ($userid, $password)
{ {
$server = $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT']; $server = $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'];
$sysadmin = FALSE;
$ids = explode (',', CODEPOT_SYSADMIN_USERIDS);
foreach ($ids as $id)
{
if (trim($id) == $userid)
{
$sysadmin = TRUE;
break;
}
}
$this->session->set_userdata ( $this->session->set_userdata (
array ( array (
'userid' => $userid, 'userid' => $userid,
'server' => $server, 'server' => $server,
'sysadmin?' => ($userid == CODEPOT_SYSADMIN_USERID) 'sysadmin?' => $sysadmin
) )
); );
return TRUE; return TRUE;

View File

@ -8,34 +8,12 @@ class LogModel extends Model
$this->load->database (); $this->load->database ();
} }
/* function getSvnCommits ($limit, $projectid = '')
function get ($id)
{
$this->db->trans_start ();
$this->db->where ('id', (string)$id);
$query = $this->db->get ('log');
$result = $query->result ();
if (empty($result))
{
$this->db->trans_complete ();
if ($this->db->trans_status() === FALSE) return FALSE;
return NULL;
}
$this->db->trans_complete ();
if ($this->db->trans_status() === FALSE) return FALSE;
return $result[0];
}
*/
function getSvnCommits ($limit)
{ {
$this->db->trans_start (); $this->db->trans_start ();
$this->db->where ('type', 'svn-commit'); $this->db->where ('type', 'svn-commit');
if ($projectid != '') $this->db->where ('projectid', $projectid);
$this->db->order_by ('createdon', 'desc'); $this->db->order_by ('createdon', 'desc');
$query = $this->db->get ('log', $limit); $query = $this->db->get ('log', $limit);
@ -49,7 +27,8 @@ class LogModel extends Model
{ {
list($repo,$rev) = split('[,]', $row->message); list($repo,$rev) = split('[,]', $row->message);
$commits[$count]['repo'] = $repo; /* $row->project must be equal to $repo */
$commits[$count]['repo'] = $row->projectid;
$commits[$count]['rev'] = $rev; $commits[$count]['rev'] = $rev;
$log = @svn_log ( $log = @svn_log (
@ -77,6 +56,7 @@ class LogModel extends Model
function writeSvnCommit ($repo, $rev) function writeSvnCommit ($repo, $rev)
{ {
$log->type = 'svn-commit'; $log->type = 'svn-commit';
$log->projectid = $repo;
$log->message = "{$repo},{$rev}"; $log->message = "{$repo},{$rev}";
$this->write ($log); $this->write ($log);
} }
@ -86,6 +66,7 @@ class LogModel extends Model
$this->db->trans_begin (); $this->db->trans_begin ();
$this->db->set ('type', $log->type); $this->db->set ('type', $log->type);
$this->db->set ('projectid', $log->projectid);
$this->db->set ('message', $log->message); $this->db->set ('message', $log->message);
$this->db->set ('createdon', date('Y-m-d H:i:s')); $this->db->set ('createdon', date('Y-m-d H:i:s'));
$this->db->insert ('log'); $this->db->insert ('log');

View File

@ -82,6 +82,40 @@ $this->load->view (
<?= anchor ($this->converter->expand(CODEPOT_SVN_BASE_URL, $_SERVER) . '/' . $project->id) ?> <?= anchor ($this->converter->expand(CODEPOT_SVN_BASE_URL, $_SERVER) . '/' . $project->id) ?>
</div> </div>
<div class="box">
<div class="boxtitle"><?=$this->lang->line('SVN commits')?></div>
<table id="project_home_mainarea_sidebar_svn_commits_table">
<?php
$xdot = $this->converter->AsciiToHex ('.');
foreach ($svn_commits as $commit)
{
print '<tr class="odd">';
print '<td>';
print substr($commit['time'], 0, 10);
print '</td>';
print '<td>';
print anchor (
"/source/revision/{$commit['repo']}/{$xdot}/{$commit['rev']}",
$commit['rev']);
print '</td>';
print '<td>';
print htmlspecialchars ($commit['author']);
print '</td>';
print '</tr>';
print '<tr class="even">';
print '<td colspan=4>';
$sm = strtok (trim ($commit['message']), "\r\n");
print htmlspecialchars ($sm);
print '</td>';
print '</tr>';
}
?>
</table>
</div>
</div> <!-- project_home_sidebar --> </div> <!-- project_home_sidebar -->
<!----------------------------------------------------------------------------> <!---------------------------------------------------------------------------->

View File

@ -5,7 +5,7 @@ function show_projectbar ($con, $site, $project, $pageid, $ctxmenuitems)
{ {
print "<div class='title'>"; print "<div class='title'>";
if (isset($project)) print $project->id; if (isset($project)) print $project->name;
else if (isset($site) && $site->name != '') print htmlspecialchars($site->name); else if (isset($site) && $site->name != '') print htmlspecialchars($site->name);
else print htmlspecialchars(CODEPOT_DEFAULT_BANNER); else print htmlspecialchars(CODEPOT_DEFAULT_BANNER);

View File

@ -26,9 +26,10 @@ function load_ini ($file)
array ('svn_base_url', 'string', 'http://${SERVER_NAME}:${SERVER_PORT}/svn'), array ('svn_base_url', 'string', 'http://${SERVER_NAME}:${SERVER_PORT}/svn'),
array ('login_model', 'string', 'LdapLoginModel'), array ('login_model', 'string', 'LdapLoginModel'),
array ('sysadmin_userid', 'string', ''), array ('sysadmin_userids', 'string', ''),
array ('max_upload_size', 'string', '10000'), // kbytes array ('max_upload_size', 'string', '10000'), // kbytes
array ('max_svn_commits', 'integer', 10), array ('max_svn_commits', 'integer', 10),
array ('max_svn_commits_in_project', 'integer', 5),
array ('max_latest_projects', 'integer', 10), array ('max_latest_projects', 'integer', 10),
array ('database_username', 'string', ''), array ('database_username', 'string', ''),

View File

@ -113,7 +113,6 @@ body {
.content .mainarea { .content .mainarea {
padding: 0.2em 0em 0.2em 0em; padding: 0.2em 0em 0.2em 0em;
min-height: 30em;
} }
.content .mainarea .title { .content .mainarea .title {
@ -377,6 +376,7 @@ pre.prettyprint .nocode a:hover {
} }
.content .footer { .content .footer {
clear: both;
padding: 0.3em 0.5em 0.3em 0.5em; padding: 0.3em 0.5em 0.3em 0.5em;
font-size: .8em; font-size: .8em;
font-weight: bold; font-weight: bold;

View File

@ -22,6 +22,23 @@
background-color: inherit; background-color: inherit;
} }
/*-----------------------------------------------
* project home view
*-----------------------------------------------*/
#project_home_mainarea_sidebar_svn_commits_table {
margin: 0;
padding: 0;
}
#project_home_mainarea_sidebar_svn_commits_table tr.odd {
background-color: #bbccef;
}
#project_home_mainarea_sidebar_svn_commits_table tr.even {
background-color: inherit;
}
/*----------------------------------------------- /*-----------------------------------------------
* project file home view * project file home view