diff --git a/angular_app/js/app.js b/angular_app/js/app.js index 0ee06f9..268c10e 100644 --- a/angular_app/js/app.js +++ b/angular_app/js/app.js @@ -139,12 +139,12 @@ eventManApp.config(['$stateProvider', '$urlRouterProvider', .state('event.ticket.new', { url: '/:id/ticket/new', templateUrl: 'ticket-edit.html', - controller: 'EventDetailsCtrl' + controller: 'EventTicketsCtrl' }) .state('event.ticket.edit', { url: '/:id/ticket/edit', templateUrl: 'ticket-edit.html', - controller: 'EventDetailsCtrl' + controller: 'EventTicketsCtrl' }) .state('import', { url: '/import', diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index 67291f2..10ddd5a 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -95,8 +95,8 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$modal', ' ); -eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', 'Person', 'EventUpdates', '$stateParams', 'Setting', '$log', '$translate', '$rootScope', - function ($scope, $state, Event, Person, EventUpdates, $stateParams, Setting, $log, $translate, $rootScope) { +eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', 'EventTicket', 'Person', 'EventUpdates', '$stateParams', 'Setting', '$log', '$translate', '$rootScope', + function ($scope, $state, Event, EventTicket, Person, EventUpdates, $stateParams, Setting, $log, $translate, $rootScope) { $scope.personsOrder = ["name", "surname"]; $scope.countAttendees = 0; $scope.message = {}; @@ -359,6 +359,33 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', ); +eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', 'EventTicket', 'Person', 'EventUpdates', '$stateParams', 'Setting', '$log', '$translate', '$rootScope', + function ($scope, $state, Event, EventTicket, Person, EventUpdates, $stateParams, Setting, $log, $translate, $rootScope) { + $scope.message = {}; + $scope.event = {}; + + $scope.newTicket = $state.is('event.ticket.new'); + + if ($stateParams.id) { + $scope.event = Event.get($stateParams, function() { + }); + } + + $scope.addTicket = function(person) { + var personObj = new Person(person); + personObj.$save(function(p) { + person.person_id = person._id; + person._id = $stateParams.id; // that's the id of the event, not the person. + EventTicket.addTicket(person, function(p) { + $log.debug(p); + }); + $scope.newPerson = {}; + }); + }; + }] +); + + eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person', 'Setting', '$modal', '$translate', '$rootScope', function ($scope, Person, Setting, $modal, $translate, $rootScope) { $scope.persons = Person.all(); diff --git a/angular_app/js/services.js b/angular_app/js/services.js index c2fcea4..1e6d552 100644 --- a/angular_app/js/services.js +++ b/angular_app/js/services.js @@ -97,6 +97,47 @@ eventManServices.factory('Event', ['$resource', '$rootScope', ); +eventManServices.factory('EventTicket', ['$resource', '$rootScope', + function($resource, $rootScope) { + return $resource('events/:id/tickets', {id: '@_id', person_id: '@person_id'}, { + + updateTicket: { + method: 'PUT', + interceptor : {responseError: $rootScope.errorHandler}, + isArray: false, + url: 'events/:id/ticketss/:person_id', + params: {uuid: $rootScope.app_uuid}, + transformResponse: function(data, headers) { + return angular.fromJson(data); + } + }, + + addTicket: { + method: 'POST', + interceptor : {responseError: $rootScope.errorHandler}, + isArray: false, + url: 'events/:id/tickets/:person_id', + params: {uuid: $rootScope.app_uuid}, + transformResponse: function(data, headers) { + return angular.fromJson(data); + } + }, + + deleteTicket: { + method: 'DELETE', + interceptor : {responseError: $rootScope.errorHandler}, + isArray: false, + url: 'events/:_id/tickets/:person_id', + params: {uuid: $rootScope.app_uuid}, + transformResponse: function(data, headers) { + return angular.fromJson(data); + } + } + }); + }] +); + + eventManServices.factory('Person', ['$resource', '$rootScope', function($resource, $rootScope) { return $resource('persons/:id', {id: '@_id'}, { diff --git a/angular_app/ticket-edit.html b/angular_app/ticket-edit.html index e5f31c9..169cf3e 100644 --- a/angular_app/ticket-edit.html +++ b/angular_app/ticket-edit.html @@ -37,7 +37,7 @@ - diff --git a/eventman_server.py b/eventman_server.py index d702625..76567d4 100755 --- a/eventman_server.py +++ b/eventman_server.py @@ -68,8 +68,9 @@ class BaseHandler(tornado.web.RequestHandler): permissions = { 'event|read': True, 'events|read': True, - 'event:ticket|all': True, - 'event:persons|all': True, + 'event:tickets|create': True, + 'event:tickets|update': True, + 'event:tickets|read': True, 'person|create': True } @@ -286,8 +287,11 @@ class CollectionHandler(BaseHandler): return self.build_error(status=401, message='insufficient permissions: %s' % permission) method = getattr(self, 'handle_get_%s' % resource, None) if method and callable(method): - self.write(method(id_, resource_id, **kwargs)) + output = method(id_, resource_id, **kwargs) + if output is not None: + self.write(output) return + return self.build_error(status=404, message='unable to access resource: %s' % resource) if id_ is not None: # read a single document permission = '%s|read' % self.document @@ -498,6 +502,11 @@ class EventsHandler(CollectionHandler): persons = self._filter_results(event.get('persons') or [], self.arguments) return {'persons': persons} + def handle_get_tickets(self, id_, resource_id=None): + if resource_id is None and not self.has_permission('event:tickets|all'): + return self.build_error(status=401, message='insufficient permissions: event:tickets|all') + return self.handle_get_persons(id_, resource_id) + def handle_post_persons(self, id_, person_id, data): # Add a person to the list of persons registered at this event. uuid, arguments = self.uuid_arguments @@ -519,6 +528,8 @@ class EventsHandler(CollectionHandler): create=False) return ret + handle_post_tickets = handle_post_persons + def handle_put_persons(self, id_, person_id, data): # Update an existing entry for a person registered at this event. self._clean_dict(data) @@ -560,6 +571,8 @@ class EventsHandler(CollectionHandler): self.send_ws_message('event/%s/updates' % id_, json.dumps(ret)) return ret + handle_put_tickets = handle_put_persons + def handle_delete_persons(self, id_, person_id): # Remove a specific person from the list of persons registered at this event. uuid, arguments = self.uuid_arguments @@ -575,6 +588,8 @@ class EventsHandler(CollectionHandler): self.send_ws_message('event/%s/updates' % id_, json.dumps(ret)) return ret + handle_delete_tickets = handle_delete_persons + class EbCSVImportPersonsHandler(BaseHandler): """Importer for CSV files exported from eventbrite.""" @@ -823,7 +838,6 @@ def run(): _ws_handler = (r"/ws/+event/+(?P[\w\d_-]+)/+updates/?", WebSocketEventUpdatesHandler) _persons_path = r"/persons/?(?P[\w\d_-]+)?/?(?P[\w\d_-]+)?/?(?P[\w\d_-]+)?" _events_path = r"/events/?(?P[\w\d_-]+)?/?(?P[\w\d_-]+)?/?(?P[\w\d_-]+)?" - _events_path = r"/events/?(?P[\w\d_-]+)?/?(?P[\w\d_-]+)?/?(?P[\w\d_-]+)?" application = tornado.web.Application([ (_persons_path, PersonsHandler, init_params), (r'/v%s%s' % (API_VERSION, _persons_path), PersonsHandler, init_params),