public object CreateRole(InputCreateRole input)
        {
            var serviceSid   = input.ServiceSid;
            var permission   = input.Permission;
            var friendlyName = input.FriendlyName;

            RoleResource.RoleTypeEnum type;
            if (input.Type == TypeRole.Channel.ToString())
            {
                type = RoleResource.RoleTypeEnum.Channel;
            }
            else
            {
                type = RoleResource.RoleTypeEnum.Deployment;
            }

            var role = RoleResource.Create(
                friendlyName: friendlyName,
                type: type,
                permission: permission,
                pathServiceSid: serviceSid
                );

            return(role);
        }
    static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        // To set up environmental variables, see http://twil.io/secure
        const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        const string authToken  = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
        const string serviceSid = Environment.GetEnvironmentVariable("TWILIO_SERVICE_SID");
        const string roleSid    = "RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

        TwilioClient.Init(accountSid, authToken);

        // Update the role
        var empty_list     = new List <string>();
        var newPermissions = new List <string> {
            "sendMessage"
        };

        var role = RoleResource.Fetch(serviceSid, roleSid);

        newPermissions.AddRange(role.Permissions ?? empty_list);

        role = RoleResource.Update(serviceSid, roleSid, newPermissions);

        foreach (var permission in role.Permissions)
        {
            Console.WriteLine(permission);
        }
    }
    static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";
        const string serviceSid = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string roleSid    = "RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

        TwilioClient.Init(accountSid, authToken);

        // Update the role
        var empty_list     = new List <string>();
        var newPermissions = new List <string> {
            "sendMessage"
        };

        var role = RoleResource.Fetch(serviceSid, roleSid);

        newPermissions.AddRange(role.Permissions ?? empty_list);

        role = RoleResource.Update(serviceSid, roleSid, newPermissions);

        foreach (var permission in role.Permissions)
        {
            Console.WriteLine(permission);
        }
    }
        public async Task <SaveRoleResponse> UpdateAsync(string id, RoleResource roleResource)
        {
            var existingRole = await _roleRepository.FindByIdAsync(id);

            if (existingRole == null)
            {
                return(new SaveRoleResponse("Role Not Found"));
            }

            existingRole.Name        = roleResource.Name;
            existingRole.RoleName    = roleResource.RoleName;
            existingRole.Description = roleResource.Description;

            try
            {
                _roleRepository.UpdateRole(existingRole);
                await _context.SaveChangesAsync();

                return(new SaveRoleResponse(existingRole));
            }
            catch (Exception ex)
            {
                return(new SaveRoleResponse($"An error occurred when updating the role: {ex.Message}"));
            }
        }
