working on permissions

This commit is contained in:
John Bintz 2009-08-15 15:38:12 -04:00
parent b9170dbe32
commit 8e3601cda5
2 changed files with 76 additions and 18 deletions

View File

@ -10,9 +10,16 @@ class WhatDidTheySayAdmin {
'de'
),
'only_allowed_users' => false,
'users' => array()
'users' => array(),
'capabilities' => array(
'submit_transcription' => 'administrator',
'approve_transcription' => 'administrator',
'change_languages' => 'administrator'
)
);
var $capabilities = array();
var $language_file;
var $all_languages = array();
var $notices = array();
@ -24,8 +31,19 @@ class WhatDidTheySayAdmin {
function init($what_did_they_say) {
$this->what_did_they_say = $what_did_they_say;
$this->capabilities = array(
'submit_transcription' => __('Submit transcriptions to a post', 'what-did-they-say'),
'approve_transcription' => __('Approve transcriptions to a post', 'what-did-they-say'),
'change_languages' => __('Change the available languages', 'what-did-they-say')
);
add_action('admin_menu', array(&$this, 'admin_menu'));
add_action('admin_notices', array(&$this, 'admin_notices'));
if (current_user_can('edit_users')) {
add_action('edit_user_profile', array(&$this, 'edit_user_profile'));
add_action('show_user_profile', array(&$this, 'edit_user_profile'));
}
wp_enqueue_script('prototype');
if (isset($_REQUEST['wdts'])) {
@ -116,6 +134,14 @@ class WhatDidTheySayAdmin {
$this->_update_options('allowed_users', $allowed_users);
}
function handle_update_capabilities($capabilities) {
$options = get_option('what-did-they-say-options');
$updated = false;
switch ($language_info['action']) {
case "capabilities":
}
}
function handle_update_options($requested_options) {
$updated_options = array(
'only_allowed_users' => false
@ -200,10 +226,6 @@ class WhatDidTheySayAdmin {
$nonce = wp_create_nonce('what-did-they-say');
$url = 'edit-comments.php?page=manage-transcriptions-wdts';
$nonce_url = add_query_arg('wdts[_nonce]', $nonce, $url);
include(dirname(__FILE__) . '/admin.inc');
}
@ -212,6 +234,23 @@ class WhatDidTheySayAdmin {
var_dump($post->ID);
}
function edit_user_profile($user) {
$options = get_option('what-did-they-say-options');
if ($options['only_allowed_users']) {
$nonce = wp_create_nonce('what-did-they-say');
$active = in_array($user->ID, $options['allowed_users']); ?>
<h3><?php _e('Transcription Roles', 'whay-did-they-say') ?></h3>
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[action]" value="change-active" />
<div>
<input type="checkbox" name="wdts[active]" value="yes" <?php echo $active ? 'checked="checked"' : "" ?> /> <?php _e('Allow this user to submit and approve transcripts', 'what-did-they-say') ?>
</div>
<?php
}
}
}
?>

View File

@ -1,7 +1,36 @@
<div class="wrap">
<h2><?php _e('Manage Transcripts', 'what-did-they-sahy') ?></h2>
<h2><?php _e('What Did They Say?!? Settings', 'what-did-they-sahy') ?></h2>
<h3><?php _e('Queued Transcripts', 'what-did-they-say') ?></h3>
<?php if (current_user_can('edit_users')) { ?>
<form method="post">
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[action]" value="capabilities" />
<h3><?php _e('Capabilities', 'what-did-they-say') ?></h3>
<table class="widefat fixed">
<tr class="thead">
<th scope="col" class="manage-col"><?php _e('Capability', 'what-did-they-say') ?></th>
<th scope="col" class="manage-col"><?php _e('Role Needed', 'what-did-they-say') ?></th>
</tr>
<?php foreach ($this->capabilities as $key => $label) { ?>
<tr>
<th scope="col"><?php echo $label ?></th>
<td>
<select name="wdts[capabilities][<?php echo $key ?>]">
<?php wp_dropdown_roles($options['capabilities'][$key]) ?>
</select>
</td>
</tr>
<?php } ?>
<tr>
<td>&nbsp;</td>
<td>
<input class="button" type="submit" value="<?php _e('Change capabilities', 'what-did-they-say') ?>" />
</td>
</tr>
</table>
</form>
<?php } ?>
<h3><?php _e('Languages', 'what-did-they-say') ?></h3>
@ -69,16 +98,6 @@
</td>
</tr>
</table>
<h3><?php _e('Authorized Users', 'what-did-they-say') ?></h3>
<ul>
<?php foreach (get_users_of_blog() as $user) { ?>
<li>
<strong><?php echo $user->display_name ?></strong>
</li>
<?php } ?>
</ul>
</div>
<script type="text/javascript">
$$('form.verify').each(function(f) {