Skip to content

Commit

Permalink
ConfigurationRepository.cs - added a new method to get configuration …
Browse files Browse the repository at this point in the history
…by module name

IConfigurationRepository.cs - added a new method to get configuration by module name
OAuthLoginRepository.cs - enchance the feature of add to slack
ConfigurationRepositoryTest.cs - added new test case
OAuthLoginRepositoryTest.cs - updated test case
configuration.component.ts - enhance the add to slack feature
  • Loading branch information
siddharthashw committed Apr 5, 2017
1 parent 6ddb707 commit f31aa27
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 6 deletions.
Expand Up @@ -114,6 +114,16 @@ public async Task<LeaveAppAddedAC> IsUserAddedLeaveAppAsync(string userId)
leaveAppDetail.IsAdded = true;
return leaveAppDetail;
}

/// <summary>
/// Method to get configuration detail by module name
/// </summary>
/// <param name="module">name of module</param>
/// <returns></returns>
public async Task<Configuration> GetConfigurationBymoduleAsync(string module)
{
return await _configurationDataRepository.FirstOrDefaultAsync(x => x.Module == module);
}
#endregion

#region Private Method
Expand Down
Expand Up @@ -44,5 +44,12 @@ public interface IConfigurationRepository
/// <param name="userId">user's Id</param>
/// <returns>configuration details</returns>
Task<LeaveAppAddedAC> IsUserAddedLeaveAppAsync(string userId);

/// <summary>
/// Method to get configuration detail by module name
/// </summary>
/// <param name="module">name of module</param>
/// <returns></returns>
Task<Configuration> GetConfigurationBymoduleAsync(string module);
}
}
Expand Up @@ -3,6 +3,7 @@
using NLog;
using Promact.Core.Repository.AppCredentialRepository;
using Promact.Core.Repository.BotRepository;
using Promact.Core.Repository.ConfigurationRepository;
using Promact.Core.Repository.SlackChannelRepository;
using Promact.Core.Repository.SlackUserRepository;
using Promact.Erp.DomainModel.ApplicationClass;
Expand Down Expand Up @@ -34,6 +35,7 @@ public class OAuthLoginRepository : IOAuthLoginRepository
private readonly IAppCredentialRepository _appCredentialRepository;
private readonly ILogger _logger;
private readonly ISocketClientWrapper _socketClientWrapper;
private readonly IConfigurationRepository _configurationRepository;
#endregion

#region Constructor
Expand All @@ -42,7 +44,8 @@ public class OAuthLoginRepository : IOAuthLoginRepository
IRepository<SlackChannelDetails> slackChannelDetailsRepository, IStringConstantRepository stringConstant,
ISlackUserRepository slackUserRepository, IEnvironmentVariableRepository envVariableRepository,
IRepository<IncomingWebHook> incomingWebHook, ISlackChannelRepository slackChannelRepository,
IAppCredentialRepository appCredentialRepository, ISocketClientWrapper socketClientWrapper)
IAppCredentialRepository appCredentialRepository, ISocketClientWrapper socketClientWrapper,
IConfigurationRepository configurationRepository)
{
_userManager = userManager;
_httpClientService = httpClientService;
Expand All @@ -56,6 +59,7 @@ public class OAuthLoginRepository : IOAuthLoginRepository
_appCredentialRepository = appCredentialRepository;
_logger = LogManager.GetLogger("AuthenticationModule");
_socketClientWrapper = socketClientWrapper;
_configurationRepository = configurationRepository;
}

