Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/site/app/controllers/components/editors.php
blob: 0abb3430e229ba03bf43013ec2e24e16e789b983 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is addons.mozilla.org site.
 *
 * The Initial Developer of the Original Code is
 * Justin Scott <fligtar@gmail.com>.
 * Portions created by the Initial Developer are Copyright (C) 2006
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */
class EditorsComponent extends Object {
    var $controller;
    
   /**
    * Save a reference to the controller on startup
    * @param object &$controller the controller using this component
    */
    function startup(&$controller) {
        $this->controller =& $controller;
    }
    
   /**
    * Process review for a nominated add-on.
    * Update add-on, approval, and file info and send emails
    * @param array $addon add-on information
    * @param array $data POST data
    */
    function reviewNominatedAddon($addon, $data) {
        //Make sure add-on is actually nominated
        if ($addon['Addon']['status'] != STATUS_NOMINATED) {
            $this->controller->Errors->addError(_('This add-on has not been nominated'));
            return false;
        }
        
        $this->controller->Addon->id = $addon['Addon']['id'];
        $addonData = array();
        
        //Get most recent version
        $version = $this->controller->Version->findByAddon_id($this->controller->Addon->id, null, 'Version.created DESC');

        if ($data['Approval']['ActionField'] == 'public') {
            $addonData['status'] = STATUS_PUBLIC;
            $addonData['higheststatus'] = STATUS_PUBLIC;
        }
        elseif ($data['Approval']['ActionField'] == 'sandbox') {
            $addonData['status'] = STATUS_SANDBOX;
        }
        elseif ($data['Approval']['ActionField'] == 'superreview') {
            $addonData['adminreview'] = 1;
            $addonData['status'] = STATUS_NOMINATED;
        }
        else {
            $this->controller->Error->addError(_('Please select a review action.'));
            return false;
        }
        
        if (empty($data['Approval']['comments'])) {
            $this->controller->Error->addError(_('Please enter review comments.'));
            return false;
        }
        
        $session = $this->controller->Session->read('User');
        
        $approvalData = array('user_id' => $session['id'],
                              'reviewtype' => 'nominated',
                              'action' => $addonData['status'],
                              'addon_id' => $this->controller->Addon->id,
                              'comments' => $data['Approval']['comments'],
                              'file_id' => $version['File'][0]['id']
                             );
        
        if ($this->controller->Error->noErrors()) {
            if ($data['Approval']['ActionField'] == 'public') {
                //Make files of most recent version public
                if (!empty($version['File'])) {
                    foreach ($version['File'] as $file) {
                        $this->controller->File->id = $file['id'];
                        $fileData = array('status' => STATUS_PUBLIC, 'datestatuschanged' => $this->controller->Amo->getNOW());
                        $this->controller->File->save($fileData);
                        
                        // Move to public rsync repo
                        $file = $this->controller->File->read();
                        $this->controller->Amo->copyFileToPublic($approvalData['addon_id'], $file['File']['filename']);
                    }
                }
            }
            
            $this->controller->Approval->save($approvalData);
            $this->controller->Addon->save($addonData);
        }
        else {
            return false;
        }
        
        if (!empty($addon['User'])) {
            foreach ($addon['User'] as $user) {
                $authors[] = $user['email'];
            }
        }
        
        $emailInfo = array('name' => $addon['Translation']['name']['string'],
                           'id' => $this->controller->Addon->id,
                           'reviewer' => $session['firstname'].' '.$session['lastname'],
                           'email' => implode(', ', $authors),
                           'comments' => $data['Approval']['comments'],
                           'version' => !empty($version) ? $version['Version']['version'] : ''
                           );
        
        $this->controller->set('info', $emailInfo);
        
        if ($data['Approval']['ActionField'] != 'superreview') {
            $this->controller->Email->template = 'email/nominated/'.$data['Approval']['ActionField'];
            $this->controller->Email->to = $emailInfo['email'];
            $this->controller->Email->subject = sprintf(_('Sugar Labs Activities: %s Nomination'), $emailInfo['name']);
        }
        else {
            $this->controller->Email->template = 'email/superreview';
            $this->controller->Email->to = ADMIN_EMAIL;
            //Doesn't need to be localized
            $this->controller->Email->subject = "Super-review requested: {$emailInfo['name']}";  
        }
        $result = $this->controller->Email->send();
        
        return true;
    }

