From ebeb0481cea61c0c69470875d91119148bd0c3c3 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 26 Feb 2010 14:41:56 +0000 Subject: [PATCH] renamed 'sysadmin_userid' to 'sysadmin_userids' to support multiple sysadmin ids. added svn commit history to the project home page --- codepot/DEBIAN/control.in | 2 +- codepot/configure | 10 +++--- codepot/configure.ac | 2 +- codepot/etc/Makefile.am | 2 +- codepot/etc/Makefile.in | 2 +- codepot/etc/codepot.ini.in | 10 ++++-- codepot/etc/codepot.sql | 3 +- codepot/etc/post-commit | 15 +++------ codepot/etc/pre-commit | 29 ++++++++++++++++++ codepot/etc/repo.sh | 8 +++++ codepot/etc/start-commit | 28 ++++++++--------- codepot/src/codepot/controllers/api.php | 6 ++++ codepot/src/codepot/controllers/project.php | 16 ++++++++-- codepot/src/codepot/models/loginmodel.php | 14 ++++++++- codepot/src/codepot/models/logmodel.php | 31 ++++--------------- codepot/src/codepot/views/project_home.php | 34 +++++++++++++++++++++ codepot/src/codepot/views/projectbar.php | 2 +- codepot/src/config.php.in | 3 +- codepot/src/css/common.css | 2 +- codepot/src/css/project.css | 17 +++++++++++ 20 files changed, 168 insertions(+), 68 deletions(-) create mode 100755 codepot/etc/pre-commit diff --git a/codepot/DEBIAN/control.in b/codepot/DEBIAN/control.in index b5546398..3415c118 100644 --- a/codepot/DEBIAN/control.in +++ b/codepot/DEBIAN/control.in @@ -3,7 +3,7 @@ Version: @VERSION@ Maintainer: @PACKAGE_BUGREPORT@ Homepage: @PACKAGE_URL@ 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 Section: web Priority: optional diff --git a/codepot/configure b/codepot/configure index 93bb247c..7ca8e299 100755 --- a/codepot/configure +++ b/codepot/configure @@ -2,7 +2,7 @@ # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.64 for codepot 0.1.0. # -# Report bugs to >. +# Report bugs to >. # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # 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: be upgraded to zsh 4.3.4 or later." 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: about your system, $0: including any error possibly output before this $0: message. Then install a modern shell, or manually run @@ -550,7 +550,7 @@ PACKAGE_NAME='codepot' PACKAGE_TARNAME='codepot' PACKAGE_VERSION='0.1.0' PACKAGE_STRING='codepot 0.1.0' -PACKAGE_BUGREPORT='Chung, Hyung-Hwan ' +PACKAGE_BUGREPORT='Hyung-Hwan Chung ' PACKAGE_URL='http://www.abiyo.net/codepot' ac_subst_vars='LTLIBOBJS @@ -1270,7 +1270,7 @@ Optional Packages: --with-logdir directory for log files --with-cachedir directory for cache files -Report bugs to >. +Report bugs to >. codepot home page: . _ACEOF ac_status=$? @@ -3532,7 +3532,7 @@ $config_files Configuration headers: $config_headers -Report bugs to >. +Report bugs to >. codepot home page: ." _ACEOF diff --git a/codepot/configure.ac b/codepot/configure.ac index 21a32bff..0391cbd0 100644 --- a/codepot/configure.ac +++ b/codepot/configure.ac @@ -1,7 +1,7 @@ dnl AC_PREREQ(2.59) -AC_INIT([codepot],[0.1.0],[Chung, Hyung-Hwan ],,[http://www.abiyo.net/codepot]) +AC_INIT([codepot],[0.1.0],[Hyung-Hwan Chung ],,[http://www.abiyo.net/codepot]) AC_CONFIG_HEADER([./config.h]) AC_CONFIG_AUX_DIR([ac/aux]) AC_CONFIG_MACRO_DIR([ac/m4]) diff --git a/codepot/etc/Makefile.am b/codepot/etc/Makefile.am index adb537b3..125d826d 100644 --- a/codepot/etc/Makefile.am +++ b/codepot/etc/Makefile.am @@ -1,7 +1,7 @@ cfgdir=$(CFGDIR) 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) diff --git a/codepot/etc/Makefile.in b/codepot/etc/Makefile.in index 53eca2ae..cedecfdb 100644 --- a/codepot/etc/Makefile.in +++ b/codepot/etc/Makefile.in @@ -166,7 +166,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ wwwdir = @wwwdir@ 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) all: all-am diff --git a/codepot/etc/codepot.ini.in b/codepot/etc/codepot.ini.in index 81d8ace0..61ff1f23 100644 --- a/codepot/etc/codepot.ini.in +++ b/codepot/etc/codepot.ini.in @@ -75,9 +75,11 @@ svn_base_url = "http://${SERVER_NAME}:${SERVER_PORT}/svn" 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 @@ -94,6 +96,10 @@ max_latest_projects = "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 diff --git a/codepot/etc/codepot.sql b/codepot/etc/codepot.sql index d555dd7d..ab97d2e5 100644 --- a/codepot/etc/codepot.sql +++ b/codepot/etc/codepot.sql @@ -76,7 +76,8 @@ CREATE TABLE file ( CREATE TABLE log ( id BIGINT PRIMARY KEY AUTO_INCREMENT, type VARCHAR(16) NOT NULL, + projectid VARCHAR(32) NOT NULL, message TEXT NOT NULL, createdon DATETIME NOT NULL, - INDEX timed_type (createdon, type) + INDEX timed_type_project (createdon, type, projectid) ) charset=utf8 engine=InnoDB; diff --git a/codepot/etc/post-commit b/codepot/etc/post-commit index 3ec8523f..2b07be21 100755 --- a/codepot/etc/post-commit +++ b/codepot/etc/post-commit @@ -1,13 +1,8 @@ #!/bin/sh -post_commit() { - local repo_path="$1" - local rev="$2" - local repo="`basename "${repo_path}"`" +REPOBASE="`basename "${1}"`" +REV="${2}" - ans="`wget -q -O- "%API%/logSvnCommit/${repo}/${rev}" 2>/dev/null`" - return 0 -} - -post_commit "$1" "$2" -exit $? +# does not care if logging has failed. +wget -q -O- "%API%/logSvnCommit/${REPOBASE}/${REV}" 2>/dev/null +exit 0 diff --git a/codepot/etc/pre-commit b/codepot/etc/pre-commit new file mode 100755 index 00000000..72942a16 --- /dev/null +++ b/codepot/etc/pre-commit @@ -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 diff --git a/codepot/etc/repo.sh b/codepot/etc/repo.sh index 0b031c22..eb95e228 100755 --- a/codepot/etc/repo.sh +++ b/codepot/etc/repo.sh @@ -29,6 +29,14 @@ make_repo() { 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" ] || { sed "s|%API%|${api}|g" "${cfgdir}/post-commit" > "${repodir}/post-commit" || { echo "ERROR: cannot install post-commit to ${repodir}" diff --git a/codepot/etc/start-commit b/codepot/etc/start-commit index 36226ec3..6664d1e8 100755 --- a/codepot/etc/start-commit +++ b/codepot/etc/start-commit @@ -1,21 +1,19 @@ #!/bin/sh -start_commit() { - local repo_path="$1" - local user="$2" - local repo="`basename "${repo_path}"`" +REPOBASE="`basename "${1}"`" +USER="${2}" - ans="`wget -q -O- "%API%/projectHasMember/${repo}/${user}" 2>/dev/null`" - [ "${ans}" = "YES" ] && return 0; +ans="`wget -q -O- "%API%/projectHasMember/${REPOBASE}/${USER}" 2>/dev/null`" +[ "${ans}" = "YES" ] && exit 0 - [ "${ans}" = "NO" ] && { - echo "${user} is not a member of ${repo}" >&2 - return 1 - } - - echo "Critical error occurred while checking project membership of ${repo} for ${user}" >&2 - return 1 +[ "${ans}" = "NO" ] && { + echo "-------------------------------------------------------------" >&2 + echo " ${USER} is not a member of ${REPOBASE}" >&2 + echo "-------------------------------------------------------------" >&2 + exit 1 } -start_commit "$1" "$2" -exit $? +echo "---------------------------------------------------------------------" >&2 +echo " Failed to check membership of ${REPOBASE} for ${USER}" >&2 +echo "---------------------------------------------------------------------" >&2 +exit 1 diff --git a/codepot/src/codepot/controllers/api.php b/codepot/src/codepot/controllers/api.php index fc11f406..1b0a52e6 100644 --- a/codepot/src/codepot/controllers/api.php +++ b/codepot/src/codepot/controllers/api.php @@ -9,6 +9,8 @@ class API extends Controller function projectHasMember ($projectid, $userid) { + if (!isset($projectid) || !isset($userid)) return 'NO'; + // TODO: access control - may allow localhost only $this->load->model ('ProjectModel', 'projects'); print ($this->projects->projectHasMember ($projectid, $userid) === FALSE)? 'NO': 'YES'; @@ -16,6 +18,8 @@ class API extends Controller function projectIsOwnedBy ($projectid, $userid) { + if (!isset($projectid) || !isset($userid)) return 'NO'; + // TODO: access control - may allow localhost only $this->load->model ('ProjectModel', 'projects'); print ($this->projects->projectIsOwnedBy ($projectid, $userid) === FALSE)? 'NO': 'YES'; @@ -23,6 +27,8 @@ class API extends Controller function logSvnCommit ($repo, $rev) { + if (!isset($repo) || !isset($rev)) return; + // TODO: access control - may allow localhost only $this->load->model ('LogModel', 'logs'); $this->logs->writeSvnCommit ($repo, $rev); diff --git a/codepot/src/codepot/controllers/project.php b/codepot/src/codepot/controllers/project.php index b28a5584..b0a7e411 100644 --- a/codepot/src/codepot/controllers/project.php +++ b/codepot/src/codepot/controllers/project.php @@ -23,6 +23,7 @@ class Project extends Controller function home ($projectid = "") { $this->load->model ('ProjectModel', 'projects'); + $this->load->model ('LogModel', 'logs'); $login = $this->login->getUser (); if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') @@ -43,8 +44,19 @@ class Project extends Controller } else { - $data['project'] = $project; - $this->load->view ($this->VIEW_HOME, $data); + $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['svn_commits'] = $svn_commits; + $this->load->view ($this->VIEW_HOME, $data); + } } } diff --git a/codepot/src/codepot/models/loginmodel.php b/codepot/src/codepot/models/loginmodel.php index 091df7c5..516400b9 100644 --- a/codepot/src/codepot/models/loginmodel.php +++ b/codepot/src/codepot/models/loginmodel.php @@ -42,11 +42,23 @@ class LoginModel extends Model function authenticate ($userid, $password) { $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 ( array ( 'userid' => $userid, 'server' => $server, - 'sysadmin?' => ($userid == CODEPOT_SYSADMIN_USERID) + 'sysadmin?' => $sysadmin ) ); return TRUE; diff --git a/codepot/src/codepot/models/logmodel.php b/codepot/src/codepot/models/logmodel.php index a17a0643..77f3326b 100644 --- a/codepot/src/codepot/models/logmodel.php +++ b/codepot/src/codepot/models/logmodel.php @@ -8,34 +8,12 @@ class LogModel extends Model $this->load->database (); } - /* - 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) + function getSvnCommits ($limit, $projectid = '') { $this->db->trans_start (); $this->db->where ('type', 'svn-commit'); + if ($projectid != '') $this->db->where ('projectid', $projectid); $this->db->order_by ('createdon', 'desc'); $query = $this->db->get ('log', $limit); @@ -49,7 +27,8 @@ class LogModel extends Model { 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; $log = @svn_log ( @@ -77,6 +56,7 @@ class LogModel extends Model function writeSvnCommit ($repo, $rev) { $log->type = 'svn-commit'; + $log->projectid = $repo; $log->message = "{$repo},{$rev}"; $this->write ($log); } @@ -86,6 +66,7 @@ class LogModel extends Model $this->db->trans_begin (); $this->db->set ('type', $log->type); + $this->db->set ('projectid', $log->projectid); $this->db->set ('message', $log->message); $this->db->set ('createdon', date('Y-m-d H:i:s')); $this->db->insert ('log'); diff --git a/codepot/src/codepot/views/project_home.php b/codepot/src/codepot/views/project_home.php index abecf434..2949823e 100644 --- a/codepot/src/codepot/views/project_home.php +++ b/codepot/src/codepot/views/project_home.php @@ -82,6 +82,40 @@ $this->load->view ( converter->expand(CODEPOT_SVN_BASE_URL, $_SERVER) . '/' . $project->id) ?> +
+
lang->line('SVN commits')?>
+ +converter->AsciiToHex ('.'); + foreach ($svn_commits as $commit) + { + print ''; + print ''; + + print ''; + + print ''; + print ''; + + print ''; + print ''; + print ''; + } +?> +
'; + print substr($commit['time'], 0, 10); + print ''; + print anchor ( + "/source/revision/{$commit['repo']}/{$xdot}/{$commit['rev']}", + $commit['rev']); + print ''; + print htmlspecialchars ($commit['author']); + print '
'; + $sm = strtok (trim ($commit['message']), "\r\n"); + print htmlspecialchars ($sm); + print '
+
+ diff --git a/codepot/src/codepot/views/projectbar.php b/codepot/src/codepot/views/projectbar.php index 1b66becb..d263b995 100644 --- a/codepot/src/codepot/views/projectbar.php +++ b/codepot/src/codepot/views/projectbar.php @@ -5,7 +5,7 @@ function show_projectbar ($con, $site, $project, $pageid, $ctxmenuitems) { print "
"; - if (isset($project)) print $project->id; + if (isset($project)) print $project->name; else if (isset($site) && $site->name != '') print htmlspecialchars($site->name); else print htmlspecialchars(CODEPOT_DEFAULT_BANNER); diff --git a/codepot/src/config.php.in b/codepot/src/config.php.in index 7b812b3f..ddc45c3a 100644 --- a/codepot/src/config.php.in +++ b/codepot/src/config.php.in @@ -26,9 +26,10 @@ function load_ini ($file) array ('svn_base_url', 'string', 'http://${SERVER_NAME}:${SERVER_PORT}/svn'), array ('login_model', 'string', 'LdapLoginModel'), - array ('sysadmin_userid', 'string', ''), + array ('sysadmin_userids', 'string', ''), array ('max_upload_size', 'string', '10000'), // kbytes array ('max_svn_commits', 'integer', 10), + array ('max_svn_commits_in_project', 'integer', 5), array ('max_latest_projects', 'integer', 10), array ('database_username', 'string', ''), diff --git a/codepot/src/css/common.css b/codepot/src/css/common.css index f07202da..4771bf64 100644 --- a/codepot/src/css/common.css +++ b/codepot/src/css/common.css @@ -113,7 +113,6 @@ body { .content .mainarea { padding: 0.2em 0em 0.2em 0em; - min-height: 30em; } .content .mainarea .title { @@ -377,6 +376,7 @@ pre.prettyprint .nocode a:hover { } .content .footer { + clear: both; padding: 0.3em 0.5em 0.3em 0.5em; font-size: .8em; font-weight: bold; diff --git a/codepot/src/css/project.css b/codepot/src/css/project.css index ae28e1d1..931109cc 100644 --- a/codepot/src/css/project.css +++ b/codepot/src/css/project.css @@ -22,6 +22,23 @@ 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