public ActionResult ContinuousIntegration(int id, string platform) { Models.PlatformContinuousIntegration mdl = new Models.PlatformContinuousIntegration(); if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMemberInRole(User.Identity.GetUserName(), id, Common.Constants.APPLICATION_MEMBER_ROLE_ADMINISTRATOR)) { throw new HttpException(403, "You are not allowed to have access to this app."); } string currentUser = User.Identity.GetUserName().ToLower(); using (var context = new Repository.BetaDepotContext()) { Repository.Application app = context.Applications.Where(w => w.Id == id).FirstOrDefault(); if (app != null) { mdl.AppId = app.Id; mdl.AppName = app.Name; mdl.AppIconUrl = Platforms.Common.GenerateAppIconUrl(app.ApplicationIdentifier); mdl.AppToken = app.AppToken; Repository.TeamMember CIUser = Repository.Managers.ApplicationMgr.GetSystemCIUser(); mdl.IsContinuousIntegrationConfigured = Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(CIUser.UserName, id); } } return(View(mdl)); }
public JsonResult GenerateNewTokenForApp(int id) { if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), id)) { throw new HttpException(403, "You are not a team member of this app."); } String token = string.Empty; try { using (var context = new Repository.BetaDepotContext()) { Repository.Application app = context.Applications.Where(w => w.Id == id).FirstOrDefault(); int currentTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; token = Common.Functions.GenerateMD5Hash(string.Format("apptoken|{0}|{1}", app.ApplicationIdentifier.ToLower(), currentTimestamp)); app.AppToken = token; context.SaveChanges(); } } catch (Exception ex) { return(Json(new { Msg = Common.Constants.APPLICATION_JSON_RESULT_ERROR })); } return(Json(new { Msg = Common.Constants.APPLICATION_JSON_RESULT_SUCCESS, AppToken = token } )); }
public ActionResult TeamMembers(string platform, int id) { Models.PlatformViewTeamMembers mdl = new Models.PlatformViewTeamMembers(); if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMemberInRole(User.Identity.GetUserName(), id, Common.Constants.APPLICATION_MEMBER_ROLE_ADMINISTRATOR)) { throw new HttpException(403, "You are not allowed to have access to this app."); } string currentUser = User.Identity.GetUserName().ToLower(); using (var context = new Repository.BetaDepotContext()) { mdl.CurrentUsersMembershipRole = context.ApplicationTeamMembers .Where(w => w.TeamMember.UserName.ToLower() == currentUser && w.ApplicationId == id).FirstOrDefault().MemberRole; Repository.Application app = context.Applications.Where(w => w.Id == id).FirstOrDefault(); if (app != null) { mdl.AppId = app.Id; mdl.AppName = app.Name; mdl.AppIconUrl = Platforms.Common.GenerateAppIconUrl(app.ApplicationIdentifier); } else { return(View(mdl)); } var q = (from tm in context.TeamMembers join atm in context.ApplicationTeamMembers on tm.Id equals atm.TeamMemberId where atm.ApplicationId == id select new { TeamMemberId = tm.Id, EmailAddress = tm.EmailAddress, FirstName = tm.FirstName, LastName = tm.LastName, UserName = tm.UserName, AssignAppCount = tm.UserMemberships.Count(), TeamMembershipRole = atm.MemberRole }); q.ToList().ForEach(f => { mdl.MemberList.Add(new Models.PlatformViewTeamMembers.Members() { UserName = f.UserName, Id = f.TeamMemberId, EmailAddress = f.EmailAddress, GravitarUrl = string.Format("http://www.gravatar.com/avatar/{0}?s=36", Common.Functions.GenerateMD5Hash(f.EmailAddress.ToLower())), Name = Common.Functions.FormatFullName(f.FirstName, f.LastName), MembershipRole = f.TeamMembershipRole, AssignAppCount = f.AssignAppCount, }); }); } return(View(mdl)); }
public JsonResult ConfigureAppForCI(int id, bool shouldConfigure) { if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), id)) { throw new HttpException(403, "You are not a team member of this app."); } Repository.TeamMember CIUser = Repository.Managers.ApplicationMgr.GetSystemCIUser(); try { if (shouldConfigure) { //Check to make sure the CI user is not already a member of the APP if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(CIUser.UserName, id)) { using (var context = new Repository.BetaDepotContext()) { Repository.Application app = context.Applications.Where(w => w.Id == id).FirstOrDefault(); Repository.ApplicationTeamMember membership = new Repository.ApplicationTeamMember() { TeamMember = CIUser, MemberRole = Common.Constants.APPLICATION_MEMBER_ROLE_CONTINUOUS_INTEGRATION }; app.AssignedMembers.Add(membership); context.SaveChanges(); } } } else { //Check to make sure the CI user is not already a member of the APP if (Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), id)) { using (var context = new Repository.BetaDepotContext()) { Repository.Application app = context.Applications.Where(w => w.Id == id).FirstOrDefault(); app.AppToken = null; Repository.ApplicationTeamMember membership = context.ApplicationTeamMembers .Where(w => w.TeamMember.UserName.ToLower() == CIUser.UserName) .FirstOrDefault(); app.AssignedMembers.Remove(membership); context.SaveChanges(); } } } } catch (Exception ex) { return(Json(new { Msg = Common.Constants.APPLICATION_JSON_RESULT_ERROR })); } return(Json(new { Msg = Common.Constants.APPLICATION_JSON_RESULT_SUCCESS })); }
private bool IsAppOverLimit(Guid AppId) { using (var context = new Repository.RepoContext()) { Repository.Application app = context.Applications.Where(w => w.ApplicationId == AppId).FirstOrDefault(); if (app != null) { switch (app.SubscriptionType) { case Common.Constants.API_SUBSCRIPTION_TYPE_NO_LIMIT: app.ApiAccessMetricCurrent++; break; case Common.Constants.API_SUBSCRIPTION_TYPE_DAILY_RESET: if (app.LastDtmAccessed.DayOfYear < DateTime.UtcNow.DayOfYear) { app.ApiAccessMetricCurrent = 1; } else { app.ApiAccessMetricCurrent++; } if (app.ApiAccessMetricCurrent >= app.ApiAccessMetricLimit) { return(true); } break; case Common.Constants.API_SUBSCRIPTION_TYPE_MONTHLY_RESET: if (app.LastDtmAccessed.Month < DateTime.UtcNow.Month) { app.ApiAccessMetricCurrent = 1; } else { app.ApiAccessMetricCurrent++; } if (app.ApiAccessMetricCurrent >= app.ApiAccessMetricLimit) { return(true); } break; } app.LastDtmAccessed = DateTime.UtcNow; context.SaveChanges(); } } return(false); }
public ActionResult BuildHistory(string Platform, int id, string environment) { Models.PlatformViewAppBuildHistory mdl = new Models.PlatformViewAppBuildHistory(); if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), id)) { throw new HttpException(403, "You are not a team member of this app."); } string currentUser = User.Identity.GetUserName().ToLower(); using (var context = new BetaDepot.Repository.BetaDepotContext()) { Repository.Application app = context.Applications.Where(wa => wa.Id == id).FirstOrDefault(); mdl.CurrentUsersMembershipRole = context.ApplicationTeamMembers .Where(w => w.TeamMember.UserName.ToLower() == currentUser && w.ApplicationId == id).FirstOrDefault().MemberRole; List <Repository.ApplicationBuild> builds = context.Builds .Where(w => w.Application.Id == id && (environment == null || w.Environment.EnvironmentName == environment)) .OrderByDescending(o => o.AddedDtm) .ToList(); mdl.AppIconUrl = Platforms.Common.GenerateAppIconUrl(app.ApplicationIdentifier); mdl.AppId = id; mdl.AppName = app.Name; mdl.Platform = app.Platform; mdl.selectedEnvironment = environment ?? string.Empty; builds.ForEach(f => { mdl.Builds.Add(new Models.PlatformViewAppBuildHistory.BuildHistory() { BuildId = f.Id, BuildNotes = f.Notes, Environment = f.Environment.EnvironmentName, UploadedByName = String.Format("{0} {1}", f.AddedBy.FirstName, f.AddedBy.LastName), UploadedDtm = Common.Functions.GetPrettyDate(f.AddedDtm.ToLocalTime(), "MM/dd/yy"), VersionNumber = string.IsNullOrEmpty(f.versionCode) ? f.versionNumber : string.Format("{0} ({1})", f.versionNumber, f.versionCode), InstallUrl = Platforms.Common.GeneratePackageInstallUrl("App", "Download", f.Platform, f.UniqueIdentifier.ToString()), Platform = f.Platform }); }); } return(View(mdl)); }
public static void WriteLog(HttpRequest request) { if (Libs.LibSession.Get(Libs.Constants.ACCOUNT_LOGIN) != null) { Repository.Application applicationRepository = new Repository.Application(); Repository.User userRepository = new Repository.User(); string applicationPath = request.Path.Substring(1, request.Path.Length - 1); var app = applicationRepository.GetApplicationByFilePath(applicationPath); int userID = userRepository.GetUserIDByUsername(Libs.LibSession.Get(Libs.Constants.ACCOUNT_LOGIN).ToString()); Model.Log log = new Model.Log(); log.UserID = userID; log.Trace = applicationPath; log.Date = DateTime.Now; if (app != null) { log.Action = app.Application_Description; } if (request.ServerVariables["REMOTE_ADDR"] != null) { log.IP = request.ServerVariables["REMOTE_ADDR"].ToString(); } log.Time_Login = DateTime.Now; if (Libs.LibSession.Get(Libs.Constants.LOG) != null) { var list = (List<Model.Log>)Libs.LibSession.Get(Libs.Constants.LOG); list.Add(log); Libs.LibSession.Set(Libs.Constants.LOG, list); } else { List<Model.Log> LogList = new List<Model.Log>(); LogList.Add(log); Libs.LibSession.Set(Libs.Constants.LOG, LogList); } } }