public function testGetMailHookConfig()
 {
     $prj = new MockProject($this);
     $prj->setReturnValue('getUnixName', 'project1');
     $prj->setReturnValue('getId', 101);
     // ShowRev
     $repo = new GitRepository();
     $repo->setId(5);
     $repo->setProject($prj);
     $repo->setName('test_default');
     $this->assertIdentical(file_get_contents($this->_fixDir . '/gitolite-mail-config/mailhook-rev.txt'), $this->project_serializer->fetchMailHookConfig($prj, $repo));
     // ShowRev + Mail
     $repo = new GitRepository();
     $repo->setId(5);
     $repo->setProject($prj);
     $repo->setName('test_default');
     $repo->setNotifiedMails(array('*****@*****.**', '*****@*****.**'));
     $this->assertIdentical(file_get_contents($this->_fixDir . '/gitolite-mail-config/mailhook-rev-mail.txt'), $this->project_serializer->fetchMailHookConfig($prj, $repo));
     // ShowRev + Mailprefix
     $repo = new GitRepository();
     $repo->setId(5);
     $repo->setProject($prj);
     $repo->setName('test_default');
     $repo->setNotifiedMails(array('*****@*****.**', '*****@*****.**'));
     $repo->setMailPrefix('[KOIN] ');
     $this->assertIdentical(file_get_contents($this->_fixDir . '/gitolite-mail-config/mailhook-rev-mail-prefix.txt'), $this->project_serializer->fetchMailHookConfig($prj, $repo));
     // ShowRev + Mailprefix
     $repo = new GitRepository();
     $repo->setId(5);
     $repo->setProject($prj);
     $repo->setName('test_default');
     $repo->setNotifiedMails(array('*****@*****.**', '*****@*****.**'));
     $repo->setMailPrefix('["\\_o<"] \\t');
     $this->assertIdentical(file_get_contents($this->_fixDir . '/gitolite-mail-config/mailhook-rev-mail-prefix-quote.txt'), $this->project_serializer->fetchMailHookConfig($prj, $repo));
 }
 public function process()
 {
     $parameters = $this->getParametersAsArray();
     //repo id
     $repositoryId = '';
     if (!empty($parameters[0])) {
         $repositoryId = $parameters[0];
     } else {
         $this->error('Missing argument repository id');
         return false;
     }
     //repo access
     $repositoryAccess = '';
     if (!empty($parameters[1])) {
         $repositoryAccess = $parameters[1];
     } else {
         $this->error('Missing argument repository access');
         return false;
     }
     //save
     $repository = new GitRepository();
     $repository->setId($repositoryId);
     try {
         $repository->load();
         $repository->setAccess($repositoryAccess);
         $repository->changeAccess();
     } catch (GitDaoException $e) {
         $this->error($e->getMessage());
         return false;
     }
     $this->done();
 }
 /**
  * Wrapper for GitRepository for unit testing purpose
  *
  * @param array $row data of the repository to instantiate
  *
  * @return GitRepository
  */
 protected function getRepository($row)
 {
     $r = new GitRepository();
     $r->setId($row[GitDao::REPOSITORY_ID]);
     $r->load();
     return $r;
 }
示例#4
0
 public function testAddMailingShowRev()
 {
     $GLOBALS['sys_https_host'] = 'codendi.org';
     $prj = new MockProject($this);
     $prj->setReturnValue('getId', 1750);
     $repo = new GitRepository();
     $repo->setPath('prj/repo.git');
     $repo->setName('repo');
     $repo->setProject($prj);
     $repo->setId(290);
     $driver = new MockGitDriver($this);
     $driver->expectOnce('setConfig', array('/var/lib/codendi/gitroot/prj/repo.git', 'hooks.showrev', "t=%s; git show --name-status --pretty='format:URL:    https://codendi.org/plugins/git/index.php/1750/view/290/?p=repo.git&a=commitdiff&h=%%H%%nAuthor: %%an <%%ae>%%nDate:   %%aD%%n%%n%%s%%n%%b' \$t"));
     $backend = new GitBackendTestVersion($this);
     $backend->setUp($this->url_manager);
     $backend->setGitRootPath(Git_Backend_Interface::GIT_ROOT_PATH);
     $backend->setReturnValue('getDriver', $driver);
     $backend->setUpMailingHook($repo);
 }
示例#5
0
 function permission_user_allowed_to_change($params)
 {
     if (!$params['allowed']) {
         if (!$this->_cached_permission_user_allowed_to_change) {
             if (in_array($params['permission_type'], array('PLUGIN_GIT_READ', 'PLUGIN_GIT_WRITE', 'PLUGIN_GIT_WPLUS'))) {
                 require_once 'GitRepository.class.php';
                 $repository = new GitRepository();
                 $repository->setId($params['object_id']);
                 try {
                     $repository->load();
                     //Only project admin can update perms of project repositories
                     //Only repo owner can update perms of personal repositories
                     $user = UserManager::instance()->getCurrentUser();
                     $this->_cached_permission_user_allowed_to_change = $repository->belongsTo($user) || $user->isMember($repository->getProjectId(), 'A');
                 } catch (Exception $e) {
                     // do nothing
                 }
             }
         }
         $params['allowed'] = $this->_cached_permission_user_allowed_to_change;
     }
 }