   /**
    * Process review for pending files
    * Update approval and file info and send emails
    * @param array $addon add-on information
    * @param array $data POST data
    */
    function reviewPendingFiles($addon, $data) {
        if (empty($data['Approval']['File'])) {
            $this->controller->addError(_('Please select at least one file to review.'));
            return false;
        }
            
        $this->controller->Addon->id = $addon['Addon']['id'];
        $fileData = array('datestatuschanged' => $this->controller->Amo->getNOW());

        //Get most recent version
        $version = $this->controller->Version->findByAddon_id($this->controller->Addon->id, null, 'Version.created DESC');

        if ($data['Approval']['ActionField'] == 'public') {
            $fileData['status'] = STATUS_PUBLIC;
        }
        elseif ($data['Approval']['ActionField'] == 'sandbox') {
            $fileData['status'] = STATUS_SANDBOX;
        }
        elseif ($data['Approval']['ActionField'] == 'superreview') {
            $addonData = array('adminreview' => 1);
            $fileData['status'] = STATUS_PENDING;
        }
        else {
            $this->controller->Error->addError(_('Please select a review action.'));
            return false;
        }
        
        if (empty($data['Approval']['comments'])) {
            $this->controller->Error->addError(_('Please enter review comments.'));
            return false;
        }

        if (empty($data['Approval']['applications'])) {
            $this->controller->Error->addError(_('Please enter the tested applications.'));
            return false;
        }
        
        if (empty($data['Approval']['os'])) {
            $this->controller->Error->addError(_('Please enter the tested operating systems.'));
            return false;
        }
        
        $session = $this->controller->Session->read('User');
        $platforms = $this->controller->Amo->getPlatformName();
        $files = array();
        
        // Loop through checked files
        foreach ($data['Approval']['File'] as $file_id) {
            if ($file_id > 0) {
                $this->controller->File->id = $file_id;
                $file = $this->controller->File->read();
                
                // Make sure file is pending review
                if ($file['File']['status'] != STATUS_PENDING) {
                    $this->controller->Error->addError(_('File not pending review.'));
                    return false;
                }
                
                $approvalData = array('user_id' => $session['id'],
                                      'reviewtype' => 'pending',
                                      'action' => $fileData['status'],
                                      'addon_id' => $this->controller->Addon->id,
                                      'file_id' => $file_id,
                                      'comments' => $data['Approval']['comments'],
                                      'os' => $data['Approval']['os'],
                                      'applications' => $data['Approval']['applications']
                                     );
                
                if ($this->controller->Error->noErrors()) {
                    // Save approval log and new file status
                    $this->controller->Approval->save($approvalData);
                    $this->controller->File->save($fileData);
                    
                    // Move to public rsync repo
                    if ($fileData['status'] == STATUS_PUBLIC) {
                        $this->controller->Amo->copyFileToPublic($approvalData['addon_id'], $file['File']['filename']);
                    }
                    
                    if (!empty($addonData)) {
                        $this->controller->Addon->save($addonData);
                    }
                    
                    $files[] = $addon['Translation']['name']['string'].' '.$version['Version']['version'].' - '.$platforms[$file['File']['platform_id']];
                }
                else {
                    return false;
                }
            }
        }
        
        if (!empty($addon['User'])) {
            foreach ($addon['User'] as $user) {
                $authors[] = $user['email'];
            }
        }
        
        $emailInfo = array('name' => $addon['Translation']['name']['string'],
                           'id' => $this->controller->Addon->id,
                           'reviewer' => $session['firstname'].' '.$session['lastname'],
                           'email' => implode(', ', $authors),
                           'comments' => $data['Approval']['comments'],
                           'os' => $data['Approval']['os'],
                           'apps' => $data['Approval']['applications'],
                           'version' => !empty($version) ? $version['Version']['version'] : '',
                           'files' => $files
                           );
        
        $this->controller->set('info', $emailInfo);
        
        if ($data['Approval']['ActionField'] != 'superreview') {
            $this->controller->Email->template = 'email/pending/'.$data['Approval']['ActionField'];
            $this->controller->Email->to = $emailInfo['email'];
            $this->controller->Email->subject = sprintf(_('Sugar Labs Activities: %s %s'), $emailInfo['name'], $emailInfo['version']);
        }
        else {
            $this->controller->Email->template = 'email/superreview';
            $this->controller->Email->to = ADMIN_EMAIL;
            //Doesn't need to be localized
            $this->controller->Email->subject = "Super-review requested: {$emailInfo['name']}";  
        }
        $result = $this->controller->Email->send();
        
        return true;
    }
    
    /**
     * Jump to specific item in queue
     * redirects to review page if item was found, to queue otherwise
     * @param string $listtype 'nominated' or 'pending'
     * @param int $rank list entry to jump to
     * @return void
     */
    function redirectByQueueRank($listtype, $rank) {
        switch($listtype) {
        case 'nominated':
            $addon = $this->controller->Addon->findAll(array('Addon.status' => STATUS_NOMINATED),
                array('Addon.id'), null, 1, $rank);
            if (!empty($addon)) {
                $addon = $this->controller->Addon->getAddon($addon[0]['Addon']['id'], array('latest_version'));
                if (!empty($addon['Version'])) {
                    $this->controller->redirect("/editors/review/{$addon['Version'][0]['id']}?num={$rank}");
                    return;
                }
            }
            break;
        
        case 'pending':
            $file = $this->controller->File->findAll(array('File.status'=>STATUS_PENDING),
                array('File.version_id'), null, 1, $rank);
            if (!empty($file)) {
                $this->controller->redirect("/editors/review/{$file[0]['File']['version_id']}?num={$rank}");
                return;
            }
            break;
        
        default:
            return false;
        }
        
        // if we did not find anything, redirect to queue
        $this->controller->redirect("/editors/queue/{$listtype}");
    }
}
?>