Private
Public Access
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a38b1aaf9a | ||
|
|
ace1a9c2f0 | ||
|
|
22b2b7d2d0 | ||
|
|
38e040354a | ||
|
|
3c26c7e6e9 | ||
|
|
62ec25b768 | ||
|
|
eff116fab0 | ||
|
|
69395cc6d7 |
No files matched your search
@@ -0,0 +1,594 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<gaphor xmlns="https://gaphor.org/model" xmlns:Core="https://gaphor.org/modelinglanguage/Core" xmlns:UML="https://gaphor.org/modelinglanguage/UML" version="4" gaphor-version="3.3.2">
|
||||
<model>
|
||||
<Core:StyleSheet id="58d6989a-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
<UML:Package id="58d6c2e8-66f8-11ec-b4c8-0456e5e540ed">
|
||||
<name>
|
||||
<val>Modelo nuevo</val>
|
||||
</name>
|
||||
<ownedDiagram>
|
||||
<reflist>
|
||||
<ref refid="58d6c536-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</reflist>
|
||||
</ownedDiagram>
|
||||
<ownedType>
|
||||
<reflist>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
<ref refid="35b002aa-6454-11f1-8f58-afa4ef76e11f"/>
|
||||
<ref refid="373b901d-6454-11f1-875f-afa4ef76e11f"/>
|
||||
<ref refid="5096ac9c-64c8-11f1-a2c9-dd61cd41bc18"/>
|
||||
</reflist>
|
||||
</ownedType>
|
||||
<packagedElement>
|
||||
<reflist>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
<ref refid="35b002aa-6454-11f1-8f58-afa4ef76e11f"/>
|
||||
<ref refid="373b901d-6454-11f1-875f-afa4ef76e11f"/>
|
||||
<ref refid="5096ac9c-64c8-11f1-a2c9-dd61cd41bc18"/>
|
||||
</reflist>
|
||||
</packagedElement>
|
||||
</UML:Package>
|
||||
<UML:Diagram id="58d6c536-66f8-11ec-b4c8-0456e5e540ed">
|
||||
<element>
|
||||
<ref refid="58d6c2e8-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</element>
|
||||
<name>
|
||||
<val>diagrama de clases</val>
|
||||
</name>
|
||||
<ownedPresentation>
|
||||
<reflist>
|
||||
<ref refid="163d4142-644c-11f1-8d91-afa4ef76e11f"/>
|
||||
<ref refid="35b17be4-6454-11f1-bd68-afa4ef76e11f"/>
|
||||
<ref refid="373d066f-6454-11f1-b9a6-afa4ef76e11f"/>
|
||||
<ref refid="11c24487-64c8-11f1-b76a-dd61cd41bc18"/>
|
||||
<ref refid="16320b23-64c8-11f1-83d1-dd61cd41bc18"/>
|
||||
<ref refid="3fdefaed-64c8-11f1-9835-dd61cd41bc18"/>
|
||||
</reflist>
|
||||
</ownedPresentation>
|
||||
</UML:Diagram>
|
||||
<UML:Class id="163b1d1c-644c-11f1-99a2-afa4ef76e11f">
|
||||
<name>
|
||||
<val>Grupo</val>
|
||||
</name>
|
||||
<note>
|
||||
<val></val>
|
||||
</note>
|
||||
<ownedAttribute>
|
||||
<reflist>
|
||||
<ref refid="c928be9d-64c4-11f1-85d8-dd61cd41bc18"/>
|
||||
<ref refid="cd1c016d-64c4-11f1-8f15-dd61cd41bc18"/>
|
||||
<ref refid="d1edd7de-64c4-11f1-a507-dd61cd41bc18"/>
|
||||
<ref refid="df08e449-64c4-11f1-8355-dd61cd41bc18"/>
|
||||
<ref refid="ed13f968-64c4-11f1-9708-dd61cd41bc18"/>
|
||||
<ref refid="f3ec2533-64c4-11f1-ae1b-dd61cd41bc18"/>
|
||||
<ref refid="fad987fd-64c4-11f1-8ec6-dd61cd41bc18"/>
|
||||
<ref refid="05b95a06-64c5-11f1-ac9a-dd61cd41bc18"/>
|
||||
<ref refid="0cc92d16-64c5-11f1-b1b1-dd61cd41bc18"/>
|
||||
<ref refid="50986f7e-64c8-11f1-b703-dd61cd41bc18"/>
|
||||
</reflist>
|
||||
</ownedAttribute>
|
||||
<ownedOperation>
|
||||
<reflist>
|
||||
<ref refid="806ba58b-64c7-11f1-808b-dd61cd41bc18"/>
|
||||
</reflist>
|
||||
</ownedOperation>
|
||||
<owningPackage>
|
||||
<ref refid="58d6c2e8-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</owningPackage>
|
||||
<package>
|
||||
<ref refid="58d6c2e8-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</package>
|
||||
<presentation>
|
||||
<reflist>
|
||||
<ref refid="163d4142-644c-11f1-8d91-afa4ef76e11f"/>
|
||||
</reflist>
|
||||
</presentation>
|
||||
</UML:Class>
|
||||
<UML:ClassItem id="163d4142-644c-11f1-8d91-afa4ef76e11f">
|
||||
<matrix>
|
||||
<val>(1.0, 0.0, 0.0, 1.0, 217.4180145263672, 320.26953125)</val>
|
||||
</matrix>
|
||||
<top-left>
|
||||
<val>(0.0, 0.0)</val>
|
||||
</top-left>
|
||||
<width>
|
||||
<val>189.0</val>
|
||||
</width>
|
||||
<height>
|
||||
<val>227.0</val>
|
||||
</height>
|
||||
<diagram>
|
||||
<ref refid="58d6c536-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</diagram>
|
||||
<subject>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
</subject>
|
||||
</UML:ClassItem>
|
||||
<UML:Class id="35b002aa-6454-11f1-8f58-afa4ef76e11f">
|
||||
<name>
|
||||
<val>IPermisosComponente</val>
|
||||
</name>
|
||||
<ownedOperation>
|
||||
<reflist>
|
||||
<ref refid="af959885-6454-11f1-81d6-afa4ef76e11f"/>
|
||||
</reflist>
|
||||
</ownedOperation>
|
||||
<owningPackage>
|
||||
<ref refid="58d6c2e8-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</owningPackage>
|
||||
<package>
|
||||
<ref refid="58d6c2e8-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</package>
|
||||
<presentation>
|
||||
<reflist>
|
||||
<ref refid="35b17be4-6454-11f1-bd68-afa4ef76e11f"/>
|
||||
</reflist>
|
||||
</presentation>
|
||||
</UML:Class>
|
||||
<UML:ClassItem id="35b17be4-6454-11f1-bd68-afa4ef76e11f">
|
||||
<matrix>
|
||||
<val>(1.0, 0.0, 0.0, 1.0, 131.24998474121094, 160.56248474121094)</val>
|
||||
</matrix>
|
||||
<top-left>
|
||||
<val>(0.0, 0.0)</val>
|
||||
</top-left>
|
||||
<width>
|
||||
<val>185.0</val>
|
||||
</width>
|
||||
<height>
|
||||
<val>74.0</val>
|
||||
</height>
|
||||
<diagram>
|
||||
<ref refid="58d6c536-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</diagram>
|
||||
<show_attributes>
|
||||
<val>0</val>
|
||||
</show_attributes>
|
||||
<subject>
|
||||
<ref refid="35b002aa-6454-11f1-8f58-afa4ef76e11f"/>
|
||||
</subject>
|
||||
</UML:ClassItem>
|
||||
<UML:Class id="373b901d-6454-11f1-875f-afa4ef76e11f">
|
||||
<name>
|
||||
<val>Permiso</val>
|
||||
</name>
|
||||
<ownedAttribute>
|
||||
<reflist>
|
||||
<ref refid="e7861f8f-64c1-11f1-9f45-dd61cd41bc18"/>
|
||||
<ref refid="ec4c0956-64c1-11f1-9c2e-dd61cd41bc18"/>
|
||||
<ref refid="f81eb2a5-64c1-11f1-afa8-dd61cd41bc18"/>
|
||||
<ref refid="cb721a7a-64c2-11f1-8024-dd61cd41bc18"/>
|
||||
<ref refid="d16738ed-64c2-11f1-b18d-dd61cd41bc18"/>
|
||||
<ref refid="d5b17a37-64c2-11f1-8263-dd61cd41bc18"/>
|
||||
<ref refid="d8a24ad1-64c2-11f1-b5c2-dd61cd41bc18"/>
|
||||
</reflist>
|
||||
</ownedAttribute>
|
||||
<ownedOperation>
|
||||
<reflist>
|
||||
<ref refid="7e7db7f1-64c7-11f1-9ad2-dd61cd41bc18"/>
|
||||
</reflist>
|
||||
</ownedOperation>
|
||||
<owningPackage>
|
||||
<ref refid="58d6c2e8-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</owningPackage>
|
||||
<package>
|
||||
<ref refid="58d6c2e8-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</package>
|
||||
<presentation>
|
||||
<reflist>
|
||||
<ref refid="373d066f-6454-11f1-b9a6-afa4ef76e11f"/>
|
||||
</reflist>
|
||||
</presentation>
|
||||
</UML:Class>
|
||||
<UML:ClassItem id="373d066f-6454-11f1-b9a6-afa4ef76e11f">
|
||||
<matrix>
|
||||
<val>(1.0, 0.0, 0.0, 1.0, -4.1602020263671875, 337.26953125)</val>
|
||||
</matrix>
|
||||
<top-left>
|
||||
<val>(0.0, 0.0)</val>
|
||||
</top-left>
|
||||
<width>
|
||||
<val>163.0</val>
|
||||
</width>
|
||||
<height>
|
||||
<val>193.0</val>
|
||||
</height>
|
||||
<diagram>
|
||||
<ref refid="58d6c536-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</diagram>
|
||||
<subject>
|
||||
<ref refid="373b901d-6454-11f1-875f-afa4ef76e11f"/>
|
||||
</subject>
|
||||
</UML:ClassItem>
|
||||
<UML:Operation id="af959885-6454-11f1-81d6-afa4ef76e11f">
|
||||
<class_>
|
||||
<ref refid="35b002aa-6454-11f1-8f58-afa4ef76e11f"/>
|
||||
</class_>
|
||||
<name>
|
||||
<val>Buscar</val>
|
||||
</name>
|
||||
<ownedParameter>
|
||||
<reflist>
|
||||
<ref refid="afaabcb9-6454-11f1-8e71-afa4ef76e11f"/>
|
||||
<ref refid="a384a881-64c7-11f1-bdcb-dd61cd41bc18"/>
|
||||
</reflist>
|
||||
</ownedParameter>
|
||||
</UML:Operation>
|
||||
<UML:Parameter id="afaabcb9-6454-11f1-8e71-afa4ef76e11f">
|
||||
<name>
|
||||
<val>id</val>
|
||||
</name>
|
||||
<ownerFormalParam>
|
||||
<ref refid="af959885-6454-11f1-81d6-afa4ef76e11f"/>
|
||||
</ownerFormalParam>
|
||||
<typeValue>
|
||||
<val>int</val>
|
||||
</typeValue>
|
||||
</UML:Parameter>
|
||||
<UML:Property id="e7861f8f-64c1-11f1-9f45-dd61cd41bc18">
|
||||
<name>
|
||||
<val>id</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="373b901d-6454-11f1-875f-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
<typeValue>
|
||||
<val>uint</val>
|
||||
</typeValue>
|
||||
</UML:Property>
|
||||
<UML:Property id="ec4c0956-64c1-11f1-9c2e-dd61cd41bc18">
|
||||
<name>
|
||||
<val>nombre</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="373b901d-6454-11f1-875f-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
<typeValue>
|
||||
<val>string</val>
|
||||
</typeValue>
|
||||
</UML:Property>
|
||||
<UML:Property id="f81eb2a5-64c1-11f1-afa8-dd61cd41bc18">
|
||||
<name>
|
||||
<val>alias</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="373b901d-6454-11f1-875f-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
<typeValue>
|
||||
<val>string</val>
|
||||
</typeValue>
|
||||
</UML:Property>
|
||||
<UML:Property id="cb721a7a-64c2-11f1-8024-dd61cd41bc18">
|
||||
<name>
|
||||
<val>descripcion</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="373b901d-6454-11f1-875f-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
<typeValue>
|
||||
<val>string</val>
|
||||
</typeValue>
|
||||
</UML:Property>
|
||||
<UML:Property id="d16738ed-64c2-11f1-b18d-dd61cd41bc18">
|
||||
<name>
|
||||
<val>createdAt</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="373b901d-6454-11f1-875f-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
<typeValue>
|
||||
<val>Time</val>
|
||||
</typeValue>
|
||||
</UML:Property>
|
||||
<UML:Property id="d5b17a37-64c2-11f1-8263-dd61cd41bc18">
|
||||
<name>
|
||||
<val>updatedAt</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="373b901d-6454-11f1-875f-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
<typeValue>
|
||||
<val>Time</val>
|
||||
</typeValue>
|
||||
</UML:Property>
|
||||
<UML:Property id="d8a24ad1-64c2-11f1-b5c2-dd61cd41bc18">
|
||||
<name>
|
||||
<val>deletedAt</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="373b901d-6454-11f1-875f-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
<typeValue>
|
||||
<val>Time</val>
|
||||
</typeValue>
|
||||
</UML:Property>
|
||||
<UML:Property id="c928be9d-64c4-11f1-85d8-dd61cd41bc18">
|
||||
<name>
|
||||
<val>id</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
<typeValue>
|
||||
<val>uint</val>
|
||||
</typeValue>
|
||||
</UML:Property>
|
||||
<UML:Property id="cd1c016d-64c4-11f1-8f15-dd61cd41bc18">
|
||||
<name>
|
||||
<val>nombre</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
<typeValue>
|
||||
<val>string</val>
|
||||
</typeValue>
|
||||
</UML:Property>
|
||||
<UML:Property id="d1edd7de-64c4-11f1-a507-dd61cd41bc18">
|
||||
<name>
|
||||
<val>descripcion</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
<typeValue>
|
||||
<val>string</val>
|
||||
</typeValue>
|
||||
</UML:Property>
|
||||
<UML:Property id="df08e449-64c4-11f1-8355-dd61cd41bc18">
|
||||
<name>
|
||||
<val>permisos: []Permiso</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
</UML:Property>
|
||||
<UML:Property id="ed13f968-64c4-11f1-9708-dd61cd41bc18">
|
||||
<name>
|
||||
<val>grupos: []Grupo</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
</UML:Property>
|
||||
<UML:Property id="f3ec2533-64c4-11f1-ae1b-dd61cd41bc18">
|
||||
<name>
|
||||
<val>usuarios: []Usuario</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
</UML:Property>
|
||||
<UML:Property id="fad987fd-64c4-11f1-8ec6-dd61cd41bc18">
|
||||
<name>
|
||||
<val>createdAt</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
<typeValue>
|
||||
<val>Time</val>
|
||||
</typeValue>
|
||||
</UML:Property>
|
||||
<UML:Property id="05b95a06-64c5-11f1-ac9a-dd61cd41bc18">
|
||||
<name>
|
||||
<val>updatedAt</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
<typeValue>
|
||||
<val>Time</val>
|
||||
</typeValue>
|
||||
</UML:Property>
|
||||
<UML:Property id="0cc92d16-64c5-11f1-b1b1-dd61cd41bc18">
|
||||
<name>
|
||||
<val>deletedAt</val>
|
||||
</name>
|
||||
<structuredClassifier>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
<typeValue>
|
||||
<val>Time</val>
|
||||
</typeValue>
|
||||
</UML:Property>
|
||||
<UML:Operation id="7e7db7f1-64c7-11f1-9ad2-dd61cd41bc18">
|
||||
<class_>
|
||||
<ref refid="373b901d-6454-11f1-875f-afa4ef76e11f"/>
|
||||
</class_>
|
||||
<name>
|
||||
<val>Buscar</val>
|
||||
</name>
|
||||
<ownedParameter>
|
||||
<reflist>
|
||||
<ref refid="7e8b62f0-64c7-11f1-9d36-dd61cd41bc18"/>
|
||||
<ref refid="bb03d334-64c7-11f1-a954-dd61cd41bc18"/>
|
||||
</reflist>
|
||||
</ownedParameter>
|
||||
</UML:Operation>
|
||||
<UML:Parameter id="7e8b62f0-64c7-11f1-9d36-dd61cd41bc18">
|
||||
<name>
|
||||
<val>id</val>
|
||||
</name>
|
||||
<ownerFormalParam>
|
||||
<ref refid="7e7db7f1-64c7-11f1-9ad2-dd61cd41bc18"/>
|
||||
</ownerFormalParam>
|
||||
<typeValue>
|
||||
<val>int</val>
|
||||
</typeValue>
|
||||
</UML:Parameter>
|
||||
<UML:Operation id="806ba58b-64c7-11f1-808b-dd61cd41bc18">
|
||||
<class_>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
</class_>
|
||||
<name>
|
||||
<val>Buscar</val>
|
||||
</name>
|
||||
<ownedParameter>
|
||||
<reflist>
|
||||
<ref refid="bda0bb00-64c7-11f1-8d47-dd61cd41bc18"/>
|
||||
<ref refid="bdaf2142-64c7-11f1-ab71-dd61cd41bc18"/>
|
||||
</reflist>
|
||||
</ownedParameter>
|
||||
</UML:Operation>
|
||||
<UML:Parameter id="a384a881-64c7-11f1-bdcb-dd61cd41bc18">
|
||||
<direction>
|
||||
<val>return</val>
|
||||
</direction>
|
||||
<ownerFormalParam>
|
||||
<ref refid="af959885-6454-11f1-81d6-afa4ef76e11f"/>
|
||||
</ownerFormalParam>
|
||||
<typeValue>
|
||||
<val>bool</val>
|
||||
</typeValue>
|
||||
</UML:Parameter>
|
||||
<UML:Parameter id="bb03d334-64c7-11f1-a954-dd61cd41bc18">
|
||||
<direction>
|
||||
<val>return</val>
|
||||
</direction>
|
||||
<ownerFormalParam>
|
||||
<ref refid="7e7db7f1-64c7-11f1-9ad2-dd61cd41bc18"/>
|
||||
</ownerFormalParam>
|
||||
<typeValue>
|
||||
<val>bool</val>
|
||||
</typeValue>
|
||||
</UML:Parameter>
|
||||
<UML:Parameter id="bda0bb00-64c7-11f1-8d47-dd61cd41bc18">
|
||||
<direction>
|
||||
<val>return</val>
|
||||
</direction>
|
||||
<ownerFormalParam>
|
||||
<ref refid="806ba58b-64c7-11f1-808b-dd61cd41bc18"/>
|
||||
</ownerFormalParam>
|
||||
<typeValue>
|
||||
<val>bool</val>
|
||||
</typeValue>
|
||||
</UML:Parameter>
|
||||
<UML:Parameter id="bdaf2142-64c7-11f1-ab71-dd61cd41bc18">
|
||||
<name>
|
||||
<val>id</val>
|
||||
</name>
|
||||
<ownerFormalParam>
|
||||
<ref refid="806ba58b-64c7-11f1-808b-dd61cd41bc18"/>
|
||||
</ownerFormalParam>
|
||||
<typeValue>
|
||||
<val>int</val>
|
||||
</typeValue>
|
||||
</UML:Parameter>
|
||||
<UML:InterfaceRealizationItem id="11c24487-64c8-11f1-b76a-dd61cd41bc18">
|
||||
<diagram>
|
||||
<ref refid="58d6c536-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</diagram>
|
||||
<horizontal>
|
||||
<val>False</val>
|
||||
</horizontal>
|
||||
<matrix>
|
||||
<val>(1.0, 0.0, 0.0, 1.0, 288.2343444824219, 316.75613840562283)</val>
|
||||
</matrix>
|
||||
<points>
|
||||
<val>[(-64.48435974121094, -82.19365366441193), (0.828125, 3.513392844377165)]</val>
|
||||
</points>
|
||||
<tail-connection>
|
||||
<ref refid="163d4142-644c-11f1-8d91-afa4ef76e11f"/>
|
||||
</tail-connection>
|
||||
</UML:InterfaceRealizationItem>
|
||||
<UML:InterfaceRealizationItem id="16320b23-64c8-11f1-83d1-dd61cd41bc18">
|
||||
<diagram>
|
||||
<ref refid="58d6c536-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</diagram>
|
||||
<horizontal>
|
||||
<val>False</val>
|
||||
</horizontal>
|
||||
<matrix>
|
||||
<val>(1.0, 0.0, 0.0, 1.0, 128.17581176757812, 312.67410715562283)</val>
|
||||
</matrix>
|
||||
<points>
|
||||
<val>[(83.17962646484375, -78.11162241441193), (-22.941436767578125, 24.595424094377165)]</val>
|
||||
</points>
|
||||
<tail-connection>
|
||||
<ref refid="373d066f-6454-11f1-b9a6-afa4ef76e11f"/>
|
||||
</tail-connection>
|
||||
</UML:InterfaceRealizationItem>
|
||||
<UML:AssociationItem id="3fdefaed-64c8-11f1-9835-dd61cd41bc18">
|
||||
<diagram>
|
||||
<ref refid="58d6c536-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</diagram>
|
||||
<head_subject>
|
||||
<ref refid="50984a3a-64c8-11f1-8a95-dd61cd41bc18"/>
|
||||
</head_subject>
|
||||
<horizontal>
|
||||
<val>False</val>
|
||||
</horizontal>
|
||||
<orthogonal>
|
||||
<val>False</val>
|
||||
</orthogonal>
|
||||
<subject>
|
||||
<ref refid="5096ac9c-64c8-11f1-a2c9-dd61cd41bc18"/>
|
||||
</subject>
|
||||
<tail_subject>
|
||||
<ref refid="50986f7e-64c8-11f1-b703-dd61cd41bc18"/>
|
||||
</tail_subject>
|
||||
<matrix>
|
||||
<val>(1.0, 0.0, 0.0, 1.0, 450.11328125, 439.22265625)</val>
|
||||
</matrix>
|
||||
<points>
|
||||
<val>[(-43.69526672363281, -5.453125), (-7.6953125, -5.453125), (-7.6953125, -250.39620534437717), (-133.86329650878906, -250.39620534437717)]</val>
|
||||
</points>
|
||||
<head-connection>
|
||||
<ref refid="163d4142-644c-11f1-8d91-afa4ef76e11f"/>
|
||||
</head-connection>
|
||||
<tail-connection>
|
||||
<ref refid="35b17be4-6454-11f1-bd68-afa4ef76e11f"/>
|
||||
</tail-connection>
|
||||
</UML:AssociationItem>
|
||||
<UML:Association id="5096ac9c-64c8-11f1-a2c9-dd61cd41bc18">
|
||||
<memberEnd>
|
||||
<reflist>
|
||||
<ref refid="50984a3a-64c8-11f1-8a95-dd61cd41bc18"/>
|
||||
<ref refid="50986f7e-64c8-11f1-b703-dd61cd41bc18"/>
|
||||
</reflist>
|
||||
</memberEnd>
|
||||
<ownedEnd>
|
||||
<reflist>
|
||||
<ref refid="50984a3a-64c8-11f1-8a95-dd61cd41bc18"/>
|
||||
</reflist>
|
||||
</ownedEnd>
|
||||
<owningPackage>
|
||||
<ref refid="58d6c2e8-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</owningPackage>
|
||||
<package>
|
||||
<ref refid="58d6c2e8-66f8-11ec-b4c8-0456e5e540ed"/>
|
||||
</package>
|
||||
<presentation>
|
||||
<reflist>
|
||||
<ref refid="3fdefaed-64c8-11f1-9835-dd61cd41bc18"/>
|
||||
</reflist>
|
||||
</presentation>
|
||||
</UML:Association>
|
||||
<UML:Property id="50984a3a-64c8-11f1-8a95-dd61cd41bc18">
|
||||
<association>
|
||||
<ref refid="5096ac9c-64c8-11f1-a2c9-dd61cd41bc18"/>
|
||||
</association>
|
||||
<owningAssociation>
|
||||
<ref refid="5096ac9c-64c8-11f1-a2c9-dd61cd41bc18"/>
|
||||
</owningAssociation>
|
||||
<type>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
</type>
|
||||
</UML:Property>
|
||||
<UML:Property id="50986f7e-64c8-11f1-b703-dd61cd41bc18">
|
||||
<aggregation>
|
||||
<val>shared</val>
|
||||
</aggregation>
|
||||
<association>
|
||||
<ref refid="5096ac9c-64c8-11f1-a2c9-dd61cd41bc18"/>
|
||||
</association>
|
||||
<structuredClassifier>
|
||||
<ref refid="163b1d1c-644c-11f1-99a2-afa4ef76e11f"/>
|
||||
</structuredClassifier>
|
||||
<type>
|
||||
<ref refid="35b002aa-6454-11f1-8f58-afa4ef76e11f"/>
|
||||
</type>
|
||||
</UML:Property>
|
||||
</model>
|
||||
</gaphor>
|
||||
@@ -0,0 +1,71 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"repuestera_back/config"
|
||||
"repuestera_back/dto"
|
||||
models_seguridad "repuestera_back/models/seguridad"
|
||||
"repuestera_back/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func CambiarContraseña(c *gin.Context) {
|
||||
var req dto.CambiarContraseñaRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.NewPassword) < 8 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "La nueva contraseña debe tener mas de 8 caracteres"})
|
||||
return
|
||||
}
|
||||
|
||||
authUserID, _ := c.Get("userID")
|
||||
authUserIDUint, _ := authUserID.(uint)
|
||||
|
||||
targetID := authUserIDUint
|
||||
if req.UserID != 0 {
|
||||
targetID = req.UserID
|
||||
}
|
||||
|
||||
esAdmin := utils.UsuarioTienePermiso(c, 3)
|
||||
|
||||
if targetID != authUserIDUint && !esAdmin {
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": "No tienes permiso para cambiar la contraseña de otro usuario"})
|
||||
return
|
||||
}
|
||||
|
||||
var user models_seguridad.Usuario
|
||||
if err := config.DB.First(&user, targetID).Error; err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "usuario no encontrado"})
|
||||
return
|
||||
}
|
||||
|
||||
if !esAdmin {
|
||||
if req.OldPassword == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Se requiere la contraseña actual"})
|
||||
return
|
||||
}
|
||||
if err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(req.OldPassword)); err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "contraseña actual incorrecta"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(req.NewPassword), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error al procesar la contraseña"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := config.DB.Model(&user).Update("password", string(hashedPassword)).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error al actualizar la contraseña"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Contraseña actualizada exitosamente"})
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"repuestera_back/config"
|
||||
"repuestera_back/dto"
|
||||
"repuestera_back/jwtutils"
|
||||
models_seguridad "repuestera_back/models/seguridad"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -14,8 +15,6 @@ import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
var JWTSecret = []byte("supersecretkey123456789")
|
||||
|
||||
func Login(c *gin.Context) {
|
||||
var req dto.LoginRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -65,5 +64,5 @@ func generarToken(user models_seguridad.Usuario, duration time.Duration) (string
|
||||
}
|
||||
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
return token.SignedString(JWTSecret)
|
||||
return token.SignedString(jwtutils.JWTSecret)
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"repuestera_back/config"
|
||||
"repuestera_back/dto"
|
||||
"repuestera_back/jwtutils"
|
||||
models_seguridad "repuestera_back/models/seguridad"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -31,7 +32,7 @@ func Me(c *gin.Context) {
|
||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||
return nil, jwt.ErrSignatureInvalid
|
||||
}
|
||||
return JWTSecret, nil
|
||||
return jwtutils.JWTSecret, nil
|
||||
})
|
||||
|
||||
if err != nil || !token.Valid {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"repuestera_back/config"
|
||||
"repuestera_back/dto"
|
||||
"repuestera_back/jwtutils"
|
||||
models_seguridad "repuestera_back/models/seguridad"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -24,7 +25,7 @@ func Refresh(c *gin.Context) {
|
||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||
return nil, jwt.ErrSignatureInvalid
|
||||
}
|
||||
return JWTSecret, nil
|
||||
return jwtutils.JWTSecret, nil
|
||||
})
|
||||
|
||||
if err != nil || !token.Valid {
|
||||
|
||||
@@ -2,6 +2,7 @@ package permission
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repuestera_back/config"
|
||||
"repuestera_back/dto"
|
||||
@@ -10,7 +11,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func AsignarPermisoAGrupo(c *gin.Context) {
|
||||
func AgregarPermisoAGrupo(c *gin.Context) {
|
||||
var req dto.GrupoPermisoRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
@@ -105,3 +106,76 @@ func QuitarSubGrupo(c *gin.Context) {
|
||||
config.DB.Model(&padre).Association("Grupos").Delete(&hijo)
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Subgrupo quitado"})
|
||||
}
|
||||
|
||||
func AgregarGrupoAUsuario(c *gin.Context) {
|
||||
var req dto.GrupoUsuarioRelacion
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
trans := config.DB.Begin()
|
||||
if trans.Error != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "no se pudo iniciar la transaccion"})
|
||||
return
|
||||
}
|
||||
|
||||
var usu models_seguridad.Usuario
|
||||
trans.Find(&usu, req.UsuarioID)
|
||||
err := trans.Model(&models_seguridad.Usuario{ID: req.UsuarioID}).Association("Grupos").Append(&models_seguridad.Grupo{ID: req.GrupoID})
|
||||
trans.Commit()
|
||||
if err != nil {
|
||||
trans.Rollback()
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "no se pudo añadir el grupo al usuario"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, usu)
|
||||
}
|
||||
|
||||
func QuitarGrupoAUsuario(c *gin.Context) {
|
||||
var req dto.GrupoUsuarioRelacion
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
trans := config.DB.Begin()
|
||||
if trans.Error != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "no se pudo iniciar la transaccion"})
|
||||
return
|
||||
}
|
||||
|
||||
var usu models_seguridad.Usuario
|
||||
trans.Find(&usu, req.UsuarioID)
|
||||
err := trans.Model(&models_seguridad.Usuario{ID: req.UsuarioID}).Association("Grupos").Delete(&models_seguridad.Grupo{ID: req.GrupoID})
|
||||
trans.Commit()
|
||||
if err != nil {
|
||||
trans.Rollback()
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "no se pudo quitar el grupo al usuario"})
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
func ObtenerGruposDeUsuario(c *gin.Context) {
|
||||
var usuarioIDStr = c.Param("id");
|
||||
|
||||
|
||||
usuarioID, err := strconv.ParseUint(usuarioIDStr, 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{"error": "id invalido"})
|
||||
return
|
||||
}
|
||||
|
||||
var grupos []models_seguridad.Grupo
|
||||
err = config.DB.Preload("Permisos").Model(&models_seguridad.Usuario{ID: uint(usuarioID)}).Association("Grupos").Find(&grupos)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "no se ha podido obtener los grupos del usuario"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, grupos)
|
||||
}
|
||||
@@ -33,3 +33,9 @@ type MeResponse struct {
|
||||
type RefreshRequest struct {
|
||||
RefreshToken string `json:"refresh_token" binding:"required"`
|
||||
}
|
||||
|
||||
type CambiarContraseñaRequest struct {
|
||||
UserID uint `json:"user_id"`
|
||||
OldPassword string `json:"old_password"`
|
||||
NewPassword string `json:"new_password" binding:"required"`
|
||||
}
|
||||
@@ -24,3 +24,12 @@ type GruposYPermisosResponse struct {
|
||||
Email string `json:"email"`
|
||||
Groups []GrupoInfo `json:"groups"`
|
||||
}
|
||||
|
||||
type GrupoUsuarioRelacion struct {
|
||||
GrupoID uint `json:"grupo_id" binding:"required"`
|
||||
UsuarioID uint `json:"usuario_id" binding:"required"`
|
||||
}
|
||||
|
||||
type UsuarioIDRequest struct{
|
||||
UsuarioID uint `json:"usuario_id" binding:"required"`
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
package jwtutils
|
||||
|
||||
import (
|
||||
"repuestera_back/controllers/auth"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
var JWTSecret = []byte("supersecretkey123456789")
|
||||
|
||||
func ValidarJWT(tokenString string) (jwt.MapClaims, error) {
|
||||
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
|
||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||
return nil, jwt.ErrSignatureInvalid
|
||||
}
|
||||
return auth.JWTSecret, nil
|
||||
return JWTSecret, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -57,3 +57,27 @@ func PermisoMiddleware(permisoID uint) gin.HandlerFunc {
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
func PermisosMiddleware(permisosIDs ...uint) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if !UsuarioTieneAlgunPermiso(c, permisosIDs) {
|
||||
c.JSON(http.StatusForbidden, gin.H{
|
||||
"error": "No tienes permiso para realizar esta accion",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
func UsuarioTieneAlgunPermiso(c *gin.Context, permisosIDs []uint) bool {
|
||||
for _, permisoID := range permisosIDs {
|
||||
if utils.UsuarioTienePermiso(c, permisoID) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package routes
|
||||
|
||||
import (
|
||||
"repuestera_back/controllers/auth"
|
||||
"repuestera_back/middleware"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -13,5 +14,6 @@ func AuthRoute(r *gin.Engine) {
|
||||
authGroup.POST("/register", auth.Register)
|
||||
authGroup.POST("/refresh", auth.Refresh)
|
||||
authGroup.GET("/me", auth.Me)
|
||||
authGroup.POST("/cambiar-contraseña", middleware.AuthMiddleware(), auth.CambiarContraseña)
|
||||
}
|
||||
}
|
||||
@@ -11,14 +11,19 @@ func GroupRoute(r *gin.Engine) {
|
||||
groupGroup := r.Group("/grupos")
|
||||
groupGroup.Use(middleware.AuthMiddleware(), middleware.PermisoMiddleware(2))
|
||||
{
|
||||
groupGroup.GET("", permission.ObtenerGrupos)
|
||||
groupGroup.GET("/:id", permission.ObtenerGrupo)
|
||||
groupGroup.POST("", permission.CrearGrupo)
|
||||
groupGroup.PUT("/:id", permission.ActualizarGrupo)
|
||||
groupGroup.DELETE("/:id", permission.EliminarGrupo)
|
||||
groupGroup.POST("/:id/permisos", permission.AsignarPermisoAGrupo)
|
||||
groupGroup.POST("/:id/permisos", permission.AgregarPermisoAGrupo)
|
||||
groupGroup.DELETE("/:id/permisos", permission.QuitarPermisoAGrupo)
|
||||
groupGroup.POST("/:id/subgrupos", permission.AgregarSubGrupo)
|
||||
groupGroup.DELETE("/:id/subgrupos", permission.QuitarSubGrupo)
|
||||
}
|
||||
groupGroup2 := r.Group("/grupos")
|
||||
groupGroup2.Use(middleware.AuthMiddleware(), middleware.PermisosMiddleware(2,3))
|
||||
{
|
||||
groupGroup2.GET("", permission.ObtenerGrupos)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,15 @@ func PermissionRoute(r *gin.Engine) {
|
||||
permGroup := r.Group("/permisos")
|
||||
permGroup.Use(middleware.AuthMiddleware(), middleware.PermisoMiddleware(1))
|
||||
{
|
||||
permGroup.GET("", permission.ObtenerPermisos)
|
||||
permGroup.POST("", permission.CrearPermiso)
|
||||
permGroup.PUT("/:id", permission.ActualizarPermiso)
|
||||
permGroup.DELETE("/:id", permission.EliminarPermiso)
|
||||
}
|
||||
|
||||
permGroup2 := r.Group("/permisos")
|
||||
permGroup2.Use(middleware.AuthMiddleware(), middleware.PermisosMiddleware(1, 3))
|
||||
{
|
||||
permGroup2.GET("", permission.ObtenerPermisos)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,13 @@ func UserRoute(r *gin.Engine) {
|
||||
userGroup.PUT("/:id", usuarios.ActualizarUsuario)
|
||||
userGroup.DELETE("/:id", usuarios.EliminarUsuario)
|
||||
|
||||
userGroup.GET("/:id/grupos", permission.ObtenerGruposDeUsuario)
|
||||
userGroup.PUT("/grupos/añadir",permission.AgregarGrupoAUsuario)
|
||||
userGroup.PUT("/grupos/quitar",permission.QuitarGrupoAUsuario)
|
||||
}
|
||||
userSelfGroup := r.Group("/usuarios")
|
||||
userSelfGroup.Use(middleware.AuthMiddleware())
|
||||
{
|
||||
userSelfGroup.POST("/grupos-permisos", permission.ObtenerGruposYPermisosPorEmail)
|
||||
}
|
||||
//Esto necesita una validacion de que el usuario que pide realmente sea él
|
||||
// userGroup.GET("/:userId/permisos", permission.ObtenerPermisosUsuario)
|
||||
//
|
||||
|
||||
userGroup.POST("/grupos-permisos", permission.ObtenerGruposYPermisosPorEmail)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
export async function handleResponse<T>(response: Response): Promise<T> {
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ message: 'Error desconocido' }));
|
||||
const error = await response.json().catch(() => 'Error desconocido');
|
||||
throw new Error(error.message || 'Error en la petición');
|
||||
}
|
||||
return response.json();
|
||||
|
||||
@@ -4,6 +4,8 @@ import { API_URL } from '../env';
|
||||
import { getToken, removeToken, removeAuthTokens } from './token';
|
||||
import { removeCurrentUser } from './user';
|
||||
|
||||
//Se usa en la parte del menu donde se obtienen los grupos y permisos para mostrar
|
||||
//
|
||||
async function handleResponse<T>(response: Response): Promise<T> {
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ message: 'Error desconocido' }));
|
||||
@@ -19,7 +21,9 @@ async function handleResponse<T>(response: Response): Promise<T> {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function ObtenerGruposDeUsuario(usu: Usuario): Promise<GruposYPermisosResponse> {
|
||||
export async function ObtenerGruposDeUsuario(
|
||||
usu: Partial<Usuario>
|
||||
): Promise<GruposYPermisosResponse> {
|
||||
const response = await fetch(`${API_URL}/usuarios/grupos-permisos`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { Usuario } from '../../types';
|
||||
import { getToken } from './token';
|
||||
|
||||
export async function actualizarUsuario(dto: Partial<Usuario>) {
|
||||
if (dto.id <= 0 || !dto.email || !dto.name) return 'Faltan Datos';
|
||||
if (!dto.id || dto.id <= 0 || !dto.email || !dto.name) return 'Faltan Datos';
|
||||
try {
|
||||
const req = await fetch(`${API_URL}/usuarios/${dto.id}`, {
|
||||
method: 'PUT',
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { API_URL } from '$lib/env';
|
||||
import { getToken } from './token';
|
||||
|
||||
export async function agregarGrupoAUsuario(
|
||||
dto: { grupo_id: number; usuario_id: number },
|
||||
callback: Function
|
||||
) {
|
||||
if (!dto.grupo_id || !dto.usuario_id) return 'Faltan cargar datos';
|
||||
|
||||
try {
|
||||
const req = await fetch(`${API_URL}/usuarios/grupos/añadir`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${getToken()}`
|
||||
},
|
||||
body: JSON.stringify(dto)
|
||||
});
|
||||
|
||||
let data = await req.json();
|
||||
if (!req.ok) {
|
||||
return data.error || 'Error';
|
||||
}
|
||||
callback();
|
||||
return 'Ok';
|
||||
} catch {
|
||||
return 'No se pudo conectar con el servidor';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { API_URL } from '$lib/env';
|
||||
import { getToken } from './token';
|
||||
|
||||
export async function cambiarContraseña(dto: {
|
||||
user_id: number;
|
||||
old_password: string;
|
||||
new_password: string;
|
||||
}) {
|
||||
if (
|
||||
!dto.old_password ||
|
||||
!dto.new_password ||
|
||||
dto.old_password.length < 8 ||
|
||||
dto.new_password.length < 8
|
||||
)
|
||||
return 'Las contraseñas no alcanzan el minimo de 8 caracteres';
|
||||
try {
|
||||
const req = await fetch(`${API_URL}/auth/cambiar-contraseña`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${getToken()}`
|
||||
},
|
||||
body: JSON.stringify(dto)
|
||||
});
|
||||
|
||||
let data = await req.json();
|
||||
if (!req.ok) {
|
||||
return data.error || 'Error';
|
||||
}
|
||||
invalidate('usuarios:load');
|
||||
return 'Ok';
|
||||
} catch {
|
||||
return 'No se pudo conectar con el servidor';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { API_URL } from '$lib/env';
|
||||
import type { Usuario } from '../../types';
|
||||
import { getToken } from './token';
|
||||
|
||||
export async function crearUsuario(dto: Partial<Usuario & { password?: string }>) {
|
||||
if (!dto.password || dto.password?.length <= 8 || !dto.email || !dto.name) return 'Faltan Datos';
|
||||
console.log(dto);
|
||||
try {
|
||||
const req = await fetch(`${API_URL}/usuarios`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${getToken()}`
|
||||
},
|
||||
body: JSON.stringify(dto)
|
||||
});
|
||||
|
||||
let data = await req.json();
|
||||
if (!req.ok) {
|
||||
return data.error || 'Error';
|
||||
}
|
||||
invalidate('usuarios:load');
|
||||
return 'Ok';
|
||||
} catch {
|
||||
return 'No se pudo conectar con el servidor';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { API_URL } from '$lib/env';
|
||||
import { getToken } from './token';
|
||||
|
||||
export async function eliminarUsuario(id: number) {
|
||||
try {
|
||||
const req = await fetch(`${API_URL}/usuarios/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Authorization: `Bearer ${getToken()}`
|
||||
}
|
||||
});
|
||||
|
||||
let data = await req.json();
|
||||
if (!req.ok) {
|
||||
return data.error || 'Error';
|
||||
}
|
||||
invalidate('usuarios:load');
|
||||
return 'Ok';
|
||||
} catch {
|
||||
return 'No se pudo conectar con el servidor';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { handleResponse } from '$lib/handleRespondeJSON';
|
||||
import type { Grupo } from '../../types';
|
||||
import { API_URL } from '../env';
|
||||
import { getToken } from './token';
|
||||
|
||||
// Se usa en la parte de /usuarios
|
||||
export async function obtenerGruposDeUsuario(dto: {
|
||||
usuario_id: number;
|
||||
}): Promise<Grupo[] | string> {
|
||||
if (!dto.usuario_id) return 'Falta datos';
|
||||
const response = await fetch(`${API_URL}/usuarios/${dto.usuario_id}/grupos`, {
|
||||
headers: { Authorization: `Bearer ${getToken()}` }
|
||||
});
|
||||
|
||||
return handleResponse<Grupo[]>(response);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { API_URL } from '$lib/env';
|
||||
import { getToken } from './token';
|
||||
|
||||
export async function quitarGrupoAUsuario(
|
||||
dto: { grupo_id: number; usuario_id: number },
|
||||
callback: Function
|
||||
) {
|
||||
if (!dto.grupo_id || !dto.usuario_id) return 'Faltan cargar datos';
|
||||
|
||||
try {
|
||||
const req = await fetch(`${API_URL}/usuarios/grupos/quitar`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${getToken()}`
|
||||
},
|
||||
body: JSON.stringify(dto)
|
||||
});
|
||||
|
||||
if (!req.ok) {
|
||||
return 'Error';
|
||||
}
|
||||
callback();
|
||||
return 'Ok';
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return 'No se pudo conectar con el servidor';
|
||||
}
|
||||
}
|
||||
@@ -393,7 +393,6 @@
|
||||
Agregar
|
||||
</Button>
|
||||
</div>
|
||||
{@debug selectedGrupo}
|
||||
{#if selectedGrupo.grupos_hijos && selectedGrupo.grupos_hijos.length > 0}
|
||||
<Table size="compact">
|
||||
<TableHead>
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.length < 6) {
|
||||
error = 'La contraseña debe tener al menos 6 caracteres';
|
||||
if (password.length < 8) {
|
||||
error = 'La contraseña debe tener al menos 8 caracteres';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,26 @@
|
||||
<script lang="ts">
|
||||
import Header from '$lib/components/Header.svelte';
|
||||
import { actualizarUsuario } from '$lib/hooks/actualizarUsuario.js';
|
||||
import {
|
||||
Button,
|
||||
DataTableSkeleton,
|
||||
Modal,
|
||||
PasswordInput,
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableContainer,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
TextInput
|
||||
TableRow
|
||||
} from 'carbon-components-svelte';
|
||||
import { Add, Pen, TrashCan } from 'carbon-icons-svelte';
|
||||
import { Keychain } from 'carbon-icons-svelte';
|
||||
import { Add, Keychain, Network_4, Pen, TrashCan } from 'carbon-icons-svelte';
|
||||
import CambiarContraseñaForm from './CambiarContraseñaForm.svelte';
|
||||
import CrearUsuarioForm from './CrearUsuarioForm.svelte';
|
||||
import EditarUsuarioForm from './EditarUsuarioForm.svelte';
|
||||
import EliminarUsuarioForm from './EliminarUsuarioForm.svelte';
|
||||
import type { Grupo, Usuario } from '../../types.js';
|
||||
import { obtenerGruposDeUsuario } from '$lib/hooks/obtenerGruposDeUsuario.js';
|
||||
import QuitarGrupo from './QuitarGrupo.svelte';
|
||||
import AsignarGrupo from './AsignarGrupo.svelte';
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
@@ -23,21 +28,48 @@
|
||||
let showEditarModal = $state(false);
|
||||
let showEliminarModal = $state(false);
|
||||
let showCambiarContraseñaModal = $state(false);
|
||||
let showError: string | Promise<string> = $state('');
|
||||
let showError = $state('');
|
||||
|
||||
let usuarioModificar = $state({ name: '', email: '' });
|
||||
let usuarioEliminar = $state();
|
||||
let usuarioCambiarContraseña = $state();
|
||||
let showQuitar = $state(false);
|
||||
let showAsignar = $state(false);
|
||||
let usugruSeleccionado = $state({ usuario_id: 0, grupo_id: 0 });
|
||||
|
||||
let usuarioModificar = $state({ id: 0, name: '', email: '' });
|
||||
let usuarioEliminar = $state({ id: 0 });
|
||||
let usuarioCambiarContraseña = $state({ id: 0 });
|
||||
|
||||
function cerrarModal() {
|
||||
showCrearModal = false;
|
||||
showEditarModal = false;
|
||||
showEliminarModal = false;
|
||||
showCambiarContraseñaModal = false;
|
||||
showQuitar = false;
|
||||
showAsignar = false;
|
||||
|
||||
usuarioModificar = undefined;
|
||||
usuarioEliminar = undefined;
|
||||
usuarioCambiarContraseña = undefined;
|
||||
usuarioModificar = { id: 0, name: '', email: '' };
|
||||
usuarioEliminar = { id: 0 };
|
||||
usuarioCambiarContraseña = { id: 0 };
|
||||
usugruSeleccionado = { usuario_id: 0, grupo_id: 0 };
|
||||
}
|
||||
|
||||
let gruposUsuarioSeleccionado = $state<{
|
||||
usuario: Usuario | null;
|
||||
grupos: Promise<Grupo[] | string>;
|
||||
} | null>(null);
|
||||
|
||||
function seleccionarUsuarioGrupo(u: Usuario) {
|
||||
// toggle
|
||||
if (gruposUsuarioSeleccionado?.usuario?.id === u.id) {
|
||||
gruposUsuarioSeleccionado = null;
|
||||
return;
|
||||
}
|
||||
|
||||
gruposUsuarioSeleccionado = {
|
||||
usuario: u,
|
||||
grupos: obtenerGruposDeUsuario({
|
||||
usuario_id: u.id
|
||||
})
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -45,7 +77,7 @@
|
||||
|
||||
<div class="page-container">
|
||||
<div class="flex justify-between">
|
||||
<h1 class="page-title">Gestión de Usuarios</h1>
|
||||
<h1>Gestión de Usuarios</h1>
|
||||
<Button
|
||||
icon={Add}
|
||||
onclick={() => {
|
||||
@@ -75,9 +107,9 @@
|
||||
<TableCell>{u.id}</TableCell>
|
||||
<TableCell>{u.email}</TableCell>
|
||||
<TableCell>{u.name}</TableCell>
|
||||
<TableCell>{u.deleted_at ? 'no' : 'si'}</TableCell>
|
||||
<TableCell>{new Date(u.created_at).toLocaleString()}</TableCell>
|
||||
<TableCell>{new Date(u.updated_at).toLocaleString()}</TableCell>
|
||||
<TableCell>{(u as any).deleted_at ? 'no' : 'si'}</TableCell>
|
||||
<TableCell>{new Date((u as any).created_at).toLocaleString()}</TableCell>
|
||||
<TableCell>{new Date((u as any).updated_at).toLocaleString()}</TableCell>
|
||||
<TableCell>
|
||||
<Button
|
||||
onclick={() => {
|
||||
@@ -107,6 +139,12 @@
|
||||
kind="secondary"
|
||||
icon={Keychain}>CambiarContraseña</Button
|
||||
>
|
||||
<Button
|
||||
size="small"
|
||||
kind="secondary"
|
||||
onclick={() => seleccionarUsuarioGrupo(u)}
|
||||
icon={Network_4}>Grupos</Button
|
||||
>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{/each}
|
||||
@@ -114,80 +152,117 @@
|
||||
</Table>
|
||||
</TableContainer>
|
||||
{/await}
|
||||
{#if gruposUsuarioSeleccionado?.usuario}
|
||||
<div class="mt-8!">
|
||||
{#await gruposUsuarioSeleccionado.grupos}
|
||||
Cargando ...
|
||||
{:then grupos}
|
||||
{#if typeof grupos === 'string'}
|
||||
{() => {
|
||||
showError = grupos;
|
||||
}}
|
||||
{:else if typeof grupos !== 'undefined'}
|
||||
<div class="flex justify-between">
|
||||
<h3>Grupos del usuario</h3>
|
||||
<Button
|
||||
onclick={() => {
|
||||
showAsignar = true;
|
||||
usugruSeleccionado = {
|
||||
usuario_id: gruposUsuarioSeleccionado?.usuario?.id || 0,
|
||||
grupo_id: 0
|
||||
};
|
||||
}}
|
||||
icon={Add}>Asignar un grupo</Button
|
||||
>
|
||||
</div>
|
||||
<TableContainer>
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableHeader>Id</TableHeader>
|
||||
<TableHeader>Nombre</TableHeader>
|
||||
<TableHeader>Descripcion</TableHeader>
|
||||
<TableHeader>Permisos</TableHeader>
|
||||
<TableHeader>Creado en</TableHeader>
|
||||
<TableHeader>Acciones</TableHeader>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{#if grupos?.length == 0}
|
||||
<TableRow>
|
||||
<TableCell colspan={7}>No hay Grupos Asignados</TableCell>
|
||||
</TableRow>
|
||||
{:else}
|
||||
{#each grupos as grupo}
|
||||
<TableRow>
|
||||
<TableCell>{grupo.id}</TableCell>
|
||||
<TableCell>{grupo.nombre}</TableCell>
|
||||
<TableCell>{grupo.descripcion}</TableCell>
|
||||
<TableCell>{grupo.permisos && grupo.permisos.map((x) => x.nombre)}</TableCell>
|
||||
<TableCell>{new Date((grupo as any).created_at).toLocaleString()}</TableCell>
|
||||
<TableCell>
|
||||
<Button
|
||||
kind="danger"
|
||||
onclick={() => {
|
||||
usugruSeleccionado = {
|
||||
grupo_id: grupo.id,
|
||||
usuario_id: gruposUsuarioSeleccionado?.usuario?.id || 0
|
||||
};
|
||||
showQuitar = true;
|
||||
}}
|
||||
icon={TrashCan}>Quitar</Button
|
||||
>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{/each}
|
||||
{/if}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
{/if}
|
||||
{/await}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#await showError then msgerr}
|
||||
<Modal
|
||||
open={!!showError && msgerr != 'Ok'}
|
||||
primaryButtonText="Cerrar"
|
||||
on:click:button--primary={() => (showError = '')}
|
||||
>
|
||||
{msgerr}
|
||||
|
||||
<CrearUsuarioForm bind:show={showCrearModal} onclose={cerrarModal} />
|
||||
<EditarUsuarioForm bind:show={showEditarModal} usuario={usuarioModificar} onclose={cerrarModal} />
|
||||
<EliminarUsuarioForm
|
||||
bind:show={showEliminarModal}
|
||||
usuario={usuarioEliminar}
|
||||
onclose={cerrarModal}
|
||||
/>
|
||||
<CambiarContraseñaForm
|
||||
bind:show={showCambiarContraseñaModal}
|
||||
usuario={usuarioCambiarContraseña}
|
||||
onclose={cerrarModal}
|
||||
/>
|
||||
<QuitarGrupo
|
||||
onclose={cerrarModal}
|
||||
bind:show={showQuitar}
|
||||
data={usugruSeleccionado}
|
||||
callback={() => {
|
||||
if (gruposUsuarioSeleccionado?.usuario?.id) {
|
||||
gruposUsuarioSeleccionado.grupos = obtenerGruposDeUsuario({
|
||||
usuario_id: gruposUsuarioSeleccionado.usuario.id
|
||||
});
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<AsignarGrupo
|
||||
onclose={cerrarModal}
|
||||
bind:show={showAsignar}
|
||||
bind:data={usugruSeleccionado}
|
||||
callback={() => {
|
||||
if (gruposUsuarioSeleccionado?.usuario?.id) {
|
||||
gruposUsuarioSeleccionado.grupos = obtenerGruposDeUsuario({
|
||||
usuario_id: gruposUsuarioSeleccionado.usuario.id
|
||||
});
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{#if showError}
|
||||
<Modal open primaryButtonText="Cerrar" on:click:button--primary={() => (showError = '')}>
|
||||
{showError}
|
||||
</Modal>
|
||||
{/await}
|
||||
<form
|
||||
id="crearForm"
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault();
|
||||
}}
|
||||
>
|
||||
<Modal
|
||||
formId="crearForm"
|
||||
bind:open={showCrearModal}
|
||||
modalHeading="Registrar Nuevo Usuario"
|
||||
primaryButtonText="Crear"
|
||||
secondaryButtonText="Cerrar"
|
||||
on:click:button--secondary={cerrarModal}
|
||||
></Modal>
|
||||
</form>
|
||||
<form
|
||||
id="editarForm"
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault();
|
||||
showError = actualizarUsuario(usuarioModificar);
|
||||
showEditarModal = false;
|
||||
}}
|
||||
>
|
||||
<Modal
|
||||
formId="editarForm"
|
||||
bind:open={showEditarModal}
|
||||
modalHeading="Editar Usuario"
|
||||
primaryButtonText="Editar"
|
||||
secondaryButtonText="Cerrar"
|
||||
on:click:button--secondary={cerrarModal}
|
||||
>
|
||||
<TextInput name="nombre" type="text" labelText="Nombre: " bind:value={usuarioModificar.name} />
|
||||
<TextInput name="email" type="text" labelText="Email" bind:value={usuarioModificar.email} />
|
||||
</Modal>
|
||||
</form>
|
||||
<form
|
||||
id="eliminarForm"
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault();
|
||||
}}
|
||||
>
|
||||
<Modal
|
||||
formId="eliminarForm"
|
||||
bind:open={showEliminarModal}
|
||||
modalHeading="Eliminar Usuario"
|
||||
primaryButtonText="Eliminar"
|
||||
secondaryButtonText="Cerrar"
|
||||
on:click:button--secondary={cerrarModal}
|
||||
></Modal>
|
||||
</form>
|
||||
<form
|
||||
id="cambiarForm"
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault();
|
||||
}}
|
||||
>
|
||||
<Modal
|
||||
formId="cambiarForm"
|
||||
bind:open={showCambiarContraseñaModal}
|
||||
modalHeading="Cambiar Contraseña"
|
||||
primaryButtonText="Aceptar"
|
||||
secondaryButtonText="Cerrar"
|
||||
on:click:button--secondary={cerrarModal}
|
||||
>
|
||||
<PasswordInput labelText="Nueva Contraseña: " />
|
||||
</Modal>
|
||||
</form>
|
||||
{/if}
|
||||
@@ -0,0 +1,81 @@
|
||||
<script lang="ts">
|
||||
import { obtenerGrupos } from '$lib/api';
|
||||
import { agregarGrupoAUsuario } from '$lib/hooks/agregarGrupoAUsuario';
|
||||
import { Modal, Select, SelectItem } from 'carbon-components-svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import type { Grupo } from '../../types';
|
||||
|
||||
let {
|
||||
show = $bindable(),
|
||||
onclose,
|
||||
data = $bindable(),
|
||||
callback
|
||||
}: {
|
||||
show?: boolean;
|
||||
onclose: () => void;
|
||||
data: { usuario_id: number; grupo_id: number };
|
||||
callback: Function;
|
||||
} = $props();
|
||||
|
||||
let error = $state('');
|
||||
let valueSelect = $state();
|
||||
let grupos: Grupo[] = $state([]);
|
||||
|
||||
onMount(async () => {
|
||||
grupos = await obtenerGrupos();
|
||||
});
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
error = '';
|
||||
data.grupo_id = Number(valueSelect);
|
||||
console.log(data, valueSelect);
|
||||
const result = await agregarGrupoAUsuario(data, callback);
|
||||
if (result !== 'Ok') {
|
||||
error = result;
|
||||
return;
|
||||
}
|
||||
reset();
|
||||
onclose();
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
reset();
|
||||
onclose();
|
||||
}
|
||||
|
||||
function reset() {
|
||||
error = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<form id="asignarForm" onsubmit={handleSubmit}>
|
||||
<Modal
|
||||
formId="asignarForm"
|
||||
bind:open={show}
|
||||
modalHeading="Asignar Grupo"
|
||||
primaryButtonText="Asignar"
|
||||
secondaryButtonText="Cerrar"
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<div class="error-msg">{error}</div>
|
||||
{/if}
|
||||
<Select
|
||||
labelText="Grupos"
|
||||
on:change={(e: Event) => (valueSelect = (e.target as HTMLSelectElement).value)}
|
||||
>
|
||||
{#each grupos as grupo}
|
||||
<SelectItem value={grupo.id} text={grupo.nombre} />
|
||||
{/each}
|
||||
</Select>
|
||||
</Modal>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
.error-msg {
|
||||
color: #da1e28;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,51 @@
|
||||
<script lang="ts">
|
||||
import { Button, Modal, PasswordInput } from 'carbon-components-svelte';
|
||||
import { cambiarContraseña } from '$lib/hooks/cambiarContraseña.js';
|
||||
|
||||
let {
|
||||
show = $bindable(),
|
||||
onclose,
|
||||
usuario
|
||||
}: { show?: boolean; onclose: () => void; usuario: { id: number } } = $props();
|
||||
|
||||
let password = $state('');
|
||||
let error = $state('');
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
error = '';
|
||||
const result = await cambiarContraseña({
|
||||
old_password: 'adminoverride',
|
||||
new_password: password,
|
||||
user_id: usuario.id
|
||||
});
|
||||
if (result !== 'Ok') {
|
||||
error = result;
|
||||
return;
|
||||
}
|
||||
password = '';
|
||||
onclose();
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
password = '';
|
||||
error = '';
|
||||
onclose();
|
||||
}
|
||||
</script>
|
||||
|
||||
<form id="cambiarForm" onsubmit={handleSubmit}>
|
||||
<Modal
|
||||
formId="cambiarForm"
|
||||
bind:open={show}
|
||||
modalHeading="Cambiar Contraseña"
|
||||
primaryButtonText="Aceptar"
|
||||
secondaryButtonText="Cerrar"
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<div class="text-red-500">{error}</div>
|
||||
{/if}
|
||||
<PasswordInput labelText="Nueva Contraseña: " minlength={8} bind:value={password} />
|
||||
</Modal>
|
||||
</form>
|
||||
@@ -0,0 +1,61 @@
|
||||
<script lang="ts">
|
||||
import { crearUsuario } from '$lib/hooks/crearUsuario.js';
|
||||
import { Button, Modal, PasswordInput, TextInput } from 'carbon-components-svelte';
|
||||
|
||||
let { show = $bindable(), onclose }: { show?: boolean; onclose: () => void } = $props();
|
||||
|
||||
let name = $state('');
|
||||
let email = $state('');
|
||||
let password = $state('');
|
||||
let error = $state('');
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
error = '';
|
||||
const result = await crearUsuario({ name, email, password });
|
||||
if (result !== 'Ok') {
|
||||
error = result;
|
||||
return;
|
||||
}
|
||||
reset();
|
||||
onclose();
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
reset();
|
||||
onclose();
|
||||
}
|
||||
|
||||
function reset() {
|
||||
name = '';
|
||||
email = '';
|
||||
password = '';
|
||||
error = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<form id="crearForm" onsubmit={handleSubmit}>
|
||||
<Modal
|
||||
formId="crearForm"
|
||||
bind:open={show}
|
||||
modalHeading="Registrar Nuevo Usuario"
|
||||
primaryButtonText="Crear"
|
||||
secondaryButtonText="Cerrar"
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<div class="error-msg">{error}</div>
|
||||
{/if}
|
||||
<TextInput bind:value={name} labelText="Nombre" placeholder="Tu nombre" />
|
||||
<TextInput bind:value={email} labelText="Email" placeholder="tu@email.com" type="email" />
|
||||
<PasswordInput bind:value={password} labelText="Contraseña" placeholder="••••••••" minlength={8} />
|
||||
</Modal>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
.error-msg {
|
||||
color: #da1e28;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,57 @@
|
||||
<script lang="ts">
|
||||
import { actualizarUsuario } from '$lib/hooks/actualizarUsuario.js';
|
||||
import { Button, Modal, TextInput } from 'carbon-components-svelte';
|
||||
|
||||
let {
|
||||
show = $bindable(),
|
||||
onclose,
|
||||
usuario
|
||||
}: {
|
||||
show?: boolean;
|
||||
onclose: () => void;
|
||||
usuario: { id: number; name: string; email: string };
|
||||
} = $props();
|
||||
|
||||
let error = $state('');
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
error = '';
|
||||
const result = await actualizarUsuario(usuario);
|
||||
if (result !== 'Ok') {
|
||||
error = result;
|
||||
return;
|
||||
}
|
||||
onclose();
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
error = '';
|
||||
onclose();
|
||||
}
|
||||
</script>
|
||||
|
||||
<form id="editarForm" onsubmit={handleSubmit}>
|
||||
<Modal
|
||||
formId="editarForm"
|
||||
bind:open={show}
|
||||
modalHeading="Editar Usuario"
|
||||
primaryButtonText="Editar"
|
||||
secondaryButtonText="Cerrar"
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<div class="error-msg">{error}</div>
|
||||
{/if}
|
||||
<TextInput name="nombre" type="text" labelText="Nombre: " bind:value={usuario.name} />
|
||||
<TextInput name="email" type="text" labelText="Email" bind:value={usuario.email} />
|
||||
</Modal>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
.error-msg {
|
||||
color: #da1e28;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,56 @@
|
||||
<script lang="ts">
|
||||
import { eliminarUsuario } from '$lib/hooks/eliminarUsuario.js';
|
||||
import { Button, Modal } from 'carbon-components-svelte';
|
||||
|
||||
let {
|
||||
show = $bindable(),
|
||||
onclose,
|
||||
usuario
|
||||
}: { show?: boolean; onclose: () => void; usuario: { id: number } } = $props();
|
||||
|
||||
let error = $state('');
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
error = '';
|
||||
if (!usuario.id) {
|
||||
error = 'No se pudo obtener la id del usuario? recarga la pagina.';
|
||||
return;
|
||||
}
|
||||
const result = await eliminarUsuario(usuario.id);
|
||||
if (result !== 'Ok') {
|
||||
error = result;
|
||||
return;
|
||||
}
|
||||
onclose();
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
error = '';
|
||||
onclose();
|
||||
}
|
||||
</script>
|
||||
|
||||
<form id="eliminarForm" onsubmit={handleSubmit}>
|
||||
<Modal
|
||||
formId="eliminarForm"
|
||||
bind:open={show}
|
||||
modalHeading="Eliminar Usuario"
|
||||
primaryButtonText="Eliminar"
|
||||
secondaryButtonText="Cerrar"
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<div class="error-msg">{error}</div>
|
||||
{/if}
|
||||
Esta seguro que quiere borrar este usuario?
|
||||
</Modal>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
.error-msg {
|
||||
color: #da1e28;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,63 @@
|
||||
<script lang="ts">
|
||||
import { quitarGrupoAUsuario } from '$lib/hooks/quitarGrupoAUsuario';
|
||||
import { Button, Modal } from 'carbon-components-svelte';
|
||||
|
||||
let {
|
||||
show = $bindable(),
|
||||
onclose,
|
||||
data,
|
||||
|
||||
callback
|
||||
}: {
|
||||
show?: boolean;
|
||||
onclose: () => void;
|
||||
data: { usuario_id: number; grupo_id: number };
|
||||
callback: Function;
|
||||
} = $props();
|
||||
|
||||
let error = $state('');
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
error = '';
|
||||
if (!data.usuario_id) {
|
||||
error = 'No se pudo obtener la id del usuario? recarga la pagina.';
|
||||
return;
|
||||
}
|
||||
const result = await quitarGrupoAUsuario(data, callback);
|
||||
if (result !== 'Ok') {
|
||||
error = result;
|
||||
return;
|
||||
}
|
||||
onclose();
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
error = '';
|
||||
onclose();
|
||||
}
|
||||
</script>
|
||||
|
||||
<form id="quitarForm" onsubmit={handleSubmit}>
|
||||
<Modal
|
||||
formId="quitarForm"
|
||||
bind:open={show}
|
||||
modalHeading="Quitar Grupo"
|
||||
primaryButtonText="Quitar"
|
||||
secondaryButtonText="Cerrar"
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<div class="error-msg">{error}</div>
|
||||
{/if}
|
||||
Esta seguro que quiere quitarle este grupo al usuario?
|
||||
</Modal>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
.error-msg {
|
||||
color: #da1e28;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user