Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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 }));
        }
Esempio n. 3
0
        public ActionResult Users()
        {
            Administration.UsersViewModel mdl = new Administration.UsersViewModel();

            List <IdentityUser>          userLogins;
            List <Repository.TeamMember> memberships;

            using (var usrContext = new IdentityDbContext())
            {
                userLogins = usrContext.Users.Include("Roles.Role").ToList();
            }

            using (var context = new Repository.BetaDepotContext())
            {
                memberships = context.TeamMembers.Include("UserMemberships").Where(w => w.IsSystemUser == false).ToList();
            }


            var rm = new RoleManager <IdentityRole>(
                new RoleStore <IdentityRole>(new ApplicationDbContext()));

            foreach (var u in userLogins)
            {
                Repository.TeamMember member = memberships.Where(w => w.UserName == u.UserName).FirstOrDefault();
                if (member != null)
                {
                    mdl.AppUsers.Add(new Administration.UsersViewModel.Users()
                    {
                        AppMemberCount = member.UserMemberships.Count(),
                        EmailAddress   = member.EmailAddress,
                        UserName       = member.UserName,
                        SystemRole     = u.Roles.Select(s => s.Role.Name).Contains(Common.Constants.SYSTEM_ROLE_ADMINISTRATOR) ? Common.Constants.SYSTEM_ROLE_ADMINISTRATOR : Common.Constants.SYSTEM_ROLE_USER,
                        Name           = string.Format("{0} {1}", member.FirstName, member.LastName),
                        GravitarUrl    = string.Format("http://www.gravatar.com/avatar/{0}?s=36", Common.Functions.GenerateMD5Hash(member.EmailAddress.ToLower()))
                    });
                }
            }

            return(View(mdl));
        }