Skip to content

Commit

Permalink
Merge pull request #1018 from knnniggett/new_group_permission
Browse files Browse the repository at this point in the history
New User Permission "Groups"
  • Loading branch information
connortechnology committed Aug 16, 2015
2 parents 28bbcbb + 32f6c92 commit a8248c3
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 46 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
cmake_minimum_required (VERSION 2.6)
project (zoneminder)
set(zoneminder_VERSION "1.28.100")
set(zoneminder_VERSION "1.28.101")
# make API version a minor of ZM version
set(zoneminder_API_VERSION "${zoneminder_VERSION}.1")

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# For instructions on building with cmake, please see INSTALL
#
AC_PREREQ(2.59)
AC_INIT(zm,1.28.100,[http://www.zoneminder.com/forums/ - Please check FAQ first],zoneminder,http://www.zoneminder.com/downloads.html)
AC_INIT(zm,1.28.101,[http://www.zoneminder.com/forums/ - Please check FAQ first],zoneminder,http://www.zoneminder.com/downloads.html)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR(src/zm.h)
AC_CONFIG_HEADERS(config.h)
Expand Down
3 changes: 2 additions & 1 deletion db/zm_create.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ CREATE TABLE `Users` (
`Events` enum('None','View','Edit') NOT NULL default 'None',
`Control` enum('None','View','Edit') NOT NULL default 'None',
`Monitors` enum('None','View','Edit') NOT NULL default 'None',
`Groups` enum('None','View','Edit') NOT NULL default 'None',
`Devices` enum('None','View','Edit') NOT NULL default 'None',
`System` enum('None','View','Edit') NOT NULL default 'None',
`MaxBandwidth` varchar(16) NOT NULL default '',
Expand Down Expand Up @@ -546,7 +547,7 @@ CREATE TABLE `Zones` (
--
-- Create a default admin user.
--
insert into Users VALUES (NULL,'admin',password('admin'),'',1,'View','Edit','Edit','Edit','Edit','Edit','','');
insert into Users VALUES (NULL,'admin',password('admin'),'',1,'View','Edit','Edit','Edit','Edit','Edit','Edit','','');

--
-- Add a sample filter to purge the oldest 100 events when the disk is 95% full
Expand Down
23 changes: 23 additions & 0 deletions db/zm_update-1.28.101.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--
-- This updates a 1.28.100 database to 1.28.101
--

--
-- Add Groups column to Users
--


SET @s = (SELECT IF(
(SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'Users'
AND table_schema = DATABASE()
AND column_name = 'Groups'
) > 0,
"SELECT 'Column Groups exists in Users'",
"ALTER TABLE Users ADD COLUMN `Groups` ENUM('None','View','Edit') NOT NULL DEFAULT 'None' AFTER `Monitors`"
));

PREPARE stmt FROM @s;
EXECUTE stmt;

2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.28.100
1.28.101
71 changes: 36 additions & 35 deletions web/includes/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,15 +624,42 @@ function getAffectedIds( $name )
}
}

// System view actions
if ( $action == "setgroup" ) {
if ( !empty($_REQUEST['gid']) ) {
setcookie( "zmGroup", validInt($_REQUEST['gid']), time()+3600*24*30*12*10 );
} else {
setcookie( "zmGroup", "", time()-3600*24*2 );
}
$refreshParent = true;
}
// Group view actions
if ( canView( 'Groups' ) && $action == "setgroup" ) {
if ( !empty($_REQUEST['gid']) ) {
setcookie( "zmGroup", validInt($_REQUEST['gid']), time()+3600*24*30*12*10 );
} else {
setcookie( "zmGroup", "", time()-3600*24*2 );
}
$refreshParent = true;
}

// Group edit actions
if ( canEdit( 'Groups' ) ) {
if ( $action == "group" ) {
# Should probably verfy that each monitor id is a valid monitor, that we have access to. HOwever at the moment, you have to have System permissions to do this
$monitors = empty( $_POST['newGroup']['MonitorIds'] ) ? NULL : implode(',', $_POST['newGroup']['MonitorIds']);
if ( !empty($_POST['gid']) ) {
dbQuery( "UPDATE Groups SET Name=?, MonitorIds=? WHERE Id=?", array($_POST['newGroup']['Name'], $monitors, $_POST['gid']) );
} else {
dbQuery( "INSERT INTO Groups SET Name=?, MonitorIds=?", array( $_POST['newGroup']['Name'], $monitors ) );
}
$view = 'none';
}
if ( !empty($_REQUEST['gid']) && $action == "delete" ) {
dbQuery( "delete from Groups where Id = ?", array($_REQUEST['gid']) );
if ( isset($_COOKIE['zmGroup']) )
{
if ( $_REQUEST['gid'] == $_COOKIE['zmGroup'] )
{
unset( $_COOKIE['zmGroup'] );
setcookie( "zmGroup", "", time()-3600*24*2 );
$refreshParent = true;
}
}
}
$refreshParent = true;
}

// System edit actions
if ( canEdit( 'System' ) )
Expand Down Expand Up @@ -851,19 +878,6 @@ function getAffectedIds( $name )
dbQuery( "replace into States set Name=?, Definition=?", array( $_REQUEST['runState'],$definition) );
}
}
elseif ( $action == "group" )
{
# Should probably verfy that each monitor id is a valid monitor, that we have access to. HOwever at the moment, you have to have System permissions to do this
$monitors = empty( $_POST['newGroup']['MonitorIds'] ) ? NULL : implode(',', $_POST['newGroup']['MonitorIds']);
if ( !empty($_POST['gid']) ) {
dbQuery( "UPDATE Groups SET Name=?, MonitorIds=? WHERE Id=?", array($_POST['newGroup']['Name'], $monitors, $_POST['gid']) );
} else {
dbQuery( "INSERT INTO Groups SET Name=?, MonitorIds=?", array( $_POST['newGroup']['Name'], $monitors ) );
}

$refreshParent = true;
$view = 'none';
}
elseif ( $action == "delete" )
{
if ( isset($_REQUEST['runState']) )
Expand All @@ -876,19 +890,6 @@ function getAffectedIds( $name )
if ( $markUid == $user['Id'] )
userLogout();
}
if ( !empty($_REQUEST['gid']) )
{
dbQuery( "delete from Groups where Id = ?", array($_REQUEST['gid']) );
if ( isset($_COOKIE['zmGroup']) )
{
if ( $_REQUEST['gid'] == $_COOKIE['zmGroup'] )
{
unset( $_COOKIE['zmGroup'] );
setcookie( "zmGroup", "", time()-3600*24*2 );
$refreshParent = true;
}
}
}
}
}
else
Expand Down
1 change: 1 addition & 0 deletions web/includes/config.php.in
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ $GLOBALS['defaultUser'] = array(
"Events" => 'Edit',
"Control" => 'Edit',
"Monitors" => 'Edit',
"Groups" => 'Edit',
"Devices" => 'Edit',
"System" => 'Edit',
"MaxBandwidth" => "",
Expand Down
2 changes: 2 additions & 0 deletions web/skins/classic/js/skin.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
var canEditSystem = <?php echo canEdit('System' )?'true':'false' ?>;
var canViewSystem = <?php echo canView('System' )?'true':'false' ?>;

var canEditGroups = <?php echo canEdit('Groups' )?'true':'false' ?>;

var refreshParent = <?php echo !empty($refreshParent)?'true':'false' ?>;

var focusWindow = <?php echo !empty($focusWindow)?'true':'false' ?>;
Expand Down
2 changes: 1 addition & 1 deletion web/skins/classic/views/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
<h3 id="systemStats"><?php echo translate('Load') ?>: <?php echo getLoad() ?> / <?php echo translate('Disk') ?>: <?php echo getDiskPercent() ?>%</h3>
<h2 id="title"><a href="http://www.zoneminder.com" target="ZoneMinder">ZoneMinder</a> <?php echo translate('Console') ?> - <?php echo makePopupLink( '?view=state', 'zmState', 'state', $status, canEdit( 'System' ) ) ?> - <?php echo $run_state ?> <?php echo makePopupLink( '?view=version', 'zmVersion', 'version', '<span class="'.$versionClass.'">v'.ZM_VERSION.'</span>', canEdit( 'System' ) ) ?></h2>
<div class="clear"></div>
<div id="monitorSummary"><?php echo makePopupLink( '?view=groups', 'zmGroups', 'groups', translate('Group') . ': ' . ($group?' ('.$group['Name'].')':'All').': '. sprintf( $CLANG['MonitorCount'], count($displayMonitors), zmVlang( $VLANG['Monitor'], count($displayMonitors) ) ) ); ?></div>
<div id="monitorSummary"><?php echo makePopupLink( '?view=groups', 'zmGroups', 'groups', sprintf( $CLANG['MonitorCount'], count($displayMonitors), zmVlang( $VLANG['Monitor'], count($displayMonitors) ) ).($group?' ('.$group['Name'].')':''), canView( 'Groups' ) ); ?></div>
<?php
if ( ZM_OPT_X10 && canView( 'Devices' ) )
{
Expand Down
4 changes: 2 additions & 2 deletions web/skins/classic/views/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//

if ( !canEdit( 'System' ) )
if ( !canEdit( 'Groups' ) )
{
$view = "error";
return;
Expand Down Expand Up @@ -78,7 +78,7 @@
</tbody>
</table>
<div id="contentButtons">
<input type="submit" value="<?php echo translate('Save') ?>"<?php if ( !canEdit( 'System' ) ) { ?> disabled="disabled"<?php } ?>/>
<input type="submit" value="<?php echo translate('Save') ?>"<?php if ( !canEdit( 'Groups' ) ) { ?> disabled="disabled"<?php } ?>/>
<input type="button" value="<?php echo translate('Cancel') ?>" onclick="closeWindow()"/>
</div>
</form>
Expand Down
10 changes: 7 additions & 3 deletions web/skins/classic/views/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//

if ( !canView( 'Groups' ) ) {
$view = "error";
return;
}

$sql = "select * from Groups order by Name";
$groups = array();
Expand Down Expand Up @@ -72,9 +76,9 @@
</table>
<div id="contentButtons">
<input type="submit" value="<?php echo translate('Apply') ?>"/>
<input type="button" value="<?php echo translate('New') ?>" onclick="newGroup()"<?php echo canEdit('System')?'':' disabled="disabled"' ?>/>
<input type="button" name="editBtn" value="<?php echo translate('Edit') ?>" onclick="editGroup( this )"<?php echo $selected&&canEdit('System')?'':' disabled="disabled"' ?>/>
<input type="button" name="deleteBtn" value="<?php echo translate('Delete') ?>" onclick="deleteGroup( this )"<?php echo $selected&&canEdit('System')?'':' disabled="disabled"' ?>/>
<input type="button" value="<?php echo translate('New') ?>" onclick="newGroup()"<?php echo canEdit('Groups')?'':' disabled="disabled"' ?>/>
<input type="button" name="editBtn" value="<?php echo translate('Edit') ?>" onclick="editGroup( this )"<?php echo $selected&&canEdit('Groups')?'':' disabled="disabled"' ?>/>
<input type="button" name="deleteBtn" value="<?php echo translate('Delete') ?>" onclick="deleteGroup( this )"<?php echo $selected&&canEdit('Groups')?'':' disabled="disabled"' ?>/>
<input type="button" value="<?php echo translate('Cancel') ?>" onclick="closeWindow();"/>
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion web/skins/classic/views/js/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function deleteGroup( element )

function configureButtons( element )
{
if ( canEditSystem )
if ( canEditGroups )
{
var form = element.form;
if ( element.checked )
Expand Down
2 changes: 2 additions & 0 deletions web/skins/classic/views/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<th class="colEvents"><?php echo translate('Events') ?></th>
<th class="colControl"><?php echo translate('Control') ?></th>
<th class="colMonitors"><?php echo translate('Monitors') ?></th>
<th class="colGroups"><?php echo translate('Groups') ?></th>
<th class="colSystem"><?php echo translate('System') ?></th>
<th class="colBandwidth"><?php echo translate('Bandwidth') ?></th>
<th class="colMonitor"><?php echo translate('Monitor') ?></th>
Expand Down Expand Up @@ -194,6 +195,7 @@
<td class="colEvents"><?php echo validHtmlStr($row['Events']) ?></td>
<td class="colControl"><?php echo validHtmlStr($row['Control']) ?></td>
<td class="colMonitors"><?php echo validHtmlStr($row['Monitors']) ?></td>
<td class="colGroups"><?php echo validHtmlStr($row['Groups']) ?></td>
<td class="colSystem"><?php echo validHtmlStr($row['System']) ?></td>
<td class="colBandwidth"><?php echo $row['MaxBandwidth']?$bwArray[$row['MaxBandwidth']]:'&nbsp;' ?></td>
<td class="colMonitor"><?php echo $row['MonitorIds']?(join( ", ", $userMonitors )):"&nbsp;" ?></td>
Expand Down
4 changes: 4 additions & 0 deletions web/skins/classic/views/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@
<th scope="row"><?php echo translate('Monitors') ?></th>
<td><?php echo buildSelect( "newUser[Monitors]", $nve ) ?></td>
</tr>
<tr>
<th scope="row"><?php echo translate('Groups') ?></th>
<td><?php echo buildSelect( "newUser[Groups]", $nve ) ?></td>
</tr>
<tr>
<th scope="row"><?php echo translate('System') ?></th>
<td><?php echo buildSelect( "newUser[System]", $nve ) ?></td>
Expand Down

0 comments on commit a8248c3

Please sign in to comment.