#endregion
Expand Down Expand Up @@ -117,6 +121,7 @@ public OAuthApplication ExternalLoginInformation(string refreshToken)
public async Task AddSlackUserInformationAsync(string code)
{
AppCredential appCredential = await _appCredentialRepository.FetchSelectedAppAsync();
Configuration configuration = await _configurationRepository.GetConfigurationBymoduleAsync(appCredential.Module);
if (appCredential != null)
{
string slackOAuthRequest = string.Format(_stringConstant.SlackOauthRequestUrl, appCredential.ClientId, appCredential.ClientSecret, code);
Expand All @@ -126,7 +131,8 @@ public async Task AddSlackUserInformationAsync(string code)
appCredential.BotToken = slackOAuth?.Bot?.BotAccessToken;
appCredential.BotUserId = slackOAuth?.Bot?.BotUserId;
await _appCredentialRepository.UpdateBotTokenAsync(appCredential);

configuration.Status = true;
await _configurationRepository.UpdateConfigurationAsync(configuration);
_logger.Info("slackOAuth UserID" + slackOAuth.UserId);
bool checkUserIncomingWebHookExist = _incomingWebHookRepository.Any(x => x.UserId == slackOAuth.UserId);
if (!checkUserIncomingWebHookExist && !string.IsNullOrEmpty(slackOAuth.IncomingWebhook?.Url))
Expand Down
3 changes: 0 additions & 3 deletions Slack.Automation/Promact.Core.Test/AutofacConfig.cs
Expand Up @@ -40,9 +40,6 @@
using Promact.Core.Repository.AppCredentialRepository;
using Promact.Core.Repository.BotRepository;
using Promact.Core.Repository.RedmineRepository;
using Promact.Core.Repository.ConfigurationRepository;
using Promact.Core.Repository.AppCredentialRepository;
using Promact.Core.Repository.BotRepository;

namespace Promact.Core.Test
{
Expand Down
11 changes: 11 additions & 0 deletions Slack.Automation/Promact.Core.Test/ConfigurationRepositoryTest.cs
Expand Up @@ -110,6 +110,17 @@ public async Task DisableAppByConfigurationIdAsync()
var configuration = await _configurationDataRepository.FirstAsync(x=>x.Id == configurationId);
Assert.False(configuration.Status);
}

/// <summary>
/// Test case to test the method DisableAppByConfigurationIdAsync of ConfigurationRepository
/// </summary>
[Fact, Trait("Category", "Required")]
public async Task GetConfigurationBymoduleAsync()
{
await AddConfigurationAsync();
var result = await _configurationRepository.GetConfigurationBymoduleAsync(_stringConstant.TaskModule);
Assert.False(result.Status);
}
#endregion

#region Initialization
Expand Down
Expand Up @@ -8,6 +8,7 @@
using Promact.Core.Repository.SlackChannelRepository;
using Promact.Core.Repository.SlackUserRepository;
using Promact.Erp.DomainModel.ApplicationClass.SlackRequestAndResponse;
using Promact.Erp.DomainModel.DataRepository;
using Promact.Erp.DomainModel.Models;
using Promact.Erp.Util.EnvironmentVariableRepository;
using Promact.Erp.Util.HttpClient;
Expand Down Expand Up @@ -38,6 +39,7 @@ public class OAuthLoginRepositoryTest
private SlackProfile profile = new SlackProfile();
private ApplicationUser user = new ApplicationUser();
private AppCredential appCredential = new AppCredential();
private readonly IRepository<Configuration> _configurationDataRepository;
#endregion

#region Constructor
Expand All @@ -54,6 +56,7 @@ public OAuthLoginRepositoryTest()
_mockServiceRepository = _componentContext.Resolve<Mock<IServiceRepository>>();
_userManager = _componentContext.Resolve<ApplicationUserManager>();
_appCredentialRepository = _componentContext.Resolve<IAppCredentialRepository>();
_configurationDataRepository = _componentContext.Resolve<IRepository<Configuration>>();
Initialize();
}
#endregion
Expand Down Expand Up @@ -103,6 +106,9 @@ public void ExternalLoginInformation()
[Fact, Trait("Category", "Required")]
public async Task AddSlackUserInformation()
{
Configuration configuration = new Configuration() {CreatedOn = DateTime.UtcNow, Module = _stringConstant.LeaveModule, Status = false };
_configurationDataRepository.Insert(configuration);
await _configurationDataRepository.SaveChangesAsync();
UserLoginInfo info = new UserLoginInfo(_stringConstant.PromactStringName, _stringConstant.AccessTokenForTest);
await _userManager.CreateAsync(user);
await _userManager.AddLoginAsync(user.Id, info);
Expand Down
Expand Up @@ -31,13 +31,13 @@ export class ConfigurationComponent implements OnInit {
openModel(configuration: Configuration, popup) {
this.loader.loader = true;
this.configurationId = configuration.Id;
this.updateConfiguration(configuration);
this.loader.loader = false;
if (configuration.Status === true) {
popup.open(this.dialogConfig);
}
else {
this.loader.loader = true;
this.updateConfiguration(configuration);
this.configurationStatus = this.sharedService.getConfigurationStatusAC();
if (configuration.Module === this.stringConstant.leaveModule)
{ this.configurationStatus.LeaveOn = configuration.Status; }
Expand Down

0 comments on commit f31aa27

Please sign in to comment.