private bool ContainsRoleType(Structure structure, Container container, RoleType roleType)
 {
     return _dbContext.Enrolls.Where(
         (cu) =>
         cu.ContainerId == container.Id &&
         cu.RoleType.Name == roleType.Name &&
         cu.RoleTypeStructureId == structure.Id
                ).Count() != 0;
 }
Beispiel #2
0
 private bool ExisteRole(Container container, RoleType roleType)
 {
     return _db.DbContext.Roles.Where(r =>
                                   r.ContainerTypeName == container.Type.Name &&
                                   r.RoleTypeName == roleType.Name
         ).Any();
 }
Beispiel #3
0
        private bool EnrollInherited(User user, Container container, RoleType roleType)
        {
            var enroll = _db.DbContext.Enrolls.Find(user.Name, container.Id, roleType.Name, container.Type.StructureId);

            if (enroll != null)
            {
                enroll.InheritedCount += 1;

                return true;
            }

            enroll = new Enroll()
            {
                User = user,
                Container = container,
                RoleType = roleType,
                Inherited = true,
                InheritedCount = 1
            };

            _db.DbContext.Enrolls.Add(enroll);

            InvokeOnEnrollUser(enroll);

            return true;
        }
Beispiel #4
0
        internal void SyncronizeEnrolls(Container container)
        {
            var roles = _db.DbContext.Roles.Where(r => r.ContainerTypeName == container.Type.Name && r.Barrier != (int)RoleBarrier.Top);
            if (roles.Count() == 0)
                return;

            var currentContainer = container.Parent;
            while(currentContainer!=null)
            {
                var currentContext = currentContainer;
                var currentRoles = _db.DbContext.Roles.Where(
                    r => r.ContainerTypeName == currentContext.Name && r.Barrier == (int)RoleBarrier.Top);

                var rolesContext = roles = roles.Where(r => !currentRoles.Where(cr => cr.RoleTypeName == r.RoleTypeName).Any());
                if (roles.Count() == 0)
                    return;

                var enrolls = _db.DbContext.Enrolls.Where(
                                e =>    e.ContainerId == currentContext.Id &&
                                        e.Inherited == false &&
                                        rolesContext.Where(r => r.RoleTypeName == e.RoleTypeName).Any()
                                                        );
                foreach (var enroll in enrolls)
                    EnrollInherited(enroll.User, container, enroll.RoleType);

                currentContainer = currentContainer.Parent;
            }
        }
Beispiel #5
0
 public EnrollEventArgs(Enroll enroll, Container container)
 {
     Enroll = enroll;
     Container = container;
 }
        private void SetChildsRoleTypes(
            IAuthorization authorization,
            Structure structure,
            Container rootContainer,
            string rootName,
            string service,
            IEnumerable<Role> roles
            )
        {
            if (rootContainer.Childs == null) return;

            foreach (var child in rootContainer.Childs)
            {
                SetChildsRoleTypes(authorization, structure, child, service, rootName, roles);

                foreach (var role in roles)
                    if (ContainsRoleType(structure, child, role.RoleType))
                    {
                        var permissions = role.Rule.Permissions.Where(
                            (sp) =>
                            sp.ServiceName == service
                            ).Select(
                                (sp) => sp.Name
                            );

                        authorization.AddGroupPermission(
                            rootName,
                            authorization.GetGroupName(structure.Id, child.Id, role.RoleTypeName),
                            permissions
                            );
                    }
            }
        }
Beispiel #7
0
        private bool PermissionToEnroll(Container container, RoleType roleType, RoleBarrier roleBarrier)
        {
            var barrier = (int) roleBarrier;

            return _db.DbContext.Roles.Where(r =>
                                          r.ContainerTypeName == container.Type.Name &&
                                          r.RoleTypeName == roleType.Name &&
                                          r.Barrier != barrier
                ).Any();
        }
Beispiel #8
0
        private void InheritedEnrollParents(User user, Container container, RoleType roleType)
        {
            var current = container;

            while (current != null){
                if (!PermissionToEnroll(current, roleType, RoleBarrier.Bottom))
                    return;

                EnrollInherited(user, current, roleType);

                current = current.Parent;
            }
        }
        private void InvokeOnDeleteContainer(Container container, ContainerType containerType)
        {
            var eventArgs = new ContainerEventArgs(container, containerType);

            if (_onDeleteContainer != null)
                try
                {
                    _onDeleteContainer(this, eventArgs);
                }catch(Exception e)
                {
                    DataBaseManager.Logger.Log(String.Format("InvokeOnDeleteContainer fail - {0}", e.Message));
                }
        }
        public Container Create(long structure, string containerName, string description, long? parent, string prototypeName)
        {
            var container = new Container
                                {
                                    Type = _dbManager.ContainerType.Get(structure, prototypeName),
                                    Description = description,
                                    Name = containerName,
                                    Parent = parent == null ? null : Get(parent.Value)
                                };
            _dbManager.DbContext.Containers.Add(container);

            _dbManager.DbContext.SaveChanges();

            InvokeOnCreateContainer(container);

            _dbManager.User.SyncronizeEnrolls(container);

            _dbManager.DbContext.SaveChanges();

            return container;
        }
 public ContainerEventArgs(Container container, ContainerType containerType)
 {
     Container = container;
     Type = containerType;
 }
