Changeset 294
- Timestamp:
- 02/09/10 12:08:42 (11 years ago)
- Location:
- trunk/server/www/app
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/www/app/controllers/galleries_controller.php
r293 r294 140 140 'contain' => array( 141 141 'Request', 142 'Request.Validator' ,142 'Request.Validator' => array('order' => 'Validator.name ASC'), 143 143 'Request.Job', 144 144 'Request.Job.Application', … … 164 164 $request['Validator'] = $this->Request->Validator->find('all', array( 165 165 'conditions' => array('Validator.parent_id' => $request['id']), 166 'order' => 'Validator.name ASC', 166 167 'recursive' => -1, 167 168 )); … … 176 177 ), 177 178 )); 179 180 // Fix array layout to match a regular query layout 181 foreach ($request['Job'] as &$job) { 182 foreach ($job['Job'] as $attr => $value) { 183 $job[$attr] = $value; 184 } 185 unset($job['Job']); 186 } 178 187 } 179 188 } -
trunk/server/www/app/controllers/requests_controller.php
r292 r294 81 81 'Job.Result.Mimetype', 82 82 'Job.Result.Format', 83 'Job.Result.Validator' ,83 'Job.Result.Validator' => array('order' => 'Validator.name ASC'), 84 84 'Gallery', 85 'Validator' ,85 'Validator' => array('order' => 'Validator.name ASC'), 86 86 )); 87 87 88 88 $request = $this->Request->read(null, $id); 89 if (empty($request) ) {89 if (empty($request) || !$this->Request->checkAccess($this->AuthCert->user('id'), $type, $id)) { 90 90 $this->Session->setFlash(__('Invalid Request.', true)); 91 91 $this->redirect(array('action'=>'add')); 92 92 } 93 93 94 if ($request['Request']['user_id'] == $this->AuthCert->user('id')) { 95 return $request; 96 } 97 98 if ($type == 'read' && !empty($request['Gallery'])) { 99 return $request; 100 } 101 102 $this->Session->setFlash(__('Invalid Request.', true)); 103 $this->redirect(array('action'=>'add')); 94 return $request; 104 95 } 105 96 -
trunk/server/www/app/controllers/results_controller.php
r287 r294 30 30 public $components = array('AuthCert'); 31 31 32 /** @var array Add Result and GalleriesRequest model */ 33 public $uses = array('Result', 'GalleriesRequest'); 34 32 35 /** 33 36 * Set the auth permissions for this controller … … 37 40 { 38 41 parent::beforeFilter(); 39 if (Configure::read('Auth.allowAnonymous')) { 40 $this->AuthCert->allow('view', 'download'); 41 } 42 $this->AuthCert->allow('view', 'download'); 42 43 } 43 44 … … 58 59 59 60 $result = $this->Result->read(null, $id); 60 if ( $result['Job']['Request']['user_id'] != $this->AuthCert->user('id')) {61 if (empty($result) || !$this->Result->checkAccess($this->AuthCert->user('id'), 'read', $id)) { 61 62 $this->Session->setFlash(__('Invalid Result.', true)); 62 63 $this->redirect(array('controller' => 'requests', 'action'=>'add')); -
trunk/server/www/app/models/gallery.php
r293 r294 41 41 'Tree', 42 42 ); 43 44 /** 45 * Check access control for this gallery 46 * @param string $user_id The user ID 47 * @param string $id The gallery ID 48 * @return boolean True or False 49 */ 50 public function checkAccess($user_id, $id = false) 51 { 52 if ($id) { 53 $id = $this->id; 54 } 55 56 if (!$id) { 57 return false; 58 } 59 60 $gallery = $this->find('first', array( 61 'conditions' => array('Gallery.id' => $id), 62 'recursive' => -1, 63 )); 64 65 if (!$gallery) { 66 return false; 67 } 68 69 if ($gallery['Gallery']['user_id'] == $user_id) { 70 return true; 71 } 72 73 if ($this->User->Group->has_member($user_id, $gallery['Gallery']['group_id'])) { 74 return true; 75 } 76 77 return false; 78 } 43 79 44 80 /** -
trunk/server/www/app/models/request.php
r293 r294 75 75 76 76 /** 77 * Check access control for this request 78 * @param string $user_id The user ID 79 * @param string $type "read" or "write" 80 * @param string $id The request ID 81 * @return boolean True or False 82 */ 83 public function checkAccess($user_id, $type = 'read', $id = false) 84 { 85 if (!$id) { 86 $id = $this->id; 87 } 88 89 if (!$id) { 90 return false; 91 } 92 93 $request = $this->find('first', array( 94 'contain' => array('Gallery'), 95 'conditions' => array('Request.id' => $id), 96 )); 97 98 if ($request['Request']['user_id'] == $user_id) { 99 return true; 100 } 101 102 if (isset($request['Gallery']) && !empty($request['Gallery'])) { 103 foreach ($request['Gallery'] as $gallery) { 104 if ($this->Gallery->checkAccess($user_id, $gallery['id'])) { 105 return true; 106 } 107 } 108 109 if ($type == 'read') { 110 return true; 111 } 112 } 113 114 if (Configure::read('Auth.allowAnonymous') && empty($request['Request']['user_id'])) { 115 return true; 116 } 117 118 return false; 119 } 120 121 /** 77 122 * Add an upload to the request 78 123 * … … 162 207 public function addValidators() 163 208 { 209 // First remove any existing validators 210 $this->Validator->deleteAll(array( 211 'Validator.parent_id' => $this->id, 212 )); 213 214 // Add new validators 164 215 $validators = Configure::read('Validator'); 165 216 foreach ($validators as $validator_name => $validator_config) { -
trunk/server/www/app/models/result.php
r293 r294 59 59 ); 60 60 61 /** @var string Use the filename as the distinguising name */ 62 public $displayField = 'filename'; 63 61 64 /** 62 65 * Constructor … … 73 76 } 74 77 75 /** @var string Use the filename as the distinguising name */ 76 public $displayField = 'filename'; 78 /** 79 * Check access control for this result 80 * @param string $user_id The user ID 81 * @param string $type "read" or "write" 82 * @param string $id The result ID 83 * @return boolean True or False 84 */ 85 public function checkAccess($user_id, $type = 'read', $id = false) 86 { 87 if (!$id) { 88 $id = $this->id; 89 } 90 91 if (!$id) { 92 return false; 93 } 94 95 $result = $this->find('first', array( 96 'contain' => array('Job', 'Job.Request'), 97 'conditions' => array('Result.id' => $id), 98 )); 99 100 if (!empty($result)) { 101 return $this->Job->Request->checkAccess($user_id, $type, $result['Job']['Request']['id']); 102 } 103 104 return false; 105 } 77 106 78 107 /** -
trunk/server/www/app/models/testsuite.php
r293 r294 110 110 111 111 $gallery_name = basename($directory); 112 $gallery = $this->Gallery->find(' count', array(112 $gallery = $this->Gallery->find('first', array( 113 113 'conditions' => array( 114 114 'Gallery.parent_id' => $gallery_id, … … 167 167 $gallery = $this->Gallery->read(null, $gallery_id); 168 168 169 // Rename the Fellowship testDoc documents to something more sensible 170 $filename = basename($path); 171 if (strtolower(substr($filename, 0, 8)) == 'testdoc.') { 172 $filename = $gallery['Gallery']['name']; 173 $filename .= strrchr($path, '.'); 174 } 175 169 176 // See if a request exists for this file 170 177 $this->Gallery->Request->bindModel(array('hasOne' => array('GalleriesRequest'))); 171 178 $request = $this->Gallery->Request->find('first', array( 172 179 'conditions' => array( 173 'Request.filename' => basename($path),180 'Request.filename' => $filename, 174 181 'GalleriesRequest.gallery_id' => $gallery_id, 175 182 ), … … 193 200 $this->Gallery->Request->save(); 194 201 195 // Rename the Fellowship testDoc documents to something more sensible196 $filename = basename($path);197 if (strtolower(substr($filename, 0, 8)) == 'testdoc.') {198 $filename = $gallery['Gallery']['name'];199 $filename .= strrchr($path, '.');200 }201 202 202 // Add the file to the request 203 203 if (!$this->Gallery->Request->setFile($path, $filename)) { … … 213 213 214 214 // Schedule the preprocessor for the request 215 //if (!$this->Gallery->Request->defer('run', 'Preprocessor')) {216 //$this->log('Failed to queue the preprocessor for request ' . $this->Gallery->Request->id);217 //}215 if (!$this->Gallery->Request->defer('run', 'Preprocessor')) { 216 $this->log('Failed to queue the preprocessor for request ' . $this->Gallery->Request->id); 217 } 218 218 219 219 // Add the request to the gallery … … 230 230 $this->Gallery->Request->deleteJobs(); 231 231 $this->Gallery->Request->setFile($path); 232 $this->Gallery->Request->set('modified', $stamp); 232 $this->Gallery->Request->set(array( 233 'modified' => filemtime($path), 234 'state' => Request::STATE_PREPROCESSOR_QUEUED, 235 )); 233 236 $this->Gallery->Request->save(); 237 238 // Add Validators to the request 239 $this->Gallery->Request->addValidators(); 240 241 // Schedule the preprocessor for the request 242 if (!$this->Gallery->Request->defer('run', 'Preprocessor')) { 243 $this->log('Failed to queue the preprocessor for request ' . $this->Gallery->Request->id); 244 } 245 246 $this->log(sprintf('Updated request %s "%s"', $request['Request']['id'], $filename), LOG_DEBUG); 234 247 } 235 248 } -
trunk/server/www/app/views/helpers/request_model.php
r276 r294 54 54 return $this->output(sprintf(__('Preprocessor failed with error "%s"', true), $request['Request']['state_info'])); 55 55 case Request::STATE_QUEUED: 56 if (!$request['Request']['expire']) { 57 return $this->output(__('Queued. Never expires', true)); 58 } 56 59 return $this->output(sprintf(__('Queued. Expires in %s', true), $this->Time->relativeTime($request['Request']['expire']))); 57 60 case Request::STATE_FINISHED:
Note: See TracChangeset
for help on using the changeset viewer.