示例#6
0
    /**
     * LIST OF MAILS TO NOTIFY
     */
    protected function _listOfMails()
    {
        $r = new GitRepository();
        $r->setId($this->repoId);
        $r->load();
        $mails = $r->getNotifiedMails();
        ?>
<h3><?php 
        echo $this->getText('notified_mails_title');
        ?>
</h3>
    <?php 
        if (!empty($mails)) {
            ?>
<form id="add_user_form" action="/plugins/git/" method="POST">
    <input type="hidden" id="action" name="action" value="remove_mail" />
    <input type="hidden" id="group_id" name="group_id" value="<?php 
            echo $this->groupId;
            ?>
" />
    <input type="hidden" id="repo_id" name="repo_id" value="<?php 
            echo $this->repoId;
            ?>
" />
    <table>
        <?php 
            $i = 0;
            foreach ($mails as $mail) {
                echo '<tr class="' . html_get_alt_row_color(++$i) . '">';
                echo '<td>' . $mail . '</td>';
                echo '<td>';
                echo '<input type="checkbox" name="mail[]" value="' . $this->HTMLPurifier->purify($mail) . '" />';
                echo '</a>';
                echo '</td>';
                echo '</tr>';
            }
            ?>
    </table>
    <input type="submit" value="<?php 
            echo $GLOBALS['Language']->getText('global', 'btn_delete');
            ?>
" />
</form>
        <?php 
        } else {
            ?>
<h4><?php 
            echo $this->getText('add_mail_existing');
            ?>
 </h4>
<?php 
        }
    }
示例#7
0
 /**
  * Internal method called by SystemEvent_PROJECT_IS_PRIVATE
  * @param <type> $projectId
  * @param <type> $isPublic
  * @return <type>
  */
 public static function changeProjectRepositoriesAccess($projectId, $isPrivate)
 {
     //if the project is private, then no changes may be applied to repositories,
     //in other words only if project is set to private, its repositories have to be set to private
     if (empty($isPrivate)) {
         return;
     }
     $dao = new GitDao();
     $repositories = $dao->getProjectRepositoryList($projectId);
     if (empty($repositories)) {
         return false;
     }
     foreach ($repositories as $repoId => $repoData) {
         $r = new GitRepository();
         $r->setId($repoId);
         if (!$r->exists()) {
             continue;
         }
         $newAccess = !empty($isPrivate) ? GitRepository::PRIVATE_ACCESS : GitRepository::PUBLIC_ACCESS;
         if ($r->getAccess() == $newAccess) {
             continue;
         }
         $r->setAccess($newAccess);
         $r->changeAccess();
         unset($r);
     }
 }
示例#8
0
 /**
  * @deprecated Should use GitRepository::getInstanceFrom row instead.
  * @param GitRepository $repository
  * @param type $result
  */
 public function hydrateRepositoryObject(GitRepository $repository, $result)
 {
     $repository->setName($result[self::REPOSITORY_NAME]);
     $repository->setPath($result[self::REPOSITORY_PATH]);
     $repository->setId($result[self::REPOSITORY_ID]);
     $repository->setDescription($result[self::REPOSITORY_DESCRIPTION]);
     $repository->setParentId($result[self::REPOSITORY_PARENT]);
     $project = ProjectManager::instance()->getProject($result[self::FK_PROJECT_ID]);
     $repository->setProject($project);
     $repository->setCreationDate($result[self::REPOSITORY_CREATION_DATE]);
     $user = UserManager::instance()->getUserById($result[self::REPOSITORY_CREATION_USER_ID]);
     $repository->setCreator($user);
     $repository->setIsInitialized($result[self::REPOSITORY_IS_INITIALIZED]);
     $repository->setDeletionDate($result[self::REPOSITORY_DELETION_DATE]);
     $repository->setAccess($result[self::REPOSITORY_ACCESS]);
     $repository->setMailPrefix($result[self::REPOSITORY_MAIL_PREFIX]);
     $repository->setBackendType($result[self::REPOSITORY_BACKEND_TYPE]);
     $repository->setNamespace($result[self::REPOSITORY_NAMESPACE]);
     $repository->setBackupPath($result[self::REPOSITORY_BACKUP_PATH]);
     $repository->setScope($result[self::REPOSITORY_SCOPE]);
     $repository->setRemoteServerId($result[self::REMOTE_SERVER_ID]);
     $repository->setRemoteServerDisconnectDate($result[self::REMOTE_SERVER_DISCONNECT_DATE]);
     $repository->setRemoteProjectDeletionDate($result[self::REMOTE_SERVER_DELETE_DATE]);
     $repository->setRemoteServerMigrationStatus($result[self::REMOTE_SERVER_MIGRATION_STATUS]);
     $repository->loadNotifiedMails();
     /* Here just for reviewer test, will be replaced by real DB data in a future changeset*/
     $result[self::ENABLE_ONLINE_EDIT] = false;
     if ($result[self::ENABLE_ONLINE_EDIT] && GitConfig::instance()->isOnlineEditEnabled()) {
         $repository->enableOnlineEdit();
     }
 }