Example #5
0
        /// <inheritdoc />
        /// <summary>
        /// Create a new role &lt;b&gt;Permissions Needed:&lt;/b&gt; ROLES_ADMIN
        /// </summary>
        /// <param name="roleResource">The role resource object</param>
        public void CreateRole(RoleResource roleResource)
        {
            mWebCallEvent.WebPath = "/auth/roles";
            if (!string.IsNullOrEmpty(mWebCallEvent.WebPath))
            {
                mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{format}", "json");
            }

            mWebCallEvent.HeaderParams.Clear();
            mWebCallEvent.QueryParams.Clear();
            mWebCallEvent.AuthSettings.Clear();
            mWebCallEvent.PostBody = null;

            mWebCallEvent.PostBody = KnetikClient.Serialize(roleResource); // http body (model) parameter

            // authentication settings
            mWebCallEvent.AuthSettings.Add("oauth2_client_credentials_grant");

            // authentication settings
            mWebCallEvent.AuthSettings.Add("oauth2_password_grant");

            // make the HTTP request
            mCreateRoleStartTime      = DateTime.Now;
            mWebCallEvent.Context     = mCreateRoleResponseContext;
            mWebCallEvent.RequestType = KnetikRequestType.POST;

            KnetikLogger.LogRequest(mCreateRoleStartTime, "CreateRole", "Sending server request...");
            KnetikGlobalEventSystem.Publish(mWebCallEvent);
        }
        public async Task <IActionResult> UpdateRole(int roleId, RoleResource roleResource)
        {
            Role currentRole = await roleService.FindAsync(roleId).ConfigureAwait(false);

            if (currentRole == null)
            {
                ProblemDetails problem = new ProblemDetails
                {
                    Title    = "Failed to update the role.",
                    Detail   = "The specified role could not be found in the database",
                    Instance = "8F167FDF-3B2B-4E71-B3D0-AA2B1C1CE2C3"
                };
                return(NotFound(problem));
            }
            mapper.Map <RoleResource, Role>(roleResource, currentRole);
            foreach (RoleScope roleScope in currentRole.Scopes)
            {
                if (!roleService.isValidScope(roleScope.Scope))
                {
                    ProblemDetails problem = new ProblemDetails
                    {
                        Title    = "Failed to update the role",
                        Detail   = $"The specified scope is not a valid scope: {roleScope.Scope}.",
                        Instance = "E0BB725C-4013-4B0E-AEBC-857F1F75B29C"
                    };
                    return(BadRequest(problem));
                }
            }


            roleService.Update(currentRole);
            roleService.Save();

            return(Ok(mapper.Map <Role, RoleResourceResult>(currentRole)));
        }
    static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        // To set up environmental variables, see http://twil.io/secure
        const string accountSid   = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        const string authToken    = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
        const string serviceSid   = Environment.GetEnvironmentVariable("TWILIO_SERVICE_SID");
        const string friendlyName = "roleName";

        TwilioClient.Init(accountSid, authToken);

        // Create a role
        var permissions = new List <string>
        {
            "createChannel",
            "joinChannel"
        };

        var role = RoleResource.Create(serviceSid,
                                       friendlyName,
                                       RoleResource.RoleTypeEnum.Deployment,
                                       permissions);

        Console.WriteLine(role.Sid);
    }
Example #8
0
        public async Task <IActionResult> Create(RoleResource resource)
        {
            var response = new SingleModelResponse <RoleResource>();

            try
            {
                if (resource == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = "Input could not be null.";
                    return(response.ToHttpResponse());
                }
                var role = new Role();
                _mapper.Map(resource, role);

                var entity = await _roleRepository.AddAsync(role);

                response.Model   = _mapper.Map(entity, resource);
                response.Message = "The data was saved successfully";
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.ToString();
            }

            return(response.ToHttpResponse());
        }
