Ejemplo n.º 1
0
        public bool CanViewProject(int projectId)
        {
            var data = PermissionSetManager.GetAppPermissions(Constants.AppId);

            if (data == null)
            {
                return(false);
            }

            if (!data.Projects.Contains(Countersoft.Gemini.Commons.Constants.AllProjectsId) && !data.Projects.Contains(projectId))
            {
                return(false);
            }

            var projects = ProjectManager.GetActive();

            if (projects == null || projects.Count == 0 || !projects.Any(p => p.Entity.Id == projectId))
            {
                return(false);
            }

            if (!UserContext.User.ProjectGroups.Any(s => data.ViewGroups.Contains(s.Id) || !s.MembersForProject(projectId).Any()))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public override void AfterCreateFull(IssueDtoEventArgs args)
        {
            if (!GeminiApp.Config.EmailAlertsEnabled)
            {
                return;
            }

            var data = args.Context.GlobalConfigurationWidgetStore.Get <List <CreateItemNotifierData> >(AppConstants.AppId);

            if (data == null || data.Value == null || data.Value.Count == 0)
            {
                return;
            }

            var projectData = data.Value.Find(d => d.ProjectId.GetValueOrDefault() == args.Issue.Entity.ProjectId);

            if (projectData == null)
            {
                projectData = data.Value.Find(d => d.ProjectId.GetValueOrDefault() == 0);
            }

            if (projectData == null)
            {
                return;
            }

            var alertService = GeminiApp.Container.Resolve <IAlertTemplates>();

            var alerts = alertService.GetAll();

            var template = alerts.Find(t => t.Id == projectData.TemplateId);

            if (template == null)
            {
                return;
            }

            AlertsTemplateHelper helper = new AlertsTemplateHelper(alerts, args.GeminiUrls[0].Key);

            using (var cache = GeminiApp.Container.Resolve <ICacheContainer>())
            {
                var userManager = GeminiApp.GetManager <UserManager>(cache.Users.Find(u => u.Active && u.ProjectGroups.Where(p => p.ProjectGroupId == Constants.GlobalGroupAdministrators && p.UserId == u.Id).Any()));

                var metaManager = new MetaManager(userManager);

                var types = metaManager.TypeGetAll();

                var OrganizationManager = new OrganizationManager(userManager);

                var organizations = OrganizationManager.GetAll();

                var permissions = new PermissionSetManager(userManager);

                var permissionSets = permissions.GetAll();

                PermissionsManager permissionManager = null;

                foreach (var user in projectData.UserIds)
                {
                    var userDto = userManager.Get(user);

                    if (userDto != null && userDto.Entity.Active)
                    {
                        if (permissionManager == null)
                        {
                            permissionManager = new PermissionsManager(userDto, types, permissionSets, organizations, userManager.UserContext.Config.HelpDeskModeGroup, false);
                        }
                        else
                        {
                            permissionManager = permissionManager.Copy(userDto);
                        }

                        if (!permissionManager.CanSeeItem(args.Issue.Project, args.Issue) || !userDto.Entity.EmailMe)
                        {
                            continue;
                        }

                        var body = helper.Build(template, args.Issue, userDto);

                        string emailLog;

                        EmailHelper.Send(GeminiApp.Config, body.Key.HasValue() ? body.Key : string.Format("[{0}] {1}", args.Issue.IssueKey, args.Issue.Title), body.Value, userDto.Entity.Email, userDto.Entity.Fullname, true, out emailLog);
                    }
                }
            }
        }