Annotation of FreeBSD/tinderbox2/webui/module/moduleTinderd.php, revision 1.1.2.1
1.1.2.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: #
! 27: # $MCom: portstools/tinderbox/webui/module/moduleTinderd.php,v 1.9 2007/10/13 02:28:48 ade Exp $
! 28: #
! 29:
! 30: require_once 'module/module.php';
! 31: require_once 'module/moduleBuilds.php';
! 32: require_once 'module/moduleUsers.php';
! 33:
! 34: class moduleTinderd extends module {
! 35:
! 36: function moduleTinderd() {
! 37: $this->module();
! 38: $this->moduleBuilds = new moduleBuilds();
! 39: $this->moduleUsers = new moduleUsers();
! 40: }
! 41:
! 42: function checkQueueEntryAccess( $entry, $mode ) {
! 43:
! 44: if( $this->moduleUsers->checkWwwAdmin() ) {
! 45: return true;
! 46: }
! 47:
! 48: switch ( $mode ) {
! 49: case 'list': return true;
! 50: break;
! 51: case 'add': if( $this->moduleUsers->checkPermAddQueue( 'builds', $this->build_id ) ) {
! 52: return true;
! 53: } else {
! 54: return false;
! 55: }
! 56: break;
! 57: case 'modify': if( $entry->getUserId() == $this->moduleUsers->get_id() &&
! 58: $this->moduleUsers->checkPermModifyOwnQueue( 'builds', $this->build_id ) ) {
! 59: return true;
! 60: } elseif( $entry->getUserId() != $this->moduleUsers->get_id() &&
! 61: $this->moduleUsers->checkPermModifyOtherQueue( 'builds', $this->build_id ) ) {
! 62: return true;
! 63: } else {
! 64: return false;
! 65: }
! 66: break;
! 67: case 'delete': if( $entry->getUserId() == $this->moduleUsers->get_id() &&
! 68: $this->moduleUsers->checkPermDeleteOwnQueue( 'builds', $this->build_id ) ) {
! 69: return true;
! 70: } elseif( $entry->getUserId() != $this->moduleUsers->get_id() &&
! 71: $this->moduleUsers->checkPermDeleteOtherQueue( 'builds', $this->build_id ) ) {
! 72: return true;
! 73: } else {
! 74: return false;
! 75: }
! 76: break;
! 77: case 'priolower5': if( $this->moduleUsers->checkPermPrioLower5( 'builds', $this->build_id ) ) {
! 78: return true;
! 79: } else {
! 80: return false;
! 81: }
! 82: break;
! 83: default:
! 84: return false;
! 85: }
! 86:
! 87: }
! 88:
! 89: function create_prio_array( $entry ) {
! 90: if( $this->checkQueueEntryAccess( $entry, 'priolower5' ) ) {
! 91: $i = 1;
! 92: } else {
! 93: if( $entry->getPriority() < 5 ) {
! 94: $prio[] = $entry->getPriority();
! 95: }
! 96: $i = 5;
! 97: }
! 98:
! 99: for( ; $i <= 10; $i++ ) {
! 100: $prio[] = $i;
! 101: }
! 102:
! 103: return $prio;
! 104: }
! 105:
! 106: function list_tinderd_queue( $build_id ) {
! 107:
! 108: if( !$this->moduleUsers->is_logged_in() ) {
! 109: return $this->template_parse( 'please_login.tpl' );
! 110: } else {
! 111: $this->template_assign( 'all_builds', $this->moduleBuilds->get_all_builds() );
! 112: $this->template_assign( 'build_id', $build_id );
! 113: $this->template_assign( 'new_build_id', '' );
! 114: $this->template_assign( 'new_priority', '' );
! 115: $this->template_assign( 'new_port_directory', '' );
! 116: $this->template_assign( 'new_email_on_completion', '' );
! 117:
! 118: if( !empty( $build_id ) ) {
! 119: $builds[0] = $this->TinderboxDS->getBuildById( $build_id );
! 120: } else {
! 121: $builds = $this->TinderboxDS->getAllBuilds();
! 122: }
! 123:
! 124: $i = 0;
! 125: foreach( $builds as $build ) {
! 126:
! 127: $this->build_id = $build->getId();
! 128:
! 129: if( is_object( $build ) ) {
! 130: $build_ports_queue_entries = $this->TinderboxDS->getBuildPortsQueueEntries( $this->build_id );
! 131: if( is_array( $build_ports_queue_entries ) && count( $build_ports_queue_entries ) > 0 ) {
! 132: foreach( $build_ports_queue_entries as $build_ports_queue_entry ) {
! 133: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'list' ) ) {
! 134: switch( $build_ports_queue_entry->getStatus() ) {
! 135: case 'ENQUEUED':
! 136: $status_field_class = 'queue_entry_enqueued';
! 137: break;
! 138: case 'PROCESSING':
! 139: $status_field_class = 'queue_entry_processing';
! 140: break;
! 141: case 'SUCCESS':
! 142: $status_field_class = 'queue_entry_success';
! 143: break;
! 144: case 'FAIL':
! 145: $status_field_class = 'port_fail';
! 146: break;
! 147: }
! 148: $entries[$i] = array( 'entry_id' => $build_ports_queue_entry->getBuildPortsQueueId(),
! 149: 'directory' => $build_ports_queue_entry->getPortDirectory(),
! 150: 'priority' => $build_ports_queue_entry->getPriority(),
! 151: 'build' => $build_ports_queue_entry->getBuildName(),
! 152: 'user' => $build_ports_queue_entry->getUserName(),
! 153: 'all_prio' => $this->create_prio_array( $build_ports_queue_entry ),
! 154: 'email_on_completion' => $build_ports_queue_entry->getEmailOnCompletion(),
! 155: 'status_field_class' => $status_field_class);
! 156:
! 157: }
! 158: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'modify' ) ) {
! 159: $entries[$i]['modify'] = 1;
! 160: }
! 161: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'delete' ) ) {
! 162: $entries[$i]['delete'] = 1;
! 163: }
! 164: $i++;
! 165: }
! 166: }
! 167: }
! 168: }
! 169:
! 170: if( !empty($entries) && is_array( $entries ) && count( $entries ) > 0 ) {
! 171: $this->template_assign( 'entries', $entries );
! 172: $this->template_assign( 'no_list', false );
! 173: } else {
! 174: $this->template_assign( 'no_list', true );
! 175: }
! 176:
! 177: $this->template_assign( 'all_prio', array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ) );
! 178: $this->template_assign( 'new_priority', 10 );
! 179:
! 180: return $this->template_parse( 'list_tinderd_queue.tpl' );
! 181: }
! 182: }
! 183:
! 184: function change_tinderd_queue( $action, $entry_id, $build_id, $priority, $email_on_completion ) {
! 185:
! 186: if( !$this->moduleUsers->is_logged_in() ) {
! 187: return $this->template_parse( 'please_login.tpl' );
! 188: } else {
! 189: $build_ports_queue_entry = $this->TinderboxDS->getBuildPortsQueueEntryById( $entry_id );
! 190: $this->build_id = $build_ports_queue_entry->getBuildId();
! 191: if( $action == 'delete' ) {
! 192: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'delete' ) ) {
! 193: $this->TinderboxDS->deleteBuildPortsQueueEntry( $entry_id );
! 194: } else {
! 195: $this->TinderboxDS->addError( build_ports_queue_not_allowed_to_delete );
! 196: }
! 197: } elseif( $action == 'reset status' ) {
! 198: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'modify' ) ) {
! 199: $build_ports_queue_entry->resetStatus();
! 200: $this->TinderboxDS->updateBuildPortsQueueEntry( $build_ports_queue_entry );
! 201: } else {
! 202: $this->TinderboxDS->addError( build_ports_queue_not_allowed_to_modify );
! 203: }
! 204: } elseif( $action == 'save' ) {
! 205: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'modify' ) ) {
! 206: $this->build_id = $build_id;
! 207: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'modify' ) ) {
! 208: if( $build_ports_queue_entry->getPriority() != $priority && $priority < 5 && !$this->checkQueueEntryAccess( $build_ports_queue_entry, 'priolower5' ) ) {
! 209: $this->TinderboxDS->addError( build_ports_queue_priority_to_low );
! 210: } else {
! 211: $build_ports_queue_entry->setBuildId( $build_id );
! 212: $build_ports_queue_entry->setPriority( $priority );
! 213: $build_ports_queue_entry->setEmailOnCompletion( $email_on_completion );
! 214: $this->TinderboxDS->updateBuildPortsQueueEntry( $build_ports_queue_entry );;
! 215: }
! 216: } else {
! 217: $this->TinderboxDS->addError( build_ports_queue_not_allowed_to_modify );
! 218: }
! 219: } else {
! 220: $this->TinderboxDS->addError( build_ports_queue_not_allowed_to_modify );
! 221: }
! 222: }
! 223: }
! 224: return;
! 225: }
! 226:
! 227: function add_tinderd_queue( $action, $build_id, $priority, $port_directory, $email_on_completion ) {
! 228:
! 229: if( !$this->moduleUsers->is_logged_in() ) {
! 230: return $this->template_parse( 'please_login.tpl' );
! 231: } else {
! 232: if( empty( $build_id ) || empty( $priority ) || empty( $port_directory ) ) {
! 233: $this->TinderboxDS->addError( mandatory_input_fields_are_empty );
! 234: } else {
! 235: $build_ports_queue_entry = $this->TinderboxDS->createBuildPortsQueueEntry( $build_id, $priority, $port_directory, $this->moduleUsers->get_id(), $email_on_completion );
! 236: $this->build_id = $build_id;
! 237: if( $action == 'add' ) {
! 238: if( $this->checkQueueEntryAccess( $build_ports_queue_entry, 'add' ) ) {
! 239: if( $priority < 5 && !$this->checkQueueEntryAccess( $entry, 'priolower5' ) ) {
! 240: $this->template_assign( 'new_build_id', $build_id );
! 241: $this->template_assign( 'new_priority', $priority );
! 242: $this->template_assign( 'new_port_directory', $port_directory );
! 243: $this->template_assign( 'new_email_on_completion', $email_on_completion );
! 244: $this->TinderboxDS->addError( build_ports_queue_priority_to_low );
! 245: } else {
! 246: $this->TinderboxDS->addBuildPortsQueueEntry( $build_ports_queue_entry );
! 247: }
! 248: } else {
! 249: $this->template_assign( 'new_build_id', $build_id );
! 250: $this->template_assign( 'new_priority', $priority );
! 251: $this->template_assign( 'new_port_directory', $port_directory );
! 252: $this->TinderboxDS->addError( build_ports_queue_not_allowed_to_add );
! 253: }
! 254: }
! 255: }
! 256: }
! 257: return;
! 258: }
! 259: }
! 260: ?>