Example #9
0
        public async Task <IActionResult> GetAsync(int id)
        {
            var response = new SingleModelResponse <RoleResource>();

            try
            {
                var entity = await _roleRepository.GetAsync(id);

                if (entity == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = "Input could not be found.";
                    return(response.ToHttpResponse());
                }
                var resource = new RoleResource();
                _mapper.Map(entity, resource);
                response.Model = resource;
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
Example #10
0
        public async Task <IActionResult> Delete(int id)
        {
            var response = new SingleModelResponse <RoleResource>();

            try
            {
                var rolesToDelete = await _roleRepository.Query().Include(x => x.UserRoles)
                                    .SingleOrDefaultAsync(x => x.Id == id);

                if (rolesToDelete == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = "Input could not be found.";
                    return(response.ToHttpResponse());
                }

                await _userRoleService.Delete(rolesToDelete.UserRoles.ToList());

                var entity = await _roleRepository.DeleteAsync(id);

                var resource = new RoleResource();
                response.Model   = _mapper.Map(entity, resource);
                response.Message = "The record was deleted successfully";
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
Example #11
0
        public async Task <IActionResult> Update(int id, RoleResource resource)
        {
            var response = new SingleModelResponse <RoleResource>();

            try
            {
                var role = await _roleRepository.FindAsync(x => x.Id == id);

                if (role == null || resource == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = "Input could not be found.";
                    return(response.ToHttpResponse());
                }

                _mapper.Map(resource, role);

                await _roleRepository.UpdateAsync(role);

                response.Model   = _mapper.Map(role, resource);
                response.Message = "The data was saved successfully";
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.ToString();
            }

            return(response.ToHttpResponse());
        }
Example #12
0
 /// <summary>
 ///     Updates a user role on the current account by ID.
 ///     HTTP Method: put
 ///     Endpoint: /restapi/{apiVersion}/account/{accountId}/user-role/{roleId}
 ///     Rate Limit Group: Medium
 ///     App Permission: RoleManagement
 ///     User Permission: EditUserRoles
 /// </summary>
 public async Task <string> Put(RoleResource roleResource, RestRequestConfig restRequestConfig = null)
 {
     if (roleId == null)
     {
         throw new ArgumentException("Parameter cannot be null", nameof(roleId));
     }
     return(await rc.Put <string>(Path(), roleResource, null, restRequestConfig));
 }
 public object Insert(RoleResource item)
 {
     using (APCRSHREntities context = new APCRSHREntities())
     {
         context.RoleResources.Add(item);
         context.SaveChanges();
         return(item.RoleID);
     }
 }
        public object GetAllRole(InputGetAllRole input)
        {
            var serviceSid = input.ServiceSid;

            var roles = RoleResource.Read(
                pathServiceSid: serviceSid
                );

            return(roles);
        }
Example #15
0
        public async Task <IActionResult> PutAsync(string id, [FromBody] RoleResource role)
        {
            var result = await _roleService.UpdateAsync(id, role);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            return(Ok(role));
        }
 //删除一个角色资源
 public bool DeleteRoleResource(RoleResource _RoleResource)
 {
     String Sql = "delete from RoleResource where ResourceID = @ResourceID and RoleID = @RoleID";
     SqlParameter[] Paras = new SqlParameter[]
     {
        new SqlParameter("@ResourceID",_RoleResource.ResourceID),
        new SqlParameter("@RoleID",_RoleResource.RoleID)
     };
     if (SqlHelper.ExecuteNonQuery(Sql, Paras, CommandType.Text) > 0)
         return true;
     return false;
 }
        public object DeleteRole(InputDeleteRole input)
        {
            var serviceSid = input.ServiceSid;
            var roleSid    = input.RoleSid;

            var result = RoleResource.Delete(
                pathServiceSid: serviceSid,
                pathSid: roleSid
                );

            return(result);
        }
Example #18
0
        public void Constructor_GiveValidArguments_PropertiesAreSet()
        {
            var roleResource = new RoleResource(TestVariables.ResourceId);

            Assert.Equal(TestVariables.ResourceId, roleResource.Id);

            foreach (var prop in roleResource.GetType().GetProperties().Where(x => x.PropertyType.Name == "IReadOnlyList`1"))
            {
                var val = prop.GetValue(roleResource, null);
                Assert.False(val == null, $"{prop.Name} is null");
            }
        }
Example #19
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        RoleResource.Delete(
            pathServiceSid: "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            pathSid: "RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
            );
    }
        public object UpdateRole(InputUpdateRole input)
        {
            var serviceSid = input.ServiceSid;
            var roleSid    = input.RoleSid;
            var permission = input.Permission;

            var role = RoleResource.Update(
                permission: permission,
                pathServiceSid: serviceSid,
                pathSid: roleSid
                );

            return(role);
        }
    static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";
        const string serviceSid = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string roleSid    = "RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

        TwilioClient.Init(accountSid, authToken);

        var role = RoleResource.Fetch(serviceSid, roleSid);

        Console.WriteLine(role.FriendlyName);
    }
        /// <summary>
        /// 添加RoleResource
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <Guid> AddRoleResource(RoleResourceDto input)
        {
            var role = new RoleResource
            {
                RoleId          = input.RoleId,
                TrialCategoryId = input.TrialCategoryId,
                ResourceTypeId  = input.ResourceTypeId,
                ResourceGroupId = input.ResourceGroupId,
                Remark          = input.Remark
            };
            await _roleResourceRepository.InsertAsync(role);

            return(role.Id);
        }
Example #23
0
    static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        const string accountSid = "accountSid";
        const string authToken  = "authToken";
        const string serviceSid = "serviceSid";
        const string roleSid    = "roleSid";

        TwilioClient.Init(accountSid, authToken);

        var status = RoleResource.Delete(serviceSid, roleSid);

        Console.WriteLine(status);
    }
Example #24
0
        private void OnUpdateRoleResponse(KnetikRestResponse response)
        {
            if (!string.IsNullOrEmpty(response.Error))
            {
                throw new KnetikException("Error calling UpdateRole: " + response.Error);
            }

            UpdateRoleData = (RoleResource)KnetikClient.Deserialize(response.Content, typeof(RoleResource), response.Headers);
            KnetikLogger.LogResponse(mUpdateRoleStartTime, "UpdateRole", string.Format("Response received successfully:\n{0}", UpdateRoleData));

            if (UpdateRoleComplete != null)
            {
                UpdateRoleComplete(response.ResponseCode, UpdateRoleData);
            }
        }
Example #25
0
    static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        // To set up environmental variables, see http://twil.io/secure
        const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        const string authToken  = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
        const string serviceSid = Environment.GetEnvironmentVariable("TWILIO_SERVICE_SID");
        const string roleSid    = "RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

        TwilioClient.Init(accountSid, authToken);

        var status = RoleResource.Delete(serviceSid, roleSid);

        Console.WriteLine(status);
    }
