Annotation of FreeBSD/tinderbox/webui/module/moduleTinderd.php, revision 1.1.1.1.2.1
1.1 as 1: <?php
2: #-
3: # Copyright (c) 2005 Oliver Lehmann <oliver@FreeBSD.org>
4: # All rights reserved.
5: #
6: # Redistribution and use in source and binary forms, with or without
7: # modification, are permitted provided that the following conditions
8: # are met:
9: # 1. Redistributions of source code must retain the above copyright
10: # notice, this list of conditions and the following disclaimer
11: # 2. Redistributions in binary form must reproduce the above copyright
12: # notice, this list of conditions and the following disclaimer in the
13: # documentation and/or other materials provided with the distribution.
14: #
15: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18: # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25: # SUCH DAMAGE.
26: #
1.1.1.1.2.1! as 27: # $Paefchen$
1.1 as 28: # $MCom: portstools/tinderbox/webui/module/moduleTinderd.php,v 1.9 2007/10/13 02:28:48 ade Exp $
29: #
30:
31: class moduleTinderd extends module {
1.1.1.1.2.1! as 32: private $moduleBuilds = null;
! 33: private $moduleUsers = null;
1.1 as 34:
1.1.1.1.2.1! as 35: public function __construct() {
! 36: parent::__construct();
! 37: $this->moduleBuilds = new moduleBuilds;
! 38: $this->moduleUsers = new moduleUsers;
1.1 as 39: }
40:
1.1.1.1.2.1! as 41: public function checkQueueEntryAccess( $entry, $mode ) {
1.1 as 42:
43: if( $this->moduleUsers->checkWwwAdmin() ) {
44: return true;
45: }
46:
47: switch ( $mode ) {
48: case 'list': return true;
49: break;
50: case 'add': if( $this->moduleUsers->checkPermAddQueue( 'builds', $this->build_id ) ) {
51: return true;
52: } else {
53: return false;
54: }
55: break;
56: case 'modify': if( $entry->getUserId() == $this->moduleUsers->get_id() &&
57: $this->moduleUsers->checkPermModifyOwnQueue( 'builds', $this->build_id ) ) {
58: return true;
59: } elseif( $entry->getUserId() != $this->moduleUsers->get_id() &&
60: $this->moduleUsers->checkPermModifyOtherQueue( 'builds', $this->build_id ) ) {
61: return true;
62: } else {
63: return false;
64: }
65: break;
66: case 'delete': if( $entry->getUserId() == $this->moduleUsers->get_id() &&
67: $this->moduleUsers->checkPermDeleteOwnQueue( 'builds', $this->build_id ) ) {
68: return true;
69: } elseif( $entry->getUserId() != $this->moduleUsers->get_id() &&
70: $this->moduleUsers->checkPermDeleteOtherQueue( 'builds', $this->build_id ) ) {
71: return true;
72: } else {
73: return false;
74: }
75: break;
76: case 'priolower5': if( $this->moduleUsers->checkPermPrioLower5( 'builds', $this->build_id ) ) {
77: return true;
78: } else {
79: return false;
80: }
81: break;
82: default:
83: return false;
84: }
85:
86: }
87:
1.1.1.1.2.1! as 88: public function create_prio_array( $entry ) {
1.1 as 89: if( $this->checkQueueEntryAccess( $entry, 'priolower5' ) ) {
90: $i = 1;
91: } else {
92: if( $entry->getPriority() < 5 ) {
93: $prio[] = $entry->getPriority();
94: }
95: $i = 5;
96: }
97:
98: for( ; $i <= 10; $i++ ) {
99: $prio[] = $i;
100: }
101:
102: return $prio;
103: }
104:
1.1.1.1.2.1! as 105: public function list_tinderd_queue( $build_id ) {
1.1 as 106:
107: if( !$this->moduleUsers->is_logged_in() ) {
108: return $this->template_parse( 'please_login.tpl' );
109: } else {
110: $this->template_assign( 'all_builds', $this->moduleBuilds->get_all_builds() );
111: $this->template_assign( 'build_id', $build_id );
112: $this->template_assign( 'new_build_id', '' );
113: $this->template_assign( 'new_priority', '' );
114: $this->template_assign( 'new_port_directory', '' );
115: $this->template_assign( 'new_email_on_completion', '' );
116:
117: if( !empty( $build_id ) ) {
118: $builds[0] = $this->TinderboxDS->getBuildById( $build_id );
119: } else {
120: $builds = $this->TinderboxDS->getAllBuilds();
121: }
122:
123: $i = 0;
124: foreach( $builds as $build ) {
125:
126: $this->build_id = $build->getId();
127:
128: if( is_object( $build ) ) {
129: $build_ports_queue_entries = $this->TinderboxDS->getBuildPortsQueueEntries( $this->build_id );
130: if( is_array( $build_ports_queue_entries ) && count( $build_ports_queue_entries ) > 0 ) {
131: foreach( $build_ports_queue_entries as $build_ports_queue_entry ) {
132: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'list' ) ) {
133: switch( $build_ports_queue_entry->getStatus() ) {
134: case 'ENQUEUED':
135: $status_field_class = 'queue_entry_enqueued';
136: break;
137: case 'PROCESSING':
138: $status_field_class = 'queue_entry_processing';
139: break;
140: case 'SUCCESS':
141: $status_field_class = 'queue_entry_success';
142: break;
143: case 'FAIL':
144: $status_field_class = 'port_fail';
145: break;
146: }
147: $entries[$i] = array( 'entry_id' => $build_ports_queue_entry->getBuildPortsQueueId(),
148: 'directory' => $build_ports_queue_entry->getPortDirectory(),
149: 'priority' => $build_ports_queue_entry->getPriority(),
150: 'build' => $build_ports_queue_entry->getBuildName(),
151: 'user' => $build_ports_queue_entry->getUserName(),
152: 'all_prio' => $this->create_prio_array( $build_ports_queue_entry ),
153: 'email_on_completion' => $build_ports_queue_entry->getEmailOnCompletion(),
154: 'status_field_class' => $status_field_class);
155:
156: }
157: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'modify' ) ) {
158: $entries[$i]['modify'] = 1;
159: }
160: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'delete' ) ) {
161: $entries[$i]['delete'] = 1;
162: }
163: $i++;
164: }
165: }
166: }
167: }
168:
169: if( !empty($entries) && is_array( $entries ) && count( $entries ) > 0 ) {
170: $this->template_assign( 'entries', $entries );
171: $this->template_assign( 'no_list', false );
172: } else {
173: $this->template_assign( 'no_list', true );
174: }
175:
176: $this->template_assign( 'all_prio', array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ) );
177: $this->template_assign( 'new_priority', 10 );
178:
179: return $this->template_parse( 'list_tinderd_queue.tpl' );
180: }
181: }
182:
1.1.1.1.2.1! as 183: public function change_tinderd_queue( $action, $entry_id, $build_id, $priority, $email_on_completion ) {
1.1 as 184:
185: if( !$this->moduleUsers->is_logged_in() ) {
186: return $this->template_parse( 'please_login.tpl' );
187: } else {
188: $build_ports_queue_entry = $this->TinderboxDS->getBuildPortsQueueEntryById( $entry_id );
189: $this->build_id = $build_ports_queue_entry->getBuildId();
190: if( $action == 'delete' ) {
191: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'delete' ) ) {
192: $this->TinderboxDS->deleteBuildPortsQueueEntry( $entry_id );
193: } else {
194: $this->TinderboxDS->addError( build_ports_queue_not_allowed_to_delete );
195: }
196: } elseif( $action == 'reset status' ) {
197: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'modify' ) ) {
198: $build_ports_queue_entry->resetStatus();
199: $this->TinderboxDS->updateBuildPortsQueueEntry( $build_ports_queue_entry );
200: } else {
201: $this->TinderboxDS->addError( build_ports_queue_not_allowed_to_modify );
202: }
203: } elseif( $action == 'save' ) {
204: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'modify' ) ) {
205: $this->build_id = $build_id;
206: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'modify' ) ) {
207: if( $build_ports_queue_entry->getPriority() != $priority && $priority < 5 && !$this->checkQueueEntryAccess( $build_ports_queue_entry, 'priolower5' ) ) {
208: $this->TinderboxDS->addError( build_ports_queue_priority_to_low );
209: } else {
210: $build_ports_queue_entry->setBuildId( $build_id );
211: $build_ports_queue_entry->setPriority( $priority );
212: $build_ports_queue_entry->setEmailOnCompletion( $email_on_completion );
213: $this->TinderboxDS->updateBuildPortsQueueEntry( $build_ports_queue_entry );;
214: }
215: } else {
216: $this->TinderboxDS->addError( build_ports_queue_not_allowed_to_modify );
217: }
218: } else {
219: $this->TinderboxDS->addError( build_ports_queue_not_allowed_to_modify );
220: }
221: }
222: }
223: return;
224: }
225:
1.1.1.1.2.1! as 226: public function add_tinderd_queue( $action, $build_id, $priority, $port_directory, $email_on_completion ) {
1.1 as 227:
228: if( !$this->moduleUsers->is_logged_in() ) {
229: return $this->template_parse( 'please_login.tpl' );
230: } else {
231: if( empty( $build_id ) || empty( $priority ) || empty( $port_directory ) ) {
232: $this->TinderboxDS->addError( mandatory_input_fields_are_empty );
233: } else {
234: $build_ports_queue_entry = $this->TinderboxDS->createBuildPortsQueueEntry( $build_id, $priority, $port_directory, $this->moduleUsers->get_id(), $email_on_completion );
235: $this->build_id = $build_id;
236: if( $action == 'add' ) {
237: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'add' ) ) {
238: if( $priority < 5 && !$this->checkQueueEntryAccess( $entry, 'priolower5' ) ) {
239: $this->template_assign( 'new_build_id', $build_id );
240: $this->template_assign( 'new_priority', $priority );
241: $this->template_assign( 'new_port_directory', $port_directory );
242: $this->template_assign( 'new_email_on_completion', $email_on_completion );
243: $this->TinderboxDS->addError( build_ports_queue_priority_to_low );
244: } else {
245: $this->TinderboxDS->addBuildPortsQueueEntry( $build_ports_queue_entry );
246: }
247: } else {
248: $this->template_assign( 'new_build_id', $build_id );
249: $this->template_assign( 'new_priority', $priority );
250: $this->template_assign( 'new_port_directory', $port_directory );
251: $this->TinderboxDS->addError( build_ports_queue_not_allowed_to_add );
252: }
253: }
254: }
255: }
256: return;
257: }
258: }
1.1.1.1.2.1! as 259:
1.1 as 260: ?>