示例#9
0
 protected function buildRepositoryFromRow($row, $project, $notification_manager = null)
 {
     $repository_id = $row[GitDao::REPOSITORY_ID];
     $repository = new GitRepository();
     $repository->setId($repository_id);
     $repository->setName($row[GitDao::REPOSITORY_NAME]);
     $repository->setProject($project);
     if (!$notification_manager) {
         $notification_manager = $this->getPostReceiveMailManager();
     }
     $notified_mails = $notification_manager->getNotificationMailsByRepositoryId($repository_id);
     $repository->setNotifiedMails($notified_mails);
     $repository->setMailPrefix($row[GitDao::REPOSITORY_MAIL_PREFIX]);
     $repository->setNamespace($row[GitDao::REPOSITORY_NAMESPACE]);
     return $repository;
 }
示例#10
0
 function permission_user_allowed_to_change($params)
 {
     if (!$params['allowed']) {
         $user = $this->getCurrentUser();
         $project = $this->getProjectManager()->getProject($params['group_id']);
         if ($this->getGitPermissionsManager()->userIsGitAdmin($user, $project)) {
             $this->_cached_permission_user_allowed_to_change = true;
         }
         if (!$this->_cached_permission_user_allowed_to_change) {
             if (in_array($params['permission_type'], array('PLUGIN_GIT_READ', 'PLUGIN_GIT_WRITE', 'PLUGIN_GIT_WPLUS'))) {
                 $repository = new GitRepository();
                 $repository->setId($params['object_id']);
                 try {
                     $repository->load();
                     //Only project admin can update perms of project repositories
                     //Only repo owner can update perms of personal repositories
                     $this->_cached_permission_user_allowed_to_change = $repository->belongsTo($user) || $this->getPermissionsManager()->userIsGitAdmin($user, $project);
                 } catch (Exception $e) {
                     // do nothing
                 }
             }
         }
         $params['allowed'] = $this->_cached_permission_user_allowed_to_change;
     }
 }
 public function process()
 {
     $parameters = $this->getParametersAsArray();
     //print_r($parameters);
     $project = null;
     if (!empty($parameters[0])) {
         $project = $this->getProject($parameters[0]);
     } else {
         $this->error('Missing argument project id');
         return false;
     }
     $repositoryName = '';
     if (!empty($parameters[1])) {
         $repositoryName = $parameters[1];
     } else {
         $this->error('Missing argument repository name');
         return false;
     }
     $parentId = '';
     if (!empty($parameters[2])) {
         $parentId = $parameters[2];
     } else {
         $this->error('Missing argument parent id');
         return false;
     }
     $userId = 0;
     if (!empty($parameters[3])) {
         $userId = $parameters[3];
     } else {
         $this->error('Missing argument user id');
         return false;
     }
     try {
         $repository = new GitRepository();
         $repository->setProject($project);
         $repository->setId($parentId);
         //load before setting creator
         $repository->load();
         $user = null;
         if (!empty($userId)) {
             $user = UserManager::instance()->getUserById($userId);
         }
         if (!empty($user)) {
             $repository->setCreator($user);
         }
         $repository->forkShell($repositoryName);
         $this->done();
     } catch (GitDaoException $e1) {
         $this->error($e1->getMessage());
         return false;
     } catch (GitDriverException $e2) {
         $this->error($e2->getMessage());
         return false;
     } catch (GitBackendException $e3) {
         $this->error($e3->getMessage());
         return false;
     } catch (Exception $e4) {
         $this->error($e4->getMessage());
         return false;
     }
 }
示例#12
0
 /**
  * Gives the parent GitRepository object of this
  * Look into the database
  * @return GitRepository
  */
 public function getParent()
 {
     if (empty($this->parent)) {
         $this->load();
         $parent = new GitRepository();
         $parent->setId($this->parentId);
         if (!$this->getDao()->getProjectRepositoryById($parent)) {
             //no parent or error
             $parent = null;
         } else {
             //there is a parent
             $this->parentId = $parent->getId();
             //not very useful
         }
         $this->parent = $parent;
     }
     return $this->parent;
 }