Example #26
0
        public void TestDeleteResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.NoContent,
                         "null"
                         ));

            var response = RoleResource.Delete("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", client: twilioRestClient);

            Assert.NotNull(response);
        }
Example #27
0
        public void TestFetchResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"sid\": \"RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"service_sid\": \"ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"friendly_name\": \"channel user\",\"type\": \"channel\",\"permissions\": [\"sendMessage\",\"leaveChannel\",\"editOwnMessage\",\"deleteOwnMessage\"],\"date_created\": \"2016-03-03T19:47:15Z\",\"date_updated\": \"2016-03-03T19:47:15Z\",\"url\": \"https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Roles/RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}"
                         ));

            var response = RoleResource.Fetch("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", client: twilioRestClient);

            Assert.NotNull(response);
        }
Example #28
0
        public void TestReadEmptyResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"meta\": {\"page\": 0,\"page_size\": 50,\"first_page_url\": \"https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Roles?PageSize=50&Page=0\",\"previous_page_url\": null,\"url\": \"https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Roles?PageSize=50&Page=0\",\"next_page_url\": null,\"key\": \"roles\"},\"roles\": []}"
                         ));

            var response = RoleResource.Read("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", client: twilioRestClient);

            Assert.NotNull(response);
        }
Example #29
0
        public void TestReadFullResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"meta\": {\"page\": 0,\"page_size\": 50,\"first_page_url\": \"https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Roles?PageSize=50&Page=0\",\"previous_page_url\": null,\"url\": \"https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Roles?PageSize=50&Page=0\",\"next_page_url\": null,\"key\": \"roles\"},\"roles\": [{\"sid\": \"RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"service_sid\": \"ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"friendly_name\": \"channel user\",\"type\": \"channel\",\"permissions\": [\"sendMessage\",\"leaveChannel\",\"editOwnMessage\",\"deleteOwnMessage\"],\"date_created\": \"2016-03-03T19:47:15Z\",\"date_updated\": \"2016-03-03T19:47:15Z\",\"url\": \"https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Roles/RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}]}"
                         ));

            var response = RoleResource.Read("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", client: twilioRestClient);

            Assert.NotNull(response);
        }
Example #30
0
        public void TestUpdateResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"sid\": \"RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"chat_service_sid\": \"ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"friendly_name\": \"Conversation Role\",\"type\": \"conversation\",\"permissions\": [\"sendMessage\",\"leaveConversation\",\"editOwnMessage\",\"deleteOwnMessage\"],\"date_created\": \"2016-03-03T19:47:15Z\",\"date_updated\": \"2016-03-03T19:47:15Z\",\"url\": \"https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Roles/RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}"
                         ));

            var response = RoleResource.Update("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", Promoter.ListOfOne("permission"), client: twilioRestClient);

            Assert.NotNull(response);
        }