Solved

Any good Idea to set rights in the software for every user

Posted on 2011-09-17
8
447 Views
Last Modified: 2013-11-13
We are making software and want any good Idea from you to set rights in the software for every user. Menu level to Tab level even till Table column level. just to enable/disable user wise. we make two tables one with list of Menus with On and Off . 2nd Table with list of all Menu and with this 2 table combination we can set the rights in the software.  If you have any good idea or any code or Any specail patch/utility available please let us know.
0
Comment
Question by:mahmood66
  • 5
  • 3
8 Comments
 
LVL 15

Expert Comment

by:x77
ID: 36555188
When I need achieve Right to users, I build a truth' Table.
Then I Build an Enumeration of Flags Type (An Integer supports 32 distinct values).
I can build Conbinations for especific privileges as mask with a name (A constant).

Then it is easy write code to Enable / disable controls based on Privilege mask.
0
 

Author Comment

by:mahmood66
ID: 36555524
dear,
can you elaborate with example.
0
 
LVL 15

Expert Comment

by:x77
ID: 36555626
<Flags()> _
Public Enum PrivPrj
    Adm = 1
    Otm = 2
    Ind = 4
    Condtra = 8
    Sap = 16
    EstudioTnd = 32
End Enum

  Public Property PrivAdm() As Boolean
      Get
          Return (PrivUsr And PrivPrj.Adm) > 0
      End Get
      Set(ByVal value As Boolean)
          PrivUsr = If(value, PrivUsr Or PrivPrj.Adm, PrivUsr And (Not PrivPrj.Adm))
      End Set
  End Property
  Public Property PrivEstudio() As Boolean
      Get
          Return (PrivUsr And (PrivPrj.EstudioTnd Or PrivPrj.Adm)) > 0
      End Get
      Set(ByVal value As Boolean)
          PrivUsr = If(value, PrivUsr Or PrivPrj.EstudioTnd, PrivUsr And (Not PrivPrj.EstudioTnd))
      End Set
  End Property
  Public ReadOnly Property PrivCondtra() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Condtra) > 0
      End Get
  End Property
  Public ReadOnly Property PrivInd() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Ind) > 0
      End Get
  End Property
  Public ReadOnly Property PrivOtm() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Otm) > 0
      End Get
  End Property
  Public ReadOnly Property PrivSap() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Sap) > 0
      End Get
  End Property

<Flags()> _
Public Enum PrivPrj
    Adm = 1
    Otm = 2
    Ind = 4
    Condtra = 8
    Sap = 16
    EstudioTnd = 32
End Enum

  Public Property PrivAdm() As Boolean
      Get
          Return (PrivUsr And PrivPrj.Adm) > 0
      End Get
      Set(ByVal value As Boolean)
          PrivUsr = If(value, PrivUsr Or PrivPrj.Adm, PrivUsr And (Not PrivPrj.Adm))
      End Set
  End Property
  Public Property PrivEstudio() As Boolean
      Get
          Return (PrivUsr And (PrivPrj.EstudioTnd Or PrivPrj.Adm)) > 0
      End Get
      Set(ByVal value As Boolean)
          PrivUsr = If(value, PrivUsr Or PrivPrj.EstudioTnd, PrivUsr And (Not PrivPrj.EstudioTnd))
      End Set
  End Property
  Public ReadOnly Property PrivCondtra() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Condtra) > 0
      End Get
  End Property
  Public ReadOnly Property PrivInd() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Ind) > 0
      End Get
  End Property
  Public ReadOnly Property PrivOtm() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Otm) > 0
      End Get
  End Property
  Public ReadOnly Property PrivSap() As Boolean
      Get
         Return (PrivUsr And PrivPrj.Sap) > 0
      End Get
  End Property

....


    Private Restringido As Boolean
    Private Sub IsAdm()
        Restringido = Not PrivAdm OrElse Prj.ProyectoPublico AndAlso Prj.MaskEstado(PrjEst.ReadOnly)
        mSave.Enabled = Not Restringido
        CmdEdit.Enabled = Not Restringido
    End Sub

    TbAvSup.ReadOnly = PrivAdm OrElse Not (Util.PrvSup.Todos OrElse Array.IndexOf(Util.PrvSup.Sup, ActiveTr.Row(Tnd.SupCol)) >= 0)

     cDm = Dgv.Columns("DM")
     If PrivAdm OrElse PrivCondtra Then Dgv2.Columns.Add(DirectCast(cDm.Clone, DataGridViewColumn))

Open in new window

0
 
LVL 15

Expert Comment

by:x77
ID: 36555989
I Hide Usr and Name columns on PrivDlg

