Skip to content

Commit

Permalink
bug 553678: First stab at recording an activity log for plugin actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorchard committed Jul 15, 2010
1 parent b68a7ea commit 5d447bd
Show file tree
Hide file tree
Showing 13 changed files with 636 additions and 184 deletions.
5 changes: 5 additions & 0 deletions application/controllers/index.php
Expand Up @@ -38,6 +38,11 @@ function index($by_cat=null)
break;
}

$this->view->events = ORM::factory('auditLogEvent')
->orderby(array('created'=>'DESC'))
->limit(15)
->find_all_for_view();

$this->view->by_cat = $by_cat;
$this->view->set_filename('index/index_by' . $this->view->by_cat);
}
Expand Down
5 changes: 5 additions & 0 deletions application/controllers/local.php
Expand Up @@ -15,6 +15,11 @@ public function __construct()
{
parent::__construct();

if (authprofiles::is_logged_in()) {
AuditLogEvent_Model::$current_profile =
authprofiles::get_profile();
}

Event::add('system.403', array($this, 'show_forbidden'));
Event::add('system.forbidden', array($this, 'show_forbidden'));
}
Expand Down
129 changes: 127 additions & 2 deletions application/controllers/plugins.php
Expand Up @@ -19,7 +19,8 @@ public function __construct()
/**
* Produce a JSON index of all plugins with release counts.
*/
function index_json(){
function index_json()
{
$this->auto_render = FALSE;
$name_counts = ORM::factory('plugin')->find_release_counts();
$out = array();
Expand Down Expand Up @@ -118,6 +119,13 @@ function create($screen_name=null)
// Create a new plugin from the export.
$new_plugin = ORM::factory('plugin')->import($import);

// Log the plugin creation
ORM::factory('auditLogEvent')->set(array(
'action' => 'created',
'plugin_id' => $new_plugin->id,
'new_state' => $import,
))->save();

// Bounce over to the created plugin
if ($new_plugin->sandbox_profile_id) {
url::redirect(
Expand Down Expand Up @@ -172,11 +180,61 @@ function sandbox($screen_name, $format='html') {
if ($screen_name == authprofiles::get_profile('screen_name')) {
// HACK: Since this is using the index page shell, inform it which tab
// to select. This should probably be done all in the view.
$this->view->events = ORM::factory('auditLogEvent')
->orderby(array('created'=>'DESC'))
->where('profile_id', $profile->id)
->limit(15)
->find_all_for_view();
$this->view->by_cat = 'sandbox';
$this->view->set_filename('plugins/sandbox_mine');
}
}

/**
* Display the activity log for a plugin
*/
function activitylog($pfs_id=null, $screen_name=null)
{
if (null == $pfs_id) {
$plugin = null;
} else {
list($plugin, $plugin_profile) =
$this->_find_plugin($pfs_id, $screen_name);
if (!authprofiles::is_allowed($plugin, 'view'))
return Event::run('system.forbidden');
}

$per_page = $this->input->get('limit', 25);
$curr_page = $this->input->get('page', 1);

if (null == $plugin) {
$total_items = ORM::factory('auditLogEvent')->count_all();
} else {
$total_items = ORM::factory('auditLogEvent')
->where('plugin_id', $plugin->id)->count_all();
}

$pagination = new Pagination(array(
'base_url' => url::current(),
'total_items' => $total_items,
'items_per_page' => $per_page,
'query_string' => 'page'
));

$events = ORM::factory('auditLogEvent')
->orderby(array('created'=>'DESC'));
if ($plugin)
$events->where('plugin_id', $plugin->id);
$events->limit($pagination->items_per_page, $pagination->sql_offset);

$this->view->set(array(
'screenname' => $screen_name,
'plugin' => $plugin,
'pagination' => $pagination,
'events' => $events->find_all_for_view()
));
}

/**
* Display plugin details, accept POST updates.
*/
Expand Down Expand Up @@ -221,7 +279,18 @@ function detail($pfs_id, $format='html', $screen_name=null)
}
}

$plugin = ORM::factory('plugin')->import($data);
$old_state = $plugin->export();

$updated_plugin = ORM::factory('plugin')->import($data);

// Log the plugin modification
ORM::factory('auditLogEvent')->set(array(
'action' => 'modified',
'plugin_id' => $plugin->id,
'old_state' => $old_state,
'new_state' => $data,
))->save();

}

// Return the plugin data as an export in JSON
Expand All @@ -241,6 +310,12 @@ function detail($pfs_id, $format='html', $screen_name=null)

// Do a rough version sort.
uksort($releases, array($this, '_versionCmp'));

$this->view->events = ORM::factory('auditLogEvent')
->orderby(array('created'=>'DESC'))
->where('plugin_id', $plugin->id)
->limit(15)
->find_all_for_view();

$this->view->releases = $releases;
}
Expand Down Expand Up @@ -272,6 +347,15 @@ function copy($pfs_id, $screen_name=null)
// Create a new plugin from the export.
$new_plugin = ORM::factory('plugin')->import($export);

