Exemplo n.º 1
0
    def put(self, id):
        controller = EventController(request)

        try:
            new_event = controller.edit(id)
        except (DoesNotExist, ValidationError): 
            api.abort(400, "Event with id {} does not exist".format(id))

        return new_event
Exemplo n.º 2
0
    def get(self, id):
        controller = EventController(request)

        try:
            event = controller.get_element_detail(id)
        except (DoesNotExist, ValidationError):
            api.abort(400, "Event with id {} does not exist".format(id))

        return json.loads(event)
Exemplo n.º 3
0
 def __init__(self):
     self.employee_types = {1: 'employee', 2: 'super_employee'}
     self.users_permission_level = {}
     self.address_controller = AddressController()
     self.condominium_controller = CondominiumController()
     self.resident_controller = ResidentController()
     self.employee_controller = EmployeeController()
     self.notification_controller = NotificationController()
     self.rule_controller = RuleController()
     self.guest_controller = GuestController()
     self.service_controller = ServiceController()
     self.event_controller = EventController()
Exemplo n.º 4
0
    def setUp(self) -> None:

        self.file = open(file="../test/input/input000.txt", mode="r")
        lines = self.file.readlines()
        number_of_events = len(lines)
        self.input = str(number_of_events) + "\n"
        self.input += "".join(lines)

        events = EventController.prepare_event_list(events=self.input)
        self.event = events[1]
        self.event.prepare()
Exemplo n.º 5
0
__author__ = 'tri'
from controller.event_controller import EventController
from controller.env_controller import EnvController
from controller.main_controller import MainController

import pygame
import time
import os

env_controller = EnvController()
event_controller = EventController()
main_controller = MainController(event_controller, env_controller)

# Control fps
clock = pygame.time.Clock()

# Intro
intro_sound = pygame.mixer.Sound('resources/Mr.ogg')
intro_sound.play()

start_time = time.time()
while time.time() - start_time < 11:
    main_controller.intro(clock)

background_music = pygame.mixer.Sound('resources/background_music.ogg')
background_music.play()

main_controller.init_game()
main_controller.prepare()

# Game loop
Exemplo n.º 6
0
def get_controller():
    controller = EventController(model=Event, request=request)
    return controller
Exemplo n.º 7
0
    def delete(self, id):
        controller = EventController(request)
        deleted = controller.delete(id)

        return deleted
        
Exemplo n.º 8
0
    def post(self):
        controller = EventController(request)
        args = controller.new()

        return args
Exemplo n.º 9
0
    def get(self):
        controller = EventController(request)
        query = controller.list()

        return jsonify(query)