To Manage Mask on DataGridview you can use my FlagCheckBoxColumn

  Private Function AddPrvCol(ByVal header As String, ByVal Flag As Integer, ByVal Width As Integer) As FlagCheckBoxColumn
       Dim c As New FlagCheckBoxColumn(Flag) With {.HeaderText = header, .Width = Width, _
        .DataPropertyName = "Prv", .SortMode = DataGridViewColumnSortMode.Automatic}
       Dgv.Columns.Add(c)
       Return c
  End Function

        AddPrvCol("Adm", PrivPrj.Adm, 30)
        AddPrvCol("OTM", PrivPrj.Otm, 35)
        AddPrvCol("Ind", PrivPrj.Ind, 30)
        AddPrvCol("OTO", PrivPrj.Condtra, 35)
        AddPrvCol("Sap", PrivPrj.Sap, 30)
        AddPrvCol("Est", PrivPrj.EstudioTnd, 30)

<DebuggerStepThrough()> _
Public NotInheritable Class FlagCheckBoxColumn
    Inherits DataGridViewCheckBoxColumn
    Public mask As Integer

    Public Sub New (ByVal Mask As Integer)
        MyBase.New (False)
        CellTemplate = New FlagCheckBoxCell
        Me.mask = Mask
    End Sub

    'Forzando Private, me aseguro de que DirectCast(OwningColumn, FlagCheckBoxColumn) es válido
    Private NotInheritable Class FlagCheckBoxCell
        Inherits DataGridViewCheckBoxCell

        Sub New()
            MyBase.New (False)
            Me.ValueType = GetType (Boolean)
            'Soportados: Boolean, Integer-threeState...
        End Sub

        'El valor, no tiene por que ser necesariamente Int32, puede ser byte, short...
        Private Shared Function IntValue (ByVal V As Object) As Int32
            Return If(V Is DBNull.Value, 0, Convert.ToInt32 (V))
        End Function

        Protected Overrides Function GetValue (ByVal rowIndex As Integer) As Object
            Dim Mask As Integer = DirectCast (OwningColumn, FlagCheckBoxColumn).mask
            Return (IntValue (MyBase.GetValue (rowIndex)) And Mask) > 0
        End Function

        Protected Overrides Function SetValue (ByVal rowIndex As Integer, ByVal value As Object) As Boolean
            Dim Mask As Integer = DirectCast (OwningColumn, FlagCheckBoxColumn).mask
            Dim flags As Integer = IntValue (MyBase.GetValue (rowIndex))
            If True.Equals (value) Then flags = flags Or Mask Else flags = flags And (Not Mask)
            Return MyBase.SetValue (rowIndex, flags)
        End Function
    End Class
End Class

Open in new window

PrivDlg.png
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 15

Accepted Solution

by:
x77 earned 500 total points
ID: 36556167
For IntValue Method:

        'El valor, no tiene por que ser necesariamente Int32, puede ser byte, short...
        Private Shared Function IntValue (ByVal V As Object) As Int32
            Return If(V Is DBNull.Value, 0, Convert.ToInt32 (V))
        End Function

Privileges - Auto Restiction Dialog.

AdmPrivDlg
I Use it to validate Applictation behaviour with distinct privileges.
But Users can also work with auto Resticted privileges.
User can also restore original Privileges.

Private Sub Chk_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs)
        If disablechk Then Return
        Dim prv = OriginalPrivUsr Or PrivUsr
        Dim oK = (e.NewValue = CheckState.Unchecked) OrElse (prv And PrivPrj.Adm) > 0
        If oK Then
        ElseIf sender Is ChkTrDoc Then
           Dim v = If(e.Index = 0, Nothing, ChkTrDoc.Items(e.Index)), PrvSup = If(bOriginalValid, OriginalPrvSup, Util.PrvSup)
           If PrvSup.Autorizado(v) Then oK = True
        Else
           If (prv And (1 << e.Index)) > 0 Then oK = True
        End If
        If oK = False Then
           e.NewValue = e.CurrentValue : Beep()
        Else
           If bOriginalValid = False Then
              bOriginalValid = True
              OriginalPrvSup = Util.PrvSup
              OriginalPrivUsr = Util.PrivUsr
           End If
        End If
    End Sub

Open in new window


This Code do´nt allow a any user elevate Privileges, Only restrict.

I use a Dialog same this to Delegate Privileges:

A User can save data to a File (Serialization) saving also  information about privileges.
It Send this File to other user (Delegated) that can modify data an return modified file.

Original User validate Changes and Sync data to DataBase.
0
 

Author Comment

by:mahmood66
ID: 36559501
this user rights i am doing first time, kinldy let me know about database structure also, of any idea which  will help me in this.
Note:1.  i want to make menue and some of the menu must not be visible of some users.
         2. if form is having tabs (tab pages),  then i want to set rights tab wise even.
kindly let me know you good suggestion.
0
 
LVL 15

Expert Comment

by:x77
ID: 36561110
Each control, menu, ... has a Member variable Name.

Then you can do :

   MyMenuItem.visible = Required_Priv_User

Where Required_Priv_User is a Property or a boolean variable.

Note that you also can set "Enabled" or "ReadOnly" Control's properties.

0
 

Author Closing Comment

by:mahmood66
ID: 36572810
thanks that what I was looking for. and you given code and suggestion works
thanks again
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This is about my first experience with programming Arduino.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now