Ejemplo n.º 1
0
    /// <summary>
    /// Gets and bulk updates permissions. Called when the "Get and bulk update permissions" button is pressed.
    /// Expects the CreatePermission method to be run first.
    /// </summary>
    private bool GetAndBulkUpdatePermissions()
    {
        // Prepare the parameters
        string where = "PermissionName LIKE N'MyNewPermission%'";

        // Get the data
        DataSet permissions = PermissionNameInfoProvider.GetPermissionNames(where, null, 0, null);

        if (!DataHelper.DataSourceIsEmpty(permissions))
        {
            // Loop through the individual items
            foreach (DataRow permissionDr in permissions.Tables[0].Rows)
            {
                // Create object from DataRow
                PermissionNameInfo modifyPermission = new PermissionNameInfo(permissionDr);

                // Update the properties
                modifyPermission.PermissionDisplayName = modifyPermission.PermissionDisplayName.ToUpper();

                // Save the changes
                PermissionNameInfoProvider.SetPermissionInfo(modifyPermission);
            }

            return(true);
        }

        return(false);
    }
Ejemplo n.º 2
0
    public static bool CreatePermission(string displayName, string Name, string resourceName)
    {
        ResourceInfo module = ResourceInfoProvider.GetResourceInfo(resourceName);

        if (module != null)
        {
            PermissionNameInfo newPermission = new PermissionNameInfo();
            newPermission.PermissionDisplayName = displayName;
            newPermission.PermissionName        = Name;
            newPermission.ResourceId            = module.ResourceId;
            PermissionNameInfoProvider.SetPermissionInfo(newPermission);
            return(true);
        }
        return(false);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Gets and updates permission. Called when the "Get and update permission" button is pressed.
    /// Expects the CreatePermission method to be run first.
    /// </summary>
    private bool GetAndUpdatePermission()
    {
        // Get the permission
        PermissionNameInfo updatePermission = PermissionNameInfoProvider.GetPermissionNameInfo("MyNewPermission", "MyNewModule", null);

        if (updatePermission != null)
        {
            // Update the properties
            updatePermission.PermissionDisplayName = updatePermission.PermissionDisplayName.ToLower();

            // Save the changes
            PermissionNameInfoProvider.SetPermissionInfo(updatePermission);

            return(true);
        }

        return(false);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Creates permission. Called when the "Create permission" button is pressed.
    /// Expects the CreateModule method to be run first.
    /// </summary>
    private bool CreatePermission()
    {
        // Get the resource
        ResourceInfo module = ResourceInfoProvider.GetResourceInfo("MyNewModule");

        if (module != null)
        {
            // Create new permission object
            PermissionNameInfo newPermission = new PermissionNameInfo();

            // Set the properties
            newPermission.PermissionDisplayName     = "My new permission";
            newPermission.PermissionName            = "MyNewPermission";
            newPermission.ResourceId                = module.ResourceId;
            newPermission.PermissionDisplayInMatrix = true;

            // Save the permission
            PermissionNameInfoProvider.SetPermissionInfo(newPermission);

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Handles btnOK's OnClick event - Update or save permission info.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Finds whether required fields are not empty
        string result = new Validator().NotEmpty(tbPermissionDisplayName.Text.Trim(), GetString("Administration-Module_Edit_PermissionName_Edit.ErrorEmptyPermissionDisplayName")).NotEmpty(tbPermissionCodeName.Text.Trim(), GetString("Administration-Module_Edit_PermissionName_Edit.ErrorEmptyPermissionCodeName"))
                        .IsCodeName(tbPermissionCodeName.Text.Trim(), GetString("general.invalidcodename")).Result;

        if (result == "")
        {
            int resourceId = QueryHelper.GetInteger("moduleid", 0);
            if ((resourceId <= 0) && (mCurrentPermission != null))
            {
                resourceId = mCurrentPermission.ResourceId;
            }

            string resourceName = "";

            ResourceInfo ri = ResourceInfoProvider.GetResourceInfo(resourceId);
            if (ri != null)
            {
                resourceName = ri.ResourceName;
            }

            PermissionNameInfo pni = PermissionNameInfoProvider.GetPermissionNameInfo(tbPermissionCodeName.Text.Trim(), resourceName, null);

            if ((pni == null) || (pni.PermissionId == mPermissionId))
            {
                if (pni == null)
                {
                    pni = PermissionNameInfoProvider.GetPermissionNameInfo(mPermissionId);
                    if (pni == null)
                    {
                        pni = new PermissionNameInfo();
                    }
                }

                pni.PermissionName            = tbPermissionCodeName.Text.Trim();
                pni.PermissionDisplayName     = tbPermissionDisplayName.Text.Trim();
                pni.PermissionDescription     = txtPermissionDescription.Text.Trim();
                pni.PermissionDisplayInMatrix = chkPermissionDisplayInMatrix.Checked;
                pni.ClassId    = 0;
                pni.ResourceId = resourceId;
                pni.PermissionEditableByGlobalAdmin = chkGlobalAdmin.Checked;

                if (pni.PermissionOrder == 0)
                {
                    pni.PermissionOrder = PermissionNameInfoProvider.GetLastPermissionOrder(0, resourceId) + 1;
                }

                // Update or save permission info
                PermissionNameInfoProvider.SetPermissionInfo(pni);

                // Redirect to edit page if editing existing permission
                if (mPermissionId > 0)
                {
                    URLHelper.Redirect("Module_Edit_PermissionName_Edit.aspx?moduleID=" + pni.ResourceId + "&permissionID=" + pni.PermissionId + "&saved=1&hidebreadcrumbs=" + (mHideBreadcrumbs ? "1" : "0"));
                }
                // Redirect to whole frameset if creating new
                else
                {
                    URLHelper.Redirect(string.Format(@"Module_Edit_PermissionName_Edit_Frameset.aspx?moduleId={0}&permissionId={1}&saved=1", pni.ResourceId, pni.PermissionId));
                }
            }
            else
            {
                // Show error message
                ShowError(GetString("Administration-Module_Edit_PermissionName_Edit.UniqueCodeName"));
            }
        }
        else
        {
            // Show error message
            ShowError(result);
        }
    }