Exemplo n.º 10
0
class PermissionManager:
    def __init__(self):
        self.employee_types = {1: 'employee', 2: 'super_employee'}
        self.users_permission_level = {}
        self.address_controller = AddressController()
        self.condominium_controller = CondominiumController()
        self.resident_controller = ResidentController()
        self.employee_controller = EmployeeController()
        self.notification_controller = NotificationController()
        self.rule_controller = RuleController()
        self.guest_controller = GuestController()
        self.service_controller = ServiceController()
        self.event_controller = EventController()

    def register_key(self, key_type, session_key):
        if key_type == 'employee':
            self.users_permission_level[session_key] = PermissionLevel.EMPLOYEE

        elif key_type == 'resident':
            self.users_permission_level[session_key] = PermissionLevel.RESIDENT

        elif key_type == 'super_employee':
            self.users_permission_level[
                session_key] = PermissionLevel.SUPER_EMPLOYEE

        elif key_type == 'super_user':
            self.users_permission_level[session_key] = PermissionLevel.SYSTEM

        else:
            raise RuntimeError

    def login_super_user(self, username, password):
        super_user = SuperUser.query.get(username)
        if super_user is None:
            return False, 'User not found', None

        if bcrypt.checkpw(password.encode('utf-8'),
                          super_user.password.encode('utf-8')):
            return True, super_user, super_user.username

        return False, 'User passowrd does not match', None

    @_user_key_decorator
    @_default_answer_decorator
    def build_condominium_schema(self, schema, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.SYSTEM:
            return build(schema), None

    def login_resident(self, username, password):
        user = self.resident_controller.do_login(username)
        if user is None:
            return False, 'User not found.', None, None

        if bcrypt.checkpw(password.encode('utf-8'),
                          user.password.encode('utf-8')):
            return True, \
                   self.condominium_controller.get_resident_login_info(user.apartment_id), \
                   user.apartment_id, \
                   user.apartment.tower.condominium.name

        return False, 'User password does not match.', None, None

    def login_employee(self, username, password):
        user = self.employee_controller.do_login(username)

        if user is None:
            return False, 'User not found.', None

        elif bcrypt.checkpw(password.encode('utf-8'),
                            user.password.encode('utf-8')):
            employee = user.employee
            return True, [
                employee, employee.condominium, employee.condominium.address
            ], self.employee_types[employee.type]
        else:
            return False, 'User password does not match.', None

    @_user_key_decorator
    @_default_answer_decorator
    def register_resident_user(self, username, hash_password, apartment_id,
                               father_id, user_key):
        if PermissionLevel.EMPLOYEE <= self.users_permission_level[
                user_key] <= PermissionLevel.SUPER_EMPLOYEE:
            for tower in self.employee_controller.get_employee_by_id(
                    father_id).condominium:
                for apartment in tower.apartments:
                    if apartment.id == apartment_id:
                        return self.resident_controller.register_user(
                            username, hash_password, apartment_id), None

            return False, 'User does not have the privileges to do such operation'

    @_user_key_decorator
    @_default_answer_decorator
    def register_resident(self, cpf, name, birthday, photo_location, father_id,
                          user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            resident = self.resident_controller.register_resident(
                cpf, name, birthday, photo_location, father_id)

            if resident is None:
                return False, 'Resident could not be registered'

            else:
                return True, [
                    resident, resident.apartment, resident.apartment.tower,
                    resident.apartment.tower.condominium,
                    resident.apartment.tower.condominium.address
                ]

    @_user_key_decorator
    def register_employee(self, employee_type, username, hash_password, cpf,
                          name, birthday, photo_location, role, father_id,
                          user_key):
        if self.users_permission_level[
                user_key] == PermissionLevel.SUPER_EMPLOYEE and employee_type == 1:
            condominium_id = self.employee_controller.get_employee_by_id(
                father_id).condominium_id

            employee = self.employee_controller.register_employee(
                employee_type, username, hash_password, cpf, name, birthday,
                photo_location, role, condominium_id)

        elif self.users_permission_level[user_key] == PermissionLevel.SYSTEM:
            employee = self.employee_controller.register_employee(
                employee_type, username, hash_password, cpf, name, birthday,
                photo_location, role, father_id)

        else:
            return None

        if employee is None:
            return False, 'Employee could not be registered'

        else:
            return True, [
                employee, employee.condominium, employee.condominium.address
            ]

    @_user_key_decorator
    @_default_answer_decorator
    def get_employees(self, user_id, user_key):
        if PermissionLevel.EMPLOYEE <= self.users_permission_level[
                user_key] <= PermissionLevel.SUPER_EMPLOYEE:
            return True, self.employee_controller.get_employee_by_id(
                user_id).condominium.employees

    @_user_key_decorator
    @_default_answer_decorator
    def get_residents(self, user_id, apartment_number, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            apartment = self.condominium_controller.get_apartment_by_id(
                father_id)
            if apartment is None:
                return False, 'ID not found'

            elif apartment.apt_number == apartment_number:
                return True, apartment.residents

        elif PermissionLevel.EMPLOYEE <= self.users_permission_level[
                user_key] <= PermissionLevel.SUPER_EMPLOYEE:
            condominium_id = self.employee_controller.get_employee_by_id(
                user_id).condominium_id
            return True, self.condominium_controller.get_apartment_residents_by_condominium_id_and_apt_number(
                condominium_id, apartment_number)

    @_user_key_decorator
    @_default_answer_decorator
    def get_notifications(self, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            condominium_id = self.condominium_controller.get_apartment_condominium_id(
                father_id)
            return True, self.condominium_controller.get_condominium_by_id(
                condominium_id).notifications

        elif PermissionLevel.EMPLOYEE <= self.users_permission_level[
                user_key] <= PermissionLevel.SUPER_EMPLOYEE:
            return True, self.employee_controller.get_employee_by_id(
                father_id).condominium.notifications

    @_user_key_decorator
    @_default_answer_decorator
    def get_guests(self, apartment_id, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            return True, self.condominium_controller.get_apartment_by_id(
                father_id).guests

        elif PermissionLevel.EMPLOYEE <= self.users_permission_level[
                user_key] <= PermissionLevel.SUPER_EMPLOYEE:
            if apartment_id is None:
                return False, 'User does not have the privileges to do such operation'

            for tower in self.employee_controller.get_employee_by_id(
                    father_id).condominium:
                for apartment in tower.apartments:
                    if apartment.id == apartment_id:
                        return True, apartment.guests

            return False, 'Apartment not found'

    @_user_key_decorator
    @_default_answer_decorator
    def get_services(self, apartment_id, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            return True, self.condominium_controller.get_apartment_by_id(
                father_id).services

        elif PermissionLevel.EMPLOYEE <= self.users_permission_level[
                user_key] <= PermissionLevel.SUPER_EMPLOYEE:
            if apartment_id is None:
                return False, 'User does not have the privileges to do such operation'

            for tower in self.employee_controller.get_employee_by_id(
                    father_id).condominium:
                for apartment in tower.apartments:
                    if apartment.id == apartment_id:
                        return True, apartment.services

            return False, 'Apartment not found'

    @_user_key_decorator
    @_default_answer_decorator
    def get_rules(self, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            return True, self.condominium_controller.get_apartment_by_id(
                father_id).tower.condominium.rules

        elif PermissionLevel.EMPLOYEE <= self.users_permission_level[
                user_key] <= PermissionLevel.SUPER_EMPLOYEE:
            return True, self.employee_controller.get_employee_by_id(
                father_id).condominium.rules

    @_user_key_decorator
    @_default_answer_decorator
    def get_apartment_events(self, apartment_id, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            return True, self.condominium_controller.get_apartment_by_id(
                father_id).events

        elif PermissionLevel.EMPLOYEE <= self.users_permission_level[
                user_key] <= PermissionLevel.SUPER_EMPLOYEE:
            if apartment_id is None:
                return False, 'User does not have the privileges to do such operation'

            for tower in self.employee_controller.get_employee_by_id(
                    father_id).condominium:
                for apartment in tower.apartments:
                    if apartment.id == apartment_id:
                        return True, apartment.events

            return False, 'Apartment not found'

    @_user_key_decorator
    @_default_answer_decorator
    def get_all_events(self, start, end, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            condominium_id = self.condominium_controller.get_apartment_by_id(
                father_id).tower.apartment_id
            return True, self.event_controller.get_condominium_events(
                start, end, condominium_id)

        elif PermissionLevel.EMPLOYEE <= self.users_permission_level[
                user_key] <= PermissionLevel.SUPER_EMPLOYEE:
            condominium_id = self.employee_controller.get_employee_by_id(
                father_id).condominium_id
            return True, self.event_controller.get_condominium_events(
                start, end, condominium_id)

    @_user_key_decorator
    @_default_answer_decorator
    def get_event_types(self, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            condominium_id = self.condominium_controller.get_apartment_by_id(
                father_id).tower.apartment_id
            return True, self.event_controller.get_condominium_event_types(
                condominium_id)

        elif PermissionLevel.EMPLOYEE <= self.users_permission_level[
                user_key] <= PermissionLevel.SUPER_EMPLOYEE:
            condominium_id = self.employee_controller.get_employee_by_id(
                father_id).condominium_id
            return True, self.event_controller.get_condominium_event_types(
                condominium_id)

    @_user_key_decorator
    @_default_answer_decorator
    def register_notification(self, notification_type, title, text,
                              finish_date, father_id, user_key):
        if PermissionLevel.EMPLOYEE <= self.users_permission_level[
                user_key] <= PermissionLevel.SUPER_EMPLOYEE:
            condominium_id = self.employee_controller.get_employee_by_id(
                father_id).condominium_id
            result = self.notification_controller.register_notification(
                notification_type, title, text, finish_date, father_id,
                condominium_id)
            if result:
                return True, None

            return False, 'Notification could not be registered'

    @_user_key_decorator
    @_default_answer_decorator
    def register_guest(self, guest_name, guest_arrival, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            result = self.guest_controller.register_guest(
                guest_name, guest_arrival, father_id)
            if result:
                return True, 'Guest registered'

            return False, 'Guest could not be registered'

    @_user_key_decorator
    @_default_answer_decorator
    def register_service(self, service_name, employee_name, service_arrival,
                         father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            result = self.service_controller.register_service(
                service_name, employee_name, service_arrival, father_id)
            if result:
                return True, 'Service registered'

            return False, 'Service could not be registered'

    @_user_key_decorator
    @_default_answer_decorator
    def register_rule(self, text, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            result = self.rule_controller.register_rule(
                text, father_id,
                self.employee_controller.get_employee_by_id(
                    father_id).condominium_id)
            if result:
                return True, 'Rule registered'

            return False, 'Rule could not be registered'

    @_user_key_decorator
    @_default_answer_decorator
    def register_event(self, start, end, event_type_id, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            result = self.event_controller.register_event(
                start, end, event_type_id, father_id)
            if result:
                return True, 'Event registered'

            return False, 'Event could not be registered'

    @_user_key_decorator
    @_default_answer_decorator
    def remove_notification(self, notification_id, father_id, user_key):
        if PermissionLevel.EMPLOYEE <= self.users_permission_level[
                user_key] <= PermissionLevel.SUPER_EMPLOYEE:
            for notification in self.employee_controller.get_employee_by_id(
                    father_id).condominium.notifications:
                if notification.id == notification_id:
                    result = self.notification_controller.remove_notification(
                        notification)
                    if result:
                        return True, None

                    return False, 'Notification could not be deleted'

            return None, 'Notification not found'

    @_user_key_decorator
    @_default_answer_decorator
    def remove_guest(self, guest_id, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            for guest in self.condominium_controller.get_apartment_by_id(
                    father_id).guests:
                if guest.id == guest_id:
                    result = self.guest_controller.remove_guest(guest)
                    if result:
                        return True, None

                    return False, 'Guest could not be deleted'

            return None, 'Guest not found'

    @_user_key_decorator
    @_default_answer_decorator
    def remove_service(self, service_id, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            for service in self.condominium_controller.get_apartment_by_id(
                    father_id).services:
                if service.id == service_id:
                    result = self.service_controller.remove_service(service)
                    if result:
                        return True, None

                    return False, 'Service could not be deleted'

            return None, 'Service not found'

    @_user_key_decorator
    @_default_answer_decorator
    def remove_rule(self, rule_id, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            for rule in self.employee_controller.get_employee_by_id(
                    father_id).condominium.rules:
                if rule.id == rule_id:
                    result = self.rule_controller.remove_rule(rule)
                    if result:
                        return True, None

                    return False, 'Rule could not be deleted'

            return None, 'Rule not found'

    @_user_key_decorator
    @_default_answer_decorator
    def remove_event(self, event_id, father_id, user_key):
        if self.users_permission_level[user_key] == PermissionLevel.RESIDENT:
            for event in self.condominium_controller.get_apartment_by_id(
                    father_id).events:
                if event.id == event_id:
                    result = self.event_controller.remove_event(event)
                    if result:
                        return True, None

                    return False, 'Event could not be deleted'

            return None, 'Event not found'

    def drop_session(self, session_key):
        if session_key not in self.users_permission_level:
            return False

        del self.users_permission_level[session_key]
        return True