示例#1
0
        public ActionResult <ChatIntegration> UpdateIntegrationForUser([FromBody] ChatIntegration chatIntegration, [FromQuery] Guid userId)
        {
            if (chatIntegration == null || chatIntegration.InstanceId == null || userId.Equals(Guid.Empty))
            {
                return(BadRequest());
            }
            ChatIntegrationEntity entity = _userService.UpdateIntegrationForUser(chatIntegration.MapDerivedIntegrationEntity(), userId);

            if (entity == null)
            {
                return(StatusCode(500));
            }
            return(entity.MapDerivedChatIntegration());
        }
        public ChatIntegrationEntity AddIntegrationToUser(ChatIntegrationEntity integration, Guid userId)
        {
            UserEntity foundUser = _userContext.Users.Find(userId);

            if (foundUser == null)
            {
                return(null);
            }
            if (foundUser != null && foundUser.ChatIntegrations.Exists(x => Guid.Equals(x.Id, integration.Id)))
            {
                return(integration);
            }
            integration.Id = Guid.NewGuid();
            foundUser.ChatIntegrations.Add(integration);
            _userContext.SaveChanges();
            return(integration);
        }
        public ChatIntegrationEntity UpdateIntegrationForUser(ChatIntegrationEntity integration, Guid userId)
        {
            UserEntity foundUser = _userContext.Users.Find(userId);

            if (foundUser == null)
            {
                return(null);
            }
            var existingIntegration = foundUser.ChatIntegrations?.Find(x => Guid.Equals(x.Id, integration.Id));

            if (foundUser != null && existingIntegration == null)
            {
                return(null);
            }
            _userContext.Entry(existingIntegration).CurrentValues.SetValues(integration);
            _userContext.SaveChanges();
            return(integration);
        }
示例#4
0
 public static ChatIntegration MapDerivedChatIntegration(this ChatIntegrationEntity integrationEntity)
 {
     if (integrationEntity.IntegrationId.IsSlackIntegration())
     {
         var slackIntegrationEntity = (integrationEntity as SlackIntegrationEntity);
         return(new AllYourChatsAreBelongToUs.Contracts.ViewModels.Slack.SlackIntegration {
             SlackToken = slackIntegrationEntity.SlackToken,
             SlackUserId = slackIntegrationEntity.SlackUserId,
             InstanceId = slackIntegrationEntity.Id,
             IntegrationId = slackIntegrationEntity.IntegrationId,
             Name = slackIntegrationEntity.Name
         });
     }
     return(new ChatIntegration {
         InstanceId = integrationEntity.Id,
         IntegrationId = integrationEntity.IntegrationId,
         Name = integrationEntity.Name
     });
 }
 public async Task <BaseUserResponse> GetUserInfo(ChatIntegrationEntity chatIntegrationEntity)
 {
     return(await GetUserInfo(chatIntegrationEntity as SlackIntegrationEntity));
 }
示例#6
0
 public static ChatUser CreateDerivedUserInfoFromBaseResponse(this BaseUserResponse response, ChatIntegrationEntity integrationEntity)
 {
     if (integrationEntity.IntegrationId.IsSlackIntegration())
     {
         var slackUserResponse = (response as UserResponse);
         if (slackUserResponse.IsOk)
         {
             var userInfo = slackUserResponse.UserInfo;
             return(new SlackUser {
                 Id = userInfo.Id,
                 TeamId = userInfo.TeamId,
                 UserName = userInfo.Name,
                 Deleted = userInfo.Deleted,
                 Color = userInfo.Color,
                 RealName = userInfo.RealName,
                 TimeZone = userInfo.TimeZone,
                 TimeZoneLabel = userInfo.TimeZoneLabel,
                 TimeZoneOffset = userInfo.TimeZoneOffset,
                 IsAdmin = userInfo.IsAdmin,
                 IsOwner = userInfo.IsOwner,
                 IsPrimaryOwner = userInfo.IsPrimaryOwner,
                 IsRestricted = userInfo.IsRestricted,
                 IsUltraRestricted = userInfo.IsUltraRestricted,
                 IsBot = userInfo.IsBot,
                 Updated = userInfo.Updated,
                 IsAppUser = userInfo.IsAppUser,
                 Has2FA = userInfo.Has2FA,
                 Profile = new Contracts.ViewModels.Slack.Profile {
                     AvatarHash = userInfo.Profile.AvatarHash,
                     StatusText = userInfo.Profile.StatusText,
                     StatusEmoji = userInfo.Profile.StatusEmoji,
                     RealName = userInfo.Profile.RealName,
                     DisplayName = userInfo.Profile.DisplayName,
                     RealNameNormalized = userInfo.Profile.RealNameNormalized,
                     DisplayNameNormalized = userInfo.Profile.DisplayNameNormalized,
                     Email = userInfo.Profile.Email,
                     ImageOriginal = userInfo.Profile.ImageOriginal,
                     Image24 = userInfo.Profile.Image24,
                     Image32 = userInfo.Profile.Image32,
                     Image48 = userInfo.Profile.Image48,
                     Image72 = userInfo.Profile.Image72,
                     Image192 = userInfo.Profile.Image192,
                     Image512 = userInfo.Profile.Image512,
                     Team = userInfo.Profile.Team
                 }
             });
         }
     }
     return(new ChatUser());
 }