Skip to content

Commit

Permalink
Removed unnecessary slack events. Removed use of slack user name from…
Browse files Browse the repository at this point in the history
… ScrumBotRepository and updated its test cases. Fixes#358.
  • Loading branch information
juliepromact committed Jun 1, 2017
1 parent 2be8235 commit f806da9
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 293 deletions.
@@ -1,5 +1,4 @@
using Promact.Erp.DomainModel.ApplicationClass;
using Promact.Erp.DomainModel.ApplicationClass.SlackRequestAndResponse;
using Promact.Erp.DomainModel.Models;
using System.Threading.Tasks;

Expand All @@ -16,31 +15,22 @@ public interface IOAuthLoginRepository
/// <returns>user information</returns>
Task<ApplicationUser> AddNewUserFromExternalLoginAsync(string email, string refreshToken, string userId);


/// <summary>
/// Method to get OAuth Server's app information
/// </summary>
/// <param name="refreshToken"></param>
/// <returns>Oauth</returns>
OAuthApplication ExternalLoginInformation(string refreshToken);


/// <summary>
/// Method to add Slack Users,channels and groups information
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
Task AddSlackUserInformationAsync(string code);

/// <summary>
/// Method to update slack user table when there is any changes in slack
/// </summary>
/// <param name="slackEvent"></param>
Task SlackEventUpdateAsync(SlackEventApiAC slackEvent);

/// <summary>
/// Method to update slack channel table when a channel is added or updated in team.
/// </summary>
/// <param name="slackEvent"></param>
Task SlackChannelAddAsync(SlackEventApiAC slackEvent);

/// <summary>
/// Method check user slackid is exists or ot
Expand Down
Expand Up @@ -56,6 +56,7 @@ public class OAuthLoginRepository : IOAuthLoginRepository
#endregion

#region Public Methods

/// <summary>
/// Method to add a new user in Application user table and store user's external login information in UserLogin table
/// </summary>
Expand All @@ -80,6 +81,7 @@ public async Task<ApplicationUser> AddNewUserFromExternalLoginAsync(string email
return userInfo;
}


/// <summary>
/// Method to get OAuth Server's app information
/// </summary>
Expand All @@ -97,6 +99,7 @@ public OAuthApplication ExternalLoginInformation(string refreshToken)
return oAuth;
}


/// <summary>
/// Method to add/update Slack User,channels and groups information
/// </summary>
Expand Down Expand Up @@ -187,7 +190,6 @@ public async Task AddSlackUserInformationAsync(string code)
}
else
throw new SlackAuthorizeException(_stringConstant.SlackAuthError + slackUsers.ErrorMessage);

}


Expand All @@ -212,50 +214,6 @@ private async Task AddChannelGroupAsync(SlackChannelDetails slackChannelDetails)
slackChannel.Name = slackChannelDetails.Name;
await _slackChannelRepository.UpdateSlackChannelAsync(slackChannel);
}

}


/// <summary>
/// Method to update slack user table when there is any changes in slack
/// </summary>
/// <param name="slackEvent"></param>
public async Task SlackEventUpdateAsync(SlackEventApiAC slackEvent)
{
SlackUserDetails user = await _slackUserDetailsRepository.FirstOrDefaultAsync(x => x.UserId == slackEvent.Event.User.UserId);
_logger.Debug("User details : " + user);
if (user == null)
{
_logger.Debug("SlackUserRepository - AddSlackUserAsync");
await _slackUserRepository.AddSlackUserAsync(slackEvent.Event.User);
}
}


/// <summary>
/// Method to update slack channel table when a channel is added or updated in team.
/// </summary>
/// <param name="slackEvent"></param>
public async Task SlackChannelAddAsync(SlackEventApiAC slackEvent)
{
SlackChannelDetails channel = await _slackChannelDetails.FirstOrDefaultAsync(x => x.ChannelId == slackEvent.Event.Channel.ChannelId);
_logger.Debug("Channel : " + channel);
if (channel == null)
{
_loggerSlackEvent.Debug("New channel adding");
slackEvent.Event.Channel.CreatedOn = DateTime.UtcNow;
_slackChannelDetails.Insert(slackEvent.Event.Channel);
await _slackChannelDetails.SaveChangesAsync();
_loggerSlackEvent.Debug("Channel added successfully");
}
else
{
_loggerSlackEvent.Debug("Updating channel");
channel.Name = slackEvent.Event.Channel.Name;
_slackChannelDetails.Update(channel);
await _slackChannelDetails.SaveChangesAsync();
_loggerSlackEvent.Debug("Channel updated successfully");
}
}


Expand Down

0 comments on commit f806da9

Please sign in to comment.