示例#13
0
 public function hydrateRepositoryObject(GitRepository $repository, $result)
 {
     $repository->setName($result[self::REPOSITORY_NAME]);
     $repository->setPath($result[self::REPOSITORY_PATH]);
     $repository->setId($result[self::REPOSITORY_ID]);
     $repository->setDescription($result[self::REPOSITORY_DESCRIPTION]);
     $repository->setParentId($result[self::REPOSITORY_PARENT]);
     $project = ProjectManager::instance()->getProject($result[self::FK_PROJECT_ID]);
     $repository->setProject($project);
     $repository->setCreationDate($result[self::REPOSITORY_CREATION_DATE]);
     $user = UserManager::instance()->getUserById($result[self::REPOSITORY_CREATION_USER_ID]);
     $repository->setCreator($user);
     $repository->setIsInitialized($result[self::REPOSITORY_IS_INITIALIZED]);
     $repository->setDeletionDate($result[self::REPOSITORY_DELETION_DATE]);
     $repository->setAccess($result[self::REPOSITORY_ACCESS]);
     $repository->setMailPrefix($result[self::REPOSITORY_MAIL_PREFIX]);
     $repository->setBackendType($result[self::REPOSITORY_BACKEND_TYPE]);
     $repository->setNamespace($result[self::REPOSITORY_NAMESPACE]);
     $repository->setScope($result[self::REPOSITORY_SCOPE]);
     $repository->loadNotifiedMails();
 }
 /**
  * Load a repository from its id. Mainly used as a wrapper for tests
  *
  * @param $repositoryId Id of the repository
  *
  * @return GitRepository
  */
 function loadRepositoryFromId($repositoryId)
 {
     $repository = new GitRepository();
     $repository->setId($repositoryId);
     $repository->load();
     return $repository;
 }
示例#15
0
 protected function definePermittedActions($repoId, $user)
 {
     if ($this->user->isMember($this->groupId, 'A') === true) {
         $this->permittedActions = array('index', 'view', 'edit', 'clone', 'add', 'del', 'create', 'confirm_deletion', 'save', 'repo_management', 'mail_prefix', 'add_mail', 'remove_mail', 'fork', 'set_private', 'confirm_private', 'fork_repositories', 'do_fork_repositories', 'view_last_git_pushes');
     } else {
         $this->addPermittedAction('index');
         $this->addPermittedAction('view_last_git_pushes');
         if ($this->user->isMember($this->groupId)) {
             $this->addPermittedAction('fork_repositories');
             $this->addPermittedAction('do_fork_repositories');
         }
         if ($repoId !== 0) {
             $repo = new GitRepository();
             $repo->setId($repoId);
             if ($repo->exists() && $repo->userCanRead($user)) {
                 $this->addPermittedAction('view');
                 $this->addPermittedAction('edit');
                 $this->addPermittedAction('clone');
                 if ($repo->belongsTo($user)) {
                     $this->addPermittedAction('repo_management');
                     $this->addPermittedAction('mail_prefix');
                     $this->addPermittedAction('add_mail');
                     $this->addPermittedAction('remove_mail');
                     $this->addPermittedAction('del');
                     $this->addPermittedAction('confirm_deletion');
                     $this->addPermittedAction('save');
                 }
             }
         }
     }
 }
示例#16
0
 /**
  * This is almost the same test than testAddMailingShowRev but
  * through the higher level setUpRepository.
  * What we want to be sure it that the right repository id is set.
  */
 public function testSetUpRepositoryConfigWithRightRepoId()
 {
     $GLOBALS['sys_https_host'] = 'codendi.org';
     $prj = new MockProject($this);
     $prj->setReturnValue('getId', 1750);
     // Use real git object because we need to store values (id)
     $repo = new GitRepository();
     $repo->setPath('prj/repo.git');
     $repo->setName('repo');
     $repo->setProject($prj);
     $repo->setId(290);
     $dao = new MockGitDao($this);
     $dao->expectOnce('save');
     $dao->setReturnValue('save', 290);
     // The id we expect below
     $driver = new MockGitDriver($this);
     $driver->expectOnce('setConfig', array('/var/lib/codendi/gitroot/prj/repo.git', 'hooks.showrev', "t=%s; git show --name-status --pretty='format:URL:    https://codendi.org/plugins/git/index.php/1750/view/290/?p=repo.git&a=commitdiff&h=%%H%%nAuthor: %%an <%%ae>%%nDate:   %%aD%%n%%n%%s%%n%%b' \$t"));
     $backend = new GitBackend4SetUp($this);
     $backend->setUp($this->url_manager);
     $backend->setGitRootPath(Git_Backend_Interface::GIT_ROOT_PATH);
     $backend->setReturnValue('getDriver', $driver);
     $backend->setReturnValue('getDao', $dao);
     $backend->setUpRepository($repo);
 }