Beispiel #12
0
 public override string GetInstancePath(Container container, WorkSpaceType workSpaceType)
 {
     return Path.Combine(Path.Combine(PathService, "repositories"), container.UniqueInstanceName(workSpaceType)) + ".git";
 }
        private void SetCurrentAndParentRoleTypes(
            IAuthorization authorization,
            Structure structure,
            Container rootContainer,
            string rootName,
            string service,
            IEnumerable<Role> roles
            )
        {
            Container current = rootContainer;

            do
            {
                foreach (var role in roles)
                    if (ContainsRoleType(structure, current, role.RoleType))
                    {
                        var permissions = role.Rule.Permissions.Where(
                            (sp) =>
                            sp.ServiceName == service
                            ).Select(
                                (sp) =>
                                sp.Name
                            );

                        authorization.AddGroupPermission(
                            rootName,
                            authorization.GetGroupName(structure.Id, current.Id, role.RoleTypeName),
                            permissions
                            );
                    }

                current = current.ParentContainer;
            } while (current != null);
        }
Beispiel #14
0
        private bool InheritedDisenroll(User user, Container container, RoleType roleType)
        {
            var enroll = _db.DbContext.Enrolls.Find(user.Name, container.Id, roleType.Name, container.Type.StructureId);

            if (enroll == null)
                return false;

            enroll.InheritedCount -= 1;

            if (enroll.InheritedCount == 0)
                if (enroll.Inherited)
                {
                    _db.DbContext.Enrolls.Remove(enroll);

                    InvokeOnDisenrollUser(enroll, container);
                }

            return true;
        }
        public Container Create(long structure, string containerName, string description, long? parent)
        {
            var container = new Container()
                                {
                                    Name = containerName,
                                    Description = description,
                                };

            if (parent != null)
            {
                var parentobj = _dbManager.Container.Get(parent.Value);

                container.Type = parentobj.Type.Childs.First();
                container.Parent = parentobj;
            }
            else
            {
                container.Type =
                    _dbManager.ContainerType.GetAll(structure).Where(
                        cp => cp.StructureId == structure && cp.Parent == null).SingleOrDefault();
            }

            _dbManager.DbContext.Containers.Add(container);

            _dbManager.DbContext.SaveChanges();

            InvokeOnCreateContainer(container);

            _dbManager.User.SyncronizeEnrolls(container);

            _dbManager.DbContext.SaveChanges();

            return container;
        }
Beispiel #16
0
        private void InheritedEnrollChilds(User user, Container container, RoleType roleType)
        {
            foreach (var child in container.Childs)
            {
                if (!PermissionToEnroll(child, roleType, RoleBarrier.Top))
                    continue;

                EnrollInherited(user, child, roleType);

                InheritedEnrollChilds(user, child, roleType);
            }
        }
Beispiel #17
0
 public override string GetInstancePath(Container container, WorkSpaceType workSpaceType)
 {
     return Path.Combine(_envPath, container.UniqueInstanceName(workSpaceType));
 }
Beispiel #18
0
        private void InvokeOnDisenrollUser(Enroll enroll, Container container)
        {
            var eventArgs = new EnrollEventArgs(enroll, container);

            if (_onDisenrollUser != null)
                try
                {
                    _onDisenrollUser(this, eventArgs);
                }catch(Exception e)
                {
                    DataBaseManager.Logger.Log(String.Format("InvokeOnDisenrollUser fail - {0}", e.Message));
                }
        }
Beispiel #19
0
 public abstract string GetInstancePath(Container container, WorkSpaceType workSpaceType);
Beispiel #20
0
        public static string InstancePath(string service, Container container, WorkSpaceType workSpaceType)
        {
            try
            {
                return Services.ContainsKey(service) ? Services[service].GetInstancePath(container, workSpaceType) : null;

            }catch(NotImplementedException)
            {
                return null;
            }
        }
        private void InvokeOnCreateContainer(Container container)
        {
            var dicionay = new Dictionary<string, IEnumerable<WorkSpaceTypeView>>();
            foreach (var service in _dbContext.Services)
            {
                var serviceContext = service;
                var wk = container.ContainerPrototype.WorkSpaceTypes.Where(
                    w => w.Services.Contains(serviceContext)
                    ).Select(
                        w => w.Convert()
                    );
                if (wk.Any())
                    dicionay.Add(service.Name, wk.ToList());
            }

            var eventArgs = new ContainerEventArgs()
                                {
                                    Strucuture = container.ContainerPrototype.StructureId,
                                    Container = container.Convert(),
                                    Services = dicionay
                                };
            var handler = _onCreateContainer;
            if (handler != null) handler(this, eventArgs);
        }