@asteby/metacore-runtime-react 31.1.0 → 32.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -548,7 +548,8 @@ export function PermissionsManager({
548
548
  mode: 'create' | 'edit'
549
549
  label: string
550
550
  color: string
551
- }>({ open: false, mode: 'create', label: '', color: ROLE_COLORS[5] })
551
+ grantAll: boolean
552
+ }>({ open: false, mode: 'create', label: '', color: ROLE_COLORS[5], grantAll: false })
552
553
  const [roleSaving, setRoleSaving] = React.useState(false)
553
554
  const [deleteOpen, setDeleteOpen] = React.useState(false)
554
555
  const [deleting, setDeleting] = React.useState(false)
@@ -650,6 +651,25 @@ export function PermissionsManager({
650
651
  [activeModule],
651
652
  )
652
653
 
654
+ // Every capability across every module in the catalog — the "Otorgar
655
+ // todo" button's target set (as opposed to setModuleAll, which is
656
+ // scoped to the currently open module).
657
+ const allCatalogCapabilities = React.useMemo(
658
+ () => allModules.flatMap((m) => moduleCapabilities(m)),
659
+ [allModules],
660
+ )
661
+
662
+ const setAllPermissions = React.useCallback(
663
+ (on: boolean) => {
664
+ if (on) {
665
+ setDraft(new Set(allCatalogCapabilities))
666
+ } else {
667
+ setDraft(new Set())
668
+ }
669
+ },
670
+ [allCatalogCapabilities],
671
+ )
672
+
653
673
  const handleSave = async () => {
654
674
  if (!activeRoleId || !draft) return
655
675
  setSaving(true)
@@ -699,7 +719,14 @@ export function PermissionsManager({
699
719
  rs.find((r) => r.name === slugify(label))?.id ||
700
720
  null
701
721
  if (createdId) setActiveRoleId(createdId)
702
- toast.success('Rol creado')
722
+ if (roleDialog.grantAll && createdId && allCatalogCapabilities.length) {
723
+ await syncRolePermissions(createdId, [...allCatalogCapabilities].sort())
724
+ setBaseline(new Set(allCatalogCapabilities))
725
+ setDraft(new Set(allCatalogCapabilities))
726
+ toast.success('Rol creado con todos los permisos')
727
+ } else {
728
+ toast.success('Rol creado')
729
+ }
703
730
  } else if (roleDialog.mode === 'edit' && updateRole && activeRole) {
704
731
  await updateRole(activeRole.id, {
705
732
  name: activeRole.name,
@@ -743,6 +770,7 @@ export function PermissionsManager({
743
770
  mode: 'edit',
744
771
  label: activeRole.label || activeRole.name,
745
772
  color: activeRole.color || ROLE_COLORS[5],
773
+ grantAll: false,
746
774
  })
747
775
  }
748
776
 
@@ -816,12 +844,29 @@ export function PermissionsManager({
816
844
  mode: 'create',
817
845
  label: '',
818
846
  color: ROLE_COLORS[5],
847
+ grantAll: false,
819
848
  })
820
849
  }
821
850
  >
822
851
  <Plus className="mr-1.5 h-4 w-4" /> Nuevo rol
823
852
  </Button>
824
853
  )}
854
+ <Button
855
+ variant="outline"
856
+ onClick={() => setAllPermissions(true)}
857
+ disabled={checksDisabled || !allCatalogCapabilities.length}
858
+ title="Marca todos los permisos de todos los módulos"
859
+ >
860
+ <CheckCheck className="mr-1.5 h-4 w-4" /> Otorgar todo
861
+ </Button>
862
+ <Button
863
+ variant="outline"
864
+ onClick={() => setAllPermissions(false)}
865
+ disabled={checksDisabled || !draft?.size}
866
+ title="Quita todos los permisos del rol"
867
+ >
868
+ <Eraser className="mr-1.5 h-4 w-4" /> Quitar todo
869
+ </Button>
825
870
  <Button
826
871
  onClick={handleSave}
827
872
  disabled={!dirty || saving || !activeRole}
@@ -1204,6 +1249,28 @@ export function PermissionsManager({
1204
1249
  ))}
1205
1250
  </div>
1206
1251
  </div>
1252
+ {roleDialog.mode === 'create' && (
1253
+ <label className="flex cursor-pointer items-start gap-3 rounded-lg border p-3 text-sm hover:bg-muted/40">
1254
+ <input
1255
+ type="checkbox"
1256
+ className="mt-0.5 size-4 accent-emerald-600"
1257
+ checked={roleDialog.grantAll}
1258
+ onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
1259
+ setRoleDialog((d) => ({
1260
+ ...d,
1261
+ grantAll: e.target.checked,
1262
+ }))
1263
+ }
1264
+ />
1265
+ <span>
1266
+ <span className="font-medium">Otorgar todos los permisos</span>
1267
+ <span className="mt-0.5 block text-xs text-muted-foreground">
1268
+ Acceso completo a todos los módulos del catálogo (como un
1269
+ admin). Puedes quitar permisos después.
1270
+ </span>
1271
+ </span>
1272
+ </label>
1273
+ )}
1207
1274
  </div>
1208
1275
  <DialogFooter>
1209
1276
  <Button