forked from TDTP/admin_transporte_backend
avance manejo de roles
parent
ad740af3d0
commit
3331a4df7f
|
@ -11,11 +11,12 @@ from .validaciones import rut_valido
|
||||||
|
|
||||||
class Aplicacion(models.Model):
|
class Aplicacion(models.Model):
|
||||||
id_aplicacion = models.IntegerField(primary_key=True)
|
id_aplicacion = models.IntegerField(primary_key=True)
|
||||||
nombre_app = models.CharField(max_length=100, blank=True, null=True)
|
nombre_app = models.CharField(max_length=100, blank=False, null=False)
|
||||||
|
path_app = models.CharField(max_length=200, blank=False, null=False)
|
||||||
vigente = models.BooleanField(blank=True, null=True)
|
vigente = models.BooleanField(blank=True, null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
managed = False
|
managed = True
|
||||||
db_table = 'aplicacion'
|
db_table = 'aplicacion'
|
||||||
|
|
||||||
|
|
||||||
|
@ -293,13 +294,13 @@ class Rol(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class RolAplicacion(models.Model):
|
class RolAplicacion(models.Model):
|
||||||
id_aplicacion = models.ForeignKey(Aplicacion, models.DO_NOTHING, db_column='id_aplicacion')
|
|
||||||
id_rol = models.ForeignKey(Rol, models.DO_NOTHING, db_column='id_rol')
|
|
||||||
solo_visualizar = models.BooleanField(blank=True, null=True)
|
|
||||||
id_rol_app = models.AutoField(primary_key=True)
|
id_rol_app = models.AutoField(primary_key=True)
|
||||||
|
id_aplicacion = models.ForeignKey(Aplicacion, models.DO_NOTHING, db_column='id_aplicacion', blank=False, null=False)
|
||||||
|
id_rol = models.ForeignKey(Rol, models.DO_NOTHING, db_column='id_rol', blank=False, null=False)
|
||||||
|
solo_visualizar = models.BooleanField(blank=True, null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
managed = False
|
managed = True
|
||||||
db_table = 'rol_aplicacion'
|
db_table = 'rol_aplicacion'
|
||||||
unique_together = (('id_aplicacion', 'id_rol'),)
|
unique_together = (('id_aplicacion', 'id_rol'),)
|
||||||
|
|
||||||
|
@ -367,6 +368,7 @@ class Usuario(models.Model):
|
||||||
rut = models.ForeignKey(Persona, models.DO_NOTHING, db_column='rut', blank=True, null=True)
|
rut = models.ForeignKey(Persona, models.DO_NOTHING, db_column='rut', blank=True, null=True)
|
||||||
vigente = models.BooleanField(blank=True, null=True)
|
vigente = models.BooleanField(blank=True, null=True)
|
||||||
superuser = models.BooleanField(blank=True, null=True)
|
superuser = models.BooleanField(blank=True, null=True)
|
||||||
|
id_rol = models.ForeignKey(Rol, models.DO_NOTHING, db_column='id_rol', blank=False, null=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
managed = False
|
managed = False
|
||||||
|
@ -385,16 +387,6 @@ class UsuarioClave(models.Model):
|
||||||
db_table = 'usuario_clave'
|
db_table = 'usuario_clave'
|
||||||
|
|
||||||
|
|
||||||
class UsuarioRol(models.Model):
|
|
||||||
login = models.ForeignKey(Usuario, models.DO_NOTHING, db_column='login', blank=True, null=True)
|
|
||||||
id_rol = models.ForeignKey(Rol, models.DO_NOTHING, db_column='id_rol', blank=True, null=True)
|
|
||||||
vigente = models.BooleanField(blank=True, null=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
managed = False
|
|
||||||
db_table = 'usuario_rol'
|
|
||||||
|
|
||||||
|
|
||||||
class Vehiculo(models.Model):
|
class Vehiculo(models.Model):
|
||||||
ppu = models.CharField(primary_key=True, max_length=10)
|
ppu = models.CharField(primary_key=True, max_length=10)
|
||||||
id_tipo_vehiculo = models.ForeignKey(TipoVehiculo, models.DO_NOTHING, db_column='id_tipo_vehiculo', blank=True, null=True)
|
id_tipo_vehiculo = models.ForeignKey(TipoVehiculo, models.DO_NOTHING, db_column='id_tipo_vehiculo', blank=True, null=True)
|
||||||
|
@ -414,3 +406,13 @@ class VehiculoLinea(models.Model):
|
||||||
managed = False
|
managed = False
|
||||||
db_table = 'vehiculo_linea'
|
db_table = 'vehiculo_linea'
|
||||||
unique_together = (('patente', 'id_linea'),)
|
unique_together = (('patente', 'id_linea'),)
|
||||||
|
|
||||||
|
class RolLinea(models.Model):
|
||||||
|
id_rol_linea = models.AutoField(primary_key=True)
|
||||||
|
id_rol = models.ForeignKey(Rol, models.DO_NOTHING, db_column='id_rol')
|
||||||
|
id_linea = models.ForeignKey(Linea, models.DO_NOTHING, db_column='id_linea')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
managed = True
|
||||||
|
db_table = 'rol_linea'
|
||||||
|
unique_together = (('id_rol', 'id_linea'),)
|
||||||
|
|
|
@ -94,6 +94,7 @@ class LineaParaderoSerializer(serializers.ModelSerializer):
|
||||||
class UsuarioSerializer(serializers.ModelSerializer):
|
class UsuarioSerializer(serializers.ModelSerializer):
|
||||||
# muestro informacion de persona en un objeto aparte
|
# muestro informacion de persona en un objeto aparte
|
||||||
persona = serializers.SerializerMethodField()
|
persona = serializers.SerializerMethodField()
|
||||||
|
rol = serializers.SerializerMethodField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Usuario
|
model = models.Usuario
|
||||||
|
@ -103,6 +104,9 @@ class UsuarioSerializer(serializers.ModelSerializer):
|
||||||
def get_persona(self, row):
|
def get_persona(self, row):
|
||||||
return model_to_dict(row.rut)
|
return model_to_dict(row.rut)
|
||||||
|
|
||||||
|
def get_rol(self, row):
|
||||||
|
return model_to_dict(row.id_rol)
|
||||||
|
|
||||||
def to_representation(self, instance):
|
def to_representation(self, instance):
|
||||||
representation = super().to_representation(instance)
|
representation = super().to_representation(instance)
|
||||||
|
|
||||||
|
|
|
@ -34,5 +34,4 @@ urlpatterns = [
|
||||||
path('mapas/paraderos/', mapa.paraderos, name='mapa-paraderos'),
|
path('mapas/paraderos/', mapa.paraderos, name='mapa-paraderos'),
|
||||||
path('mapas/rutas/', mapa.rutas, name='mapa-rutas'),
|
path('mapas/rutas/', mapa.rutas, name='mapa-rutas'),
|
||||||
path('paraderos/info-public/<int:pk>/', paradero.info_public, name='paradero-infopublic'),
|
path('paraderos/info-public/<int:pk>/', paradero.info_public, name='paradero-infopublic'),
|
||||||
# path('proto/status/', proto.status, name='proto_status'),
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
from .. import models, serializers
|
from .. import models, serializers
|
||||||
|
from django.db import models as dj_models
|
||||||
|
|
||||||
class AplicacionViewSet(viewsets.ModelViewSet):
|
class AplicacionViewSet(viewsets.ModelViewSet):
|
||||||
queryset = models.Aplicacion.objects.all()
|
queryset = models.Aplicacion.objects.all()
|
||||||
serializer_class = serializers.AplicacionSerializer
|
serializer_class = serializers.AplicacionSerializer
|
||||||
ordering_fields = '__all__'
|
ordering_fields = '__all__'
|
||||||
|
|
||||||
|
def create(self, request, *args, **kwargs):
|
||||||
|
# se indica que si no se indico el id, entonces sea el maximo + 1
|
||||||
|
if not request.data.get('id_aplicacion', None):
|
||||||
|
max_id = models.Aplicacion.objects.aggregate(dj_models.Max('id_aplicacion'))['id_aplicacion__max']
|
||||||
|
new_id = max_id + 1 if max_id is not None else 1
|
||||||
|
request.data['id_aplicacion'] = new_id
|
||||||
|
|
||||||
|
return super().create(request, *args, **kwargs)
|
|
@ -1,46 +0,0 @@
|
||||||
|
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
|
||||||
from rest_framework.decorators import action, api_view
|
|
||||||
from api.utils import gtfs_realtime_pb2
|
|
||||||
from project.settings import BASE_DIR
|
|
||||||
from django.http import JsonResponse
|
|
||||||
import logging
|
|
||||||
|
|
||||||
def status(request):
|
|
||||||
nombre_archivo_proto = f'{BASE_DIR}/api/utils/demo.proto'
|
|
||||||
with open(nombre_archivo_proto, 'rb') as proto_file:
|
|
||||||
feed = gtfs_realtime_pb2.FeedMessage()
|
|
||||||
feed.ParseFromString(proto_file.read())
|
|
||||||
|
|
||||||
data = {} #get_object(feed)
|
|
||||||
# logging.error(dir(feed))
|
|
||||||
# logging.error(feed.header)
|
|
||||||
# logging.error(dir(feed.entity))
|
|
||||||
logging.error(feed.entity[0])
|
|
||||||
# logging.error(dir(feed.entity[0].trip_update))
|
|
||||||
|
|
||||||
return JsonResponse(data, safe=False)
|
|
||||||
|
|
||||||
|
|
||||||
def get_object(obj1, obj2 = {}, level = 1):
|
|
||||||
attributes = dir(obj1)
|
|
||||||
for attr in attributes:
|
|
||||||
if attr[0:1] != '_':
|
|
||||||
try:
|
|
||||||
for elem in obj1[attr]:
|
|
||||||
logging.error(elem)
|
|
||||||
except:
|
|
||||||
logging.error(attr)
|
|
||||||
pass
|
|
||||||
return obj2
|
|
||||||
|
|
||||||
|
|
||||||
def is_subscriptable(obj):
|
|
||||||
return hasattr(obj, '__getitem__')
|
|
||||||
|
|
||||||
def is_iterable(obj):
|
|
||||||
try:
|
|
||||||
iter(obj)
|
|
||||||
return True
|
|
||||||
except TypeError:
|
|
||||||
return False
|
|
|
@ -5,8 +5,6 @@ import logging
|
||||||
class RolAplicacionViewSet(viewsets.ModelViewSet):
|
class RolAplicacionViewSet(viewsets.ModelViewSet):
|
||||||
serializer_class = serializers.RolAplicacionSerializer
|
serializer_class = serializers.RolAplicacionSerializer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
id_rol = self.request.query_params.get('id_rol') # Obtener el valor del parámetro id_rol desde la solicitud
|
id_rol = self.request.query_params.get('id_rol') # Obtener el valor del parámetro id_rol desde la solicitud
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse, JsonResponse
|
||||||
|
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.decorators import action
|
||||||
|
|
||||||
from .. import models, schemas, serializers
|
from .. import models, schemas, serializers
|
||||||
import json
|
import json
|
||||||
|
@ -24,8 +24,6 @@ class UsuarioViewSet(viewsets.ModelViewSet):
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
input = json.loads(request.body)
|
input = json.loads(request.body)
|
||||||
|
|
||||||
# validaciones se realiza a nivel del model
|
|
||||||
|
|
||||||
persona = models.Persona.objects.filter(rut = input['rut']).first()
|
persona = models.Persona.objects.filter(rut = input['rut']).first()
|
||||||
id_tipo_tratamiento = input.get('id_tipo_tratamiento',None)
|
id_tipo_tratamiento = input.get('id_tipo_tratamiento',None)
|
||||||
if not id_tipo_tratamiento:
|
if not id_tipo_tratamiento:
|
||||||
|
@ -106,14 +104,18 @@ class UsuarioViewSet(viewsets.ModelViewSet):
|
||||||
# validaciones se realiza a nivel del model
|
# validaciones se realiza a nivel del model
|
||||||
|
|
||||||
persona = models.Persona.objects.filter(rut = pk).first()
|
persona = models.Persona.objects.filter(rut = pk).first()
|
||||||
|
rol = models.Rol.objects.filter(id_rol = input.get('id_rol')).first()
|
||||||
|
|
||||||
usuario = models.Usuario.objects.filter(rut = pk).first()
|
usuario = models.Usuario.objects.filter(rut = pk).first()
|
||||||
usuario.vigente = input.get('vigente', False)
|
usuario.vigente = input.get('vigente', False)
|
||||||
|
usuario.superuser = input.get('superuser', False)
|
||||||
|
usuario.id_rol = rol
|
||||||
usuario.save()
|
usuario.save()
|
||||||
|
|
||||||
logging.error(f'clave = {input["clave"]}')
|
if 'clave' in input:
|
||||||
if input['clave']:
|
|
||||||
logging.error('Modificar clave de usuario')
|
logging.error('Modificar clave de usuario')
|
||||||
|
logging.error(f'clave = {input["clave"]}')
|
||||||
|
|
||||||
clave = models.UsuarioClave.objects.filter(login = usuario.login).first()
|
clave = models.UsuarioClave.objects.filter(login = usuario.login).first()
|
||||||
if clave:
|
if clave:
|
||||||
logging.error('Clave Usuario ya existe')
|
logging.error('Clave Usuario ya existe')
|
||||||
|
@ -147,5 +149,21 @@ class UsuarioViewSet(viewsets.ModelViewSet):
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
transaction.rollback()
|
transaction.rollback()
|
||||||
print(e)
|
logging.error(e)
|
||||||
return HttpResponse(str(e), status = 500)
|
return HttpResponse(str(e), status = 500)
|
||||||
|
|
||||||
|
@action(detail=False, methods=['post'])
|
||||||
|
def permiso(self, request):
|
||||||
|
input = json.loads(request.body)
|
||||||
|
|
||||||
|
logging.error(request.jwt_info)
|
||||||
|
usuario = models.Usuario.objects.filter(login=input['login'])
|
||||||
|
|
||||||
|
|
||||||
|
return JsonResponse({
|
||||||
|
"path": input['path'],
|
||||||
|
"permisos": {
|
||||||
|
"": 1,
|
||||||
|
"MensajeParadero": "No considerar, uso futuro"
|
||||||
|
}
|
||||||
|
})
|
Loading…
Reference in New Issue