Пример #1
0
 /**
  * Control the access rights to the repository.
  *
  * @param string Username
  * @param string Path including the possible .git
  * @param string Type of access. 'readonly' or ('writable')
  * @return mixed False or array(base_git_reps, relative path to repo)
  */
 public function haveAccess($username, $path, $mode = 'writable')
 {
     if ('.git' == substr($path, -4)) {
         $path = substr($path, 0, -4);
     }
     $sql = new Pluf_SQL('shortname=%s', array($path));
     $projects = Pluf::factory('IDF_Project')->getList(array('filter' => $sql->gen()));
     if ($projects->count() != 1) {
         return false;
     }
     $project = $projects[0];
     $conf = new IDF_Conf();
     $conf->setProject($project);
     $scm = $conf->getVal('scm', 'git');
     if ($scm != 'git') {
         return false;
     }
     $sql = new Pluf_SQL('login=%s', array($username));
     $users = Pluf::factory('Pluf_User')->getList(array('filter' => $sql->gen()));
     if ($users->count() != 1 or !$users[0]->active) {
         return false;
     }
     $user = $users[0];
     $request = new StdClass();
     $request->user = $user;
     $request->conf = $conf;
     $request->project = $project;
     if (true === IDF_Precondition::accessSource($request)) {
         if ($mode == 'readonly') {
             return array(Pluf::f('idf_plugin_syncgit_base_repositories', '/home/git/repositories'), $project->shortname);
         }
         if (true === IDF_Precondition::projectMemberOrOwner($request)) {
             return array(Pluf::f('idf_plugin_syncgit_base_repositories', '/home/git/repositories'), $project->shortname);
         }
     }
     return false;
 }
Пример #2
0
 public function view($request, $match)
 {
     $prj = $request->project;
     $upload = Pluf_Shortcuts_GetObjectOr404('IDF_Upload', $match[2]);
     $prj->inOr404($upload);
     $title = sprintf(__('Download %s'), $upload->summary);
     $form = false;
     $ptags = self::getDownloadTags($prj);
     $dtag = array_pop($ptags);
     // The last tag is the deprecated tag.
     $tags = $upload->get_tags_list();
     $deprecated = Pluf_Model_InArray($dtag, $tags);
     if ($request->method == 'POST' and true === IDF_Precondition::projectMemberOrOwner($request)) {
         $form = new IDF_Form_UpdateUpload($request->POST, array('project' => $prj, 'upload' => $upload, 'user' => $request->user));
         if ($form->isValid()) {
             $upload = $form->save();
             $urlfile = Pluf_HTTP_URL_urlForView('IDF_Views_Download::view', array($prj->shortname, $upload->id));
             $request->user->setMessage(sprintf(__('The file <a href="%1$s">%2$s</a> has been updated.'), $urlfile, Pluf_esc($upload->file)));
             $url = Pluf_HTTP_URL_urlForView('IDF_Views_Download::index', array($prj->shortname));
             return new Pluf_HTTP_Response_Redirect($url);
         }
     } elseif (true === IDF_Precondition::projectMemberOrOwner($request)) {
         $form = new IDF_Form_UpdateUpload(null, array('upload' => $upload, 'project' => $prj, 'user' => $request->user));
     }
     return Pluf_Shortcuts_RenderToResponse('idf/downloads/view.html', array('file' => $upload, 'deprecated' => $deprecated, 'tags' => $tags, 'auto_labels' => self::autoCompleteArrays($prj), 'page_title' => $title, 'form' => $form), $request);
 }