mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
Creating new ticketing model, based on an independent table
This commit is contained in:
parent
7b29d698dc
commit
d6e031e9e6
92
server/src/uds/REST/methods/client.py
Normal file
92
server/src/uds/REST/methods/client.py
Normal file
@ -0,0 +1,92 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2014 Virtual Cable S.L.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from uds.core.util import Config
|
||||
from uds.core.util.State import State
|
||||
from uds.core.util import log
|
||||
from uds.core.managers import cryptoManager
|
||||
from uds.REST import Handler
|
||||
from uds.REST import RequestError
|
||||
from uds.models import UserService
|
||||
|
||||
|
||||
import datetime
|
||||
import six
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Error codes:
|
||||
|
||||
# Enclosed methods under /actor path
|
||||
class Client(Handler):
|
||||
'''
|
||||
Processes actor requests
|
||||
'''
|
||||
authenticated = False # Actor requests are not authenticated
|
||||
|
||||
@staticmethod
|
||||
def result(result=None, error=None):
|
||||
'''
|
||||
Helper method to create a "result" set for actor response
|
||||
:param result: Result value to return (can be None, in which case it is converted to empty string '')
|
||||
:param error: If present, This response represents an error. Result will contain an "Explanation" and error contains the error code
|
||||
:return: A dictionary, suitable for response to Caller
|
||||
'''
|
||||
result = result if result is not None else ''
|
||||
res = {'result': result, 'date': datetime.datetime.now()}
|
||||
if error is not None:
|
||||
res['error'] = error
|
||||
return res
|
||||
|
||||
def test(self):
|
||||
'''
|
||||
Executes and returns the test
|
||||
'''
|
||||
return Client.result(_('Correct'))
|
||||
|
||||
def get(self):
|
||||
'''
|
||||
Processes get requests
|
||||
'''
|
||||
logger.debug("Client args for GET: {0}".format(self._args))
|
||||
|
||||
if len(self._args) < 1:
|
||||
raise RequestError('Invalid request')
|
||||
|
||||
raise RequestError('Invalid request')
|
94
server/src/uds/models/Ticket.py
Normal file
94
server/src/uds/models/Ticket.py
Normal file
@ -0,0 +1,94 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2012 Virtual Cable S.L.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
'''
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
__updated__ = '2015-03-23'
|
||||
|
||||
from django.db import models
|
||||
|
||||
from uds.models.UUIDModel import UUIDModel
|
||||
from uds.models.Util import getSqlDatetime
|
||||
import datetime
|
||||
|
||||
|
||||
import pickle
|
||||
|
||||
|
||||
import base64
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TicketStore(UUIDModel):
|
||||
'''
|
||||
Image storing on DB model
|
||||
This is intended for small images (i will limit them to 128x128), so storing at db is fine
|
||||
|
||||
'''
|
||||
|
||||
stamp = models.DateTimeField() # Date creation or validation of this entry
|
||||
validity = models.IntegerField(default=60) # Duration allowed for this ticket to be valid, in seconds
|
||||
|
||||
data = models.BinaryField() # Associated ticket data
|
||||
|
||||
class Meta:
|
||||
'''
|
||||
Meta class to declare the name of the table at database
|
||||
'''
|
||||
db_table = 'uds_tickets'
|
||||
app_label = 'uds'
|
||||
|
||||
@staticmethod
|
||||
def create(data, validity=60):
|
||||
return TicketStore.objects.create(stamp=getSqlDatetime(), data=pickle.dumps(data), validity=validity).uuid
|
||||
|
||||
@staticmethod
|
||||
def get(uuid):
|
||||
try:
|
||||
t = TicketStore.objects.get(uuid=uuid)
|
||||
if datetime.timedelta(seconds=t.validity) + t.stamp < getSqlDatetime():
|
||||
raise Exception('Not valid anymore')
|
||||
return pickle.loads(t.data)
|
||||
except TicketStore.DoesNotExist:
|
||||
raise Exception('Does not exists')
|
||||
|
||||
@staticmethod
|
||||
def revalidate(uuid, validity=None):
|
||||
try:
|
||||
t = TicketStore.objects.get(uuid=uuid)
|
||||
t.stamp = getSqlDatetime()
|
||||
if validity is not None:
|
||||
t.validity = validity
|
||||
t.save()
|
||||
except TicketStore.DoesNotExist:
|
||||
raise Exception('Does not exists')
|
@ -33,7 +33,7 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
__updated__ = '2015-03-02'
|
||||
__updated__ = '2015-03-23'
|
||||
|
||||
import logging
|
||||
|
||||
@ -95,4 +95,6 @@ from .Scheduler import Scheduler
|
||||
from .DelayedTask import DelayedTask
|
||||
|
||||
# Image galery related
|
||||
from .Image import Image
|
||||
from .Image import Image
|
||||
|
||||
from .Ticket import TicketStore
|
||||
|
Loading…
Reference in New Issue
Block a user