Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        public static EntityDashboard   ToEntity(this ModelDashboard d, DataContext dc)
        {
            var e = new EntityDashboard()
            {
                Id       = d.Id,
                OrgId    = d.OrgId,
                Title    = d.Title,
                Uid      = d.Uid,
                Data     = d.Data,
                FolderId = d.FolderId
            };

            if (null != d.Tags)
            {
                e.Tags = d
                         .Tags
                         .Select(x => new DashboardTag()
                {
                    Term = x
                })
                         .ToList();
            }

            if (string.IsNullOrEmpty(e.Uid))
            {
                e.Uid = TestFactory.GetUid();
            }

            DashboardAnalyzer.UpdateAlerts(dc, d, e);

            return(e);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        public static void UpdateAlerts(DataContext dc,
                                        ModelDashboard model, EntityDashboard entity)
        {
            if (null == model.Data)
            {
                return;
            }

            var an    = new DashboardAnalyzer(dc, model);
            var rules = an.ExtractAlerts();

            var alerts = new List <Alert>();

            foreach (var r in rules)
            {
                var alert = entity
                            .Alerts?
                            .FirstOrDefault(x => x.PanelId == r.PanelId);

                if (null == alert)
                {
                    alert = r.ToEntity();
                }
                else
                {
                    alert.Update(r);
                }

                alert.OrgId = dc.ActiveOrgId;
                alerts.Add(alert);
            }

            entity.Alerts = alerts;
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="permissions"></param>
        /// <returns></returns>
        private bool CheckDowngradedPermissions(EntityDashboard entity, ModelDashboardPermissions perms)
        {
            if (null == entity.Folder)
            {
                return(true);
            }

            foreach (var p in entity.Folder?.Permissions)
            {
                if (p.UserId.HasValue)
                {
                    var up = perms.FirstOrDefault(x => x.User?.Id == p.UserId);

                    if (null != up)
                    {
                        if (up.Permission < p.Permission)
                        {
                            return(false);
                        }
                    }
                }
                else if (p.TeamId.HasValue)
                {
                    var tp = perms.FirstOrDefault(x => x.Team?.Id == p.TeamId);

                    if (null != tp)
                    {
                        if (tp.Permission < p.Permission)
                        {
                            return(false);
                        }
                    }
                }
                else if (p.Role.HasValue)
                {
                    var rp = perms.FirstOrDefault(x => x.Role == p.Role);

                    if (null != rp)
                    {
                        if (rp.Permission < p.Permission)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        private OperationResult <PermissionRules> GetPermissions(EntityDashboard entity)
        {
            if (null == entity)
            {
                return(OperationResult <PermissionRules> .Create(ErrorCode.BadGetDashboard));
            }

            var perms = new PermissionRules();

            var nat = entity
                      .Permissions
                      .Select(x => x
                              .ToModel()
                              .AddTime(DataContext.Entry(entity)))
                      .ToList();

            var parent = entity
                         .Folder?
                         .Permissions
                         .Select(x => x
                                 .ToModel()
                                 .AddTime(DataContext.Entry(entity.Folder)))
                         .ToList() ?? new List <ModelFolderPermission>();

            if (null != entity.Folder && !entity.Folder.HasAcl)
            {
                parent.AddRange(ModelFolderPermission.GetDefault(entity.Folder.ToModel()));
            }

            if (null == entity.Folder && !entity.HasAcl)
            {
                nat.AddRange(ModelDashboardPermission.GetDefault(entity.ToModel()));
            }

            perms.AddRange(parent);
            perms.AddRange(nat);

            return(OperationResult <PermissionRules> .Create(perms));
        }