Skip to content

Commit

Permalink
#62 - move plugin log to event-level
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed Oct 7, 2015
1 parent 49266a0 commit fc79438
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 19 deletions.
10 changes: 6 additions & 4 deletions src/main/java/alfio/controller/api/admin/PluginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
import alfio.manager.plugin.PluginManager;
import alfio.model.plugin.PluginLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.List;

@RestController
@RequestMapping("/admin/api/plugin")
@RequestMapping("/admin/api")
public class PluginController {

private final PluginManager pluginManager;
Expand All @@ -36,9 +38,9 @@ public PluginController(PluginManager pluginManager) {
this.pluginManager = pluginManager;
}

@RequestMapping(value = "/log", method = RequestMethod.GET)
public List<PluginLog> loadAllLogMessages() {
return pluginManager.loadAllLogMessages();
@RequestMapping(value = "/events/{eventName}/plugin/log", method = RequestMethod.GET)
public List<PluginLog> loadAllLogMessages(@PathVariable("eventName") String eventName, Principal principal) {
return pluginManager.loadAllLogMessages(eventName, principal.getName());
}

}
12 changes: 9 additions & 3 deletions src/main/java/alfio/manager/plugin/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,18 @@ public void saveAllConfigOptions(int eventId, List<PluginConfigOptionModificatio
}

private boolean validateOwnership(int eventId, String username) {
Event event = eventRepository.findById(eventId);
return validateOwnership(eventRepository.findById(eventId), username);
}

private boolean validateOwnership(Event event, String username) {
return userManager.isOwnerOfOrganization(userManager.findUserByUsername(username), event.getOrganizationId());
}

public List<PluginLog> loadAllLogMessages() {
return pluginLogRepository.loadAll();
public List<PluginLog> loadAllLogMessages(String eventName, String username) {
Event event = eventRepository.findByShortName(eventName);
Validate.notNull(event, "invalid shortName");
Validate.isTrue(validateOwnership(event, username), "Not Authorized");
return pluginLogRepository.loadByEventId(event.getId());
}

private static <T extends Plugin> Stream<T> filterPlugins(List<Plugin> plugins, int eventId, Class<T> type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ public interface PluginLogRepository {

@Query("select pl.id, pl.plugin_id, pl.event_id, pl.description, pl.type, pl.event_ts, e.short_name from plugin_log pl, event e where pl.event_id = e.id order by pl.event_ts asc")
List<PluginLog> loadAll();

@Query("select pl.id, pl.plugin_id, pl.event_id, pl.description, pl.type, pl.event_ts, e.short_name from plugin_log pl, event e where pl.event_id = :eventId and pl.event_id = e.id order by pl.event_ts asc")
List<PluginLog> loadByEventId(@Bind("eventId") int eventId);
}
1 change: 0 additions & 1 deletion src/main/webapp/WEB-INF/templates/admin/index.ms
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
<ul class="nav navbar-nav">
<li data-ui-sref-active="active"><a data-ui-sref="index">Dashboard</a></li>
<li data-ui-sref-active="active"><a data-ui-sref="configuration.system">Configuration</a></li>
<li data-ui-sref-active="active"><a data-ui-sref="plugin-log">Plugin Log</a></li>
<li class="nav-divider"></li>
<li class="visible-xs"><span class="navbar-brand"><i class="fa fa-user"></i> {{username}}</span></li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ <h4 class="text-muted">{{event.shortDescription}}</h4>
<span><a class="btn btn-warning" data-ui-sref="compose-custom-message({eventName: event.shortName})"><i class="fa fa-envelope"></i> send a message to attendees</a></span>
<waiting-queue-display-counter data-event="event"></waiting-queue-display-counter>
<span><a class="btn btn-default" data-ui-sref="events.email-log({eventName:event.shortName})"><i class="fa fa-paper-plane-o"></i> view sent messages</a></span>
<span><a class="btn btn-default" data-ui-sref="events.plugin-log({eventName:event.shortName})"><i class="fa fa-plug"></i> view Plugins log</a></span>
</div>
<div class="page-header"><h2>Logistic info</h2></div>
<div class="row">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="container">
<div class="page-header">
<h1>Plugin Log</h1>
<h1>Plugin Log for {{ctrl.event.displayName}}</h1>
<small class="text-muted">Here you can monitor the activity of the active plugins</small>
</div>

Expand All @@ -20,21 +20,20 @@ <h3>Plugins' activity</h3>
<input type="text" class="form-control" placeholder="Filter table" data-ng-model="ctrl.searchFilter">
</div>
</div>
</div>
</div>
<div class="clearfix"></div>

<div class="table-responsive">
<table class="table">
<thead>
<th>event</th>
<th>Plugin ID</th>
<th>Message</th>
<th>Message type</th>
<th>Timestamp</th>
</thead>
<tbody>
<tr data-ng-repeat="entry in ctrl.logEntries | filter:ctrl.searchFilter" data-ng-class="{'text-success': entry.type === 'SUCCESS', 'text-danger': entry.type === 'ERROR', 'text-warning': entry.type === 'WARNING'}">
<td data-ng-class-even="'active'">{{entry.eventName}}</td>
<td data-ng-class-even="'active'">{{entry.pluginId}}</td>
<td data-ng-class-even="'active'">{{entry.description}}</td>
<td data-ng-class-even="'active'">{{entry.type}}</td>
Expand All @@ -43,5 +42,8 @@ <h3>Plugins' activity</h3>
</tbody>
</table>
</div>
<div class="text-center">
<a class="btn btn-default" data-ui-sref="events.detail({eventName: ctrl.event.shortName})">back</a>
</div>
</div>
</div>
19 changes: 11 additions & 8 deletions src/main/webapp/resources/js/admin/feature/plugin/plugin-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
angular.module('alfio-plugins', ['adminServices'])
.config(['$stateProvider', function($stateProvider) {
$stateProvider
.state('plugin-log', {
url: '/plugin-log',
.state('events.plugin-log', {
url: '/:eventName/plugin-log',
templateUrl: '/resources/angular-templates/admin/partials/plugin/log.html',
controller: PluginLogController,
controllerAs: 'ctrl'
Expand All @@ -14,20 +14,23 @@
.service('PluginService', PluginService);


function PluginLogController(PluginService) {
function PluginLogController(PluginService, EventService, $stateParams) {
var ctrl = this;
ctrl.logEntries = [];
PluginService.loadLogEntries().success(function(result) {
EventService.getEvent($stateParams.eventName).success(function(result) {
ctrl.event = result.event;
});
PluginService.loadLogEntries($stateParams.eventName).success(function(result) {
ctrl.logEntries = result;
})
});
}

PluginLogController.prototype.$inject = ['PluginService'];
PluginLogController.prototype.$inject = ['PluginService', 'EventService', '$stateParams'];

function PluginService($http, HttpErrorHandler) {

this.loadLogEntries = function() {
return $http.get('/admin/api/plugin/log').error(HttpErrorHandler.handle);
this.loadLogEntries = function(eventName) {
return $http.get('/admin/api/events/'+eventName+'/plugin/log').error(HttpErrorHandler.handle);
};
}

Expand Down

0 comments on commit fc79438

Please sign in to comment.