// Log the sandbox copy.
ORM::factory('auditLogEvent')->set(array(
'action' => 'copied_to_sandbox',
'plugin_id' => $plugin->id,
'details' => array(
'sandbox_profile' => authprofiles::get_profile()->as_array()
),
))->save();

$auth_screen_name = authprofiles::get_profile('screen_name');
if (empty($_GET)) {
// Bounce over to sandbox.
Expand Down Expand Up @@ -311,6 +395,20 @@ function deploy($pfs_id, $screen_name=null) {
// Import the export to finish deployment.
$new_plugin = ORM::factory('plugin')->import($export);

ORM::factory('auditLogEvent')->set(array(
'action' => 'deployed_from_sandbox',
'plugin_id' => $plugin->id,
))->save();

ORM::factory('auditLogEvent')->set(array(
'action' => 'deployed_from_sandbox',
'plugin_id' => $new_plugin->id,
'details' => array(
'sandbox_profile'=>$plugin_profile->as_array()
),
'new_state' => $new_plugin->export(),
))->save();

// Bounce over to the deployed plugin
url::redirect("plugins/detail/{$new_plugin->pfs_id}");

Expand All @@ -329,6 +427,12 @@ function delete($pfs_id, $screen_name=null)
// Only perform the delete on POST.
if ('post' == request::method()) {

ORM::factory('auditLogEvent')->set(array(
'action' => 'deleted',
'plugin_id' => $plugin->id,
'old_state' => $plugin->export(),
))->save();

$plugin->delete();

// Bounce over to sandbox.
Expand Down Expand Up @@ -385,6 +489,11 @@ function requestpush($pfs_id, $screen_name=null)
Session::instance()
->set_flash('message', 'Approval requested');

ORM::factory('auditLogEvent')->set(array(
'action' => 'requested_push',
'plugin_id' => $plugin->id,
))->save();

// Bounce over to sandbox.
$auth_screen_name = authprofiles::get_profile('screen_name');
url::redirect(
Expand All @@ -406,6 +515,14 @@ function addtrusted($pfs_id, $screen_name)
if ('post' == request::method()) {
$plugin->add_trusted($plugin_profile);

ORM::factory('auditLogEvent')->set(array(
'action' => 'add_trusted',
'details' => array(
'profile' => $plugin_profile->as_array()
),
'plugin_id' => $plugin->id,
))->save();

// Bounce over to sandbox.
$auth_screen_name = authprofiles::get_profile('screen_name');
url::redirect(
Expand All @@ -427,6 +544,14 @@ function removetrusted($pfs_id, $screen_name)
if ('post' == request::method()) {
$plugin->remove_trusted($plugin_profile);

ORM::factory('auditLogEvent')->set(array(
'action' => 'remove_trusted',
'details' => array(
'profile' => $plugin_profile->as_array()
),
'plugin_id' => $plugin->id,
))->save();

// Bounce over to sandbox.
$auth_screen_name = authprofiles::get_profile('screen_name');
url::redirect(
Expand Down

0 comments on commit 5d447bd

Please sign in to comment.