From bbe0ea663cdb75126cf8f532c68ef13ec37ba1ed Mon Sep 17 00:00:00 2001 From: Oscar Irigoyen Date: Fri, 30 Sep 2022 09:42:56 -0700 Subject: [PATCH] Bloquear acceso a empersa por url cuando no se es administrador --- Sistemas/Empresa.aspx.vb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Sistemas/Empresa.aspx.vb b/Sistemas/Empresa.aspx.vb index 0e19d9054..b095f668a 100644 --- a/Sistemas/Empresa.aspx.vb +++ b/Sistemas/Empresa.aspx.vb @@ -6,6 +6,7 @@ Imports Extensiones Imports System.Runtime.InteropServices Imports System.IO Imports Microsoft.Reporting.WebForms +Imports Microsoft.Owin.Security.Provider Partial Class Sistemas_Empresa Inherits ClsPaginas @@ -152,6 +153,18 @@ Partial Class Sistemas_Empresa Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not IsPostBack Then + + If UsuarioActual.CveRol <> 1 AndAlso (Request("CveEmpresa") IsNot Nothing AndAlso Request("CveEmpresa").ToEntero > 0) Then + + If Not ValidaCveEmpresaUsaurio(UsuarioActual.CveUsuario, Request("CveEmpresa").ToEntero) Then + 'Response.Redirect("../Inicio.aspx") + Alert("No tiene acceso a esta empresa.", TipoMensaje.MsgAdvertencia, "document.location.href = ""../Inicio.aspx""") + Exit Sub + End If + + + End If + CargaDdlPac() CargaRegimenFiscal() CargaGridIndicadores() @@ -159,6 +172,7 @@ Partial Class Sistemas_Empresa DtFuncionalidades = Nothing DtCuentas = Nothing CveClasificacionPorcentaje = 0 + If (Request("CveEmpresa") IsNot Nothing AndAlso IsNumeric(Request("CveEmpresa")) AndAlso Request("CveEmpresa").ToEntero > 0 AndAlso UsuarioActual.CveRol = 1) OrElse UsuarioActual.CveRol <> 1 Then ViewState("CveEmpresa") = If(UsuarioActual.CveRol <> 1, UsuarioActual.Empresa.CveEmpresa.ToString, Request("CveEmpresa")) ' Request("CveEmpresa") ' Session("FileUpload") = CveEmpresa @@ -207,6 +221,22 @@ Partial Class Sistemas_Empresa End If End Sub + Private Function ValidaCveEmpresaUsaurio(CveUsuario As Integer, CveEmpresaValidar As Integer) As Boolean + + Dim Respuesta As Boolean = False + Using ObjEmpresas As New ClsSisEmpresas() + If ObjEmpresas.GetEmpresas(-1, "-1", "-1", "-1", "-1", UsuarioActual.CveUsuario) Then + If ObjEmpresas.DtResultados.FiltraParametros($"CveEmpresa = {CveEmpresaValidar}").Rows.Count = 1 Then + Respuesta = True + End If + End If + End Using + Return Respuesta + + End Function + + + Private Sub CargaDatos() Dim ObjEmpresas As New ClsSisEmpresas()