コード例 #1
0
        public async Task <string> UpdatePermissions([FromBody] JObject data)
        {
            try
            {
                PermissionsModule     permissionsModule = new PermissionsModule();
                List <PermissionsSet> modules           = data["Modules"].ToObject <List <PermissionsSet> >();
                permissionsModule.Modules = new List <IPermissionsSet>();
                permissionsModule.Modules.AddRange(modules);

                List <PermissionsOperation> operations = data["Operations"].ToObject <List <PermissionsOperation> >();
                permissionsModule.Operations = new List <IPermissionsOperation>();
                permissionsModule.Operations.AddRange(operations);

                permissionsModule.OwnerId = Guid.Parse(data["OwnerId"].ToString());
                permissionsModule.Type    = SetType.Role;

                var response = await _bosIAClient.AddPermissionsAsync <PermissionsModule>(permissionsModule);

                if (response.IsSuccessStatusCode)
                {
                    return("Permissions updated successfully");
                }
                else
                {
                    return(response.BOSErrors[0].Message);
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        public async Task <string> UpdatePermissions([FromBody] JObject data)
        {
            try
            {
                /* ------ LOGIC ----------
                 * Get the flat-listed modules from the View
                 * Get the flat-listed operations from the View
                 * Get the RoleId which in this case is the OwnerId
                 * Prepare the input parameter to the BOS API
                 * Make the API Call and return the status
                 */

                //Checking for non-null data
                if (data != null)
                {
                    //Setting the flat-listed modules that are permitted for the selected role
                    PermissionsModule     permissionsModule = new PermissionsModule();
                    List <PermissionsSet> modules           = data["Modules"].ToObject <List <PermissionsSet> >();
                    permissionsModule.Components = new List <IPermissionsSet>();
                    permissionsModule.Components.AddRange(modules);

                    //Setting the flat-listed operations that are permitted for the selected role
                    List <PermissionsOperation> operations = data["Operations"].ToObject <List <PermissionsOperation> >();
                    permissionsModule.Operations = new List <IPermissionsOperation>();
                    permissionsModule.Operations.AddRange(operations);

                    //Setting the RoleId to be the OwnerId
                    permissionsModule.OwnerId = Guid.Parse(data["OwnerId"].ToString());
                    permissionsModule.Type    = SetType.Role;

                    var response = await _bosIAClient.AddPermissionsAsync <PermissionsModule>(permissionsModule); //Making the BOS API call to Add/ Update the API

                    if (response != null && response.IsSuccessStatusCode)
                    {
                        return("Permissions updated successfully"); //return the success message
                    }
                    if (response != null && response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                    {
                        return("Token Expired, Please try again");//Token Expired
                    }
                    else
                    {
                        return(response.BOSErrors[0].Message);
                    }
                }
                else
                {
                    return("Permission set cannot be empty");
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("Permissions", "FetchPermissions", ex);
                return(ex.Message);
            }
        }