public async Task <UserRight> Get(string userId, string resourceId, RightType type)
        {
            userId.ThrowArgumentExceptionIfNull(nameof(userId), "Cannot be empty");
            userId.ThrowArgumentExceptionIfNull(nameof(resourceId), "Cannot be empty");

            return(await Get <UserRight>(userId, resourceId, type));
        }
Exemple #2
0
        /// <summary>
        /// Sets the control.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="rightType">Type of the right.</param>
        private static void SetControl(System.Windows.Forms.Control control, RightType rightType)
        {
            switch (rightType)
            {
            case RightType.Enable:
                control.Visible = true;
                control.Enabled = true;
                break;

            case RightType.Disable:
                control.Visible = true;
                control.Enabled = false;
                break;

            case RightType.Visible:
                control.Visible = true;
                break;

            case RightType.Hidden:
                control.Visible = false;
                break;

            default:
                control.Enabled = true;
                control.Visible = true;
                break;
            }
        }
Exemple #3
0
        public bool HasEffectiveRight(long?userId, long?entityId, long key, RightType rightType)
        {
            using (var uow = this.GetUnitOfWork())
            {
                var entityPermissionRepository = uow.GetRepository <EntityPermission>();
                var userRepository             = uow.GetReadOnlyRepository <User>();

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

                if (userId == null)
                {
                    return((entityPermissionRepository.Get(p => p.Subject == null && p.Entity.Id == entityId && p.Key == key).FirstOrDefault()?.Rights & (int)rightType) > 0);
                }


                var user = userRepository.Get((long)userId);

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

                var subjectIds = new List <long>()
                {
                    user.Id
                };
                subjectIds.AddRange(user.Groups.Select(g => g.Id).ToList());
                var rights = entityPermissionRepository.Get(m => (subjectIds.Contains(m.Subject.Id) || m.Subject == null) && m.Entity.Id == entityId && m.Key == key).Select(e => e.Rights).ToList();
                return((rights.Aggregate(0, (left, right) => left | right) & (int)rightType) > 0);
            }
        }
        public async Task <string> SetRight(
            string userId,
            string resourceId,
            RightType type,
            Permission permission)
        {
            var userRight = await Get(userId, resourceId, type);

            if (userRight.IsNotNull())
            {
                return(userRight.Id);
            }

            var id = _idGenerator.New();

            userRight = new UserRight
            {
                Id         = id,
                UserId     = userId,
                ResourceId = resourceId,
                Rights     = permission,
                Type       = type
            };

            Log.TraceFormat(
                "Add right: user {0} to [{1:G},{2}] => rights {3:X} ({3:G})",
                userId,
                type,
                resourceId,
                permission);

            await _dbContext.SaveAsync(userRight);

            return(id);
        }
Exemple #5
0
        /// <summary>
        /// 权限类型工厂
        /// </summary>
        /// <param name="type">权限类型</param>
        /// <returns></returns>
        public IRight GetInstance(RightType type)
        {
            IRight right;

            switch (type)
            {
            case RightType.Function:
                right = new FunctionRight();
                break;

            case RightType.EntryRight:
                right = new EntryRight();
                break;

            case RightType.ButtonRight:
                right = new ButtonRight();
                break;

            case RightType.ButtonRightByMenu:
                right = new ButtonRightByMenu();
                break;

            case RightType.Field:
                right = new FieldRight();
                break;

            default:
                right = null;
                break;
            }
            return(right);
        }
Exemple #6
0
        public List <long> GetKeys(long?subjectId, long entityId, RightType rightType)
        {
            using (var uow = this.GetUnitOfWork())
            {
                var entityPermissionRepository = uow.GetReadOnlyRepository <EntityPermission>();

                if (subjectId == null)
                {
                    return(entityPermissionRepository.Query(e =>
                                                            e.Subject == null &&
                                                            e.Entity.Id == entityId &&
                                                            (e.Rights & (int)rightType) > 0
                                                            )
                           .Select(e => e.Key)
                           .ToList());
                }

                return(entityPermissionRepository.Query(e =>
                                                        e.Subject.Id == subjectId &&
                                                        e.Entity.Id == entityId &&
                                                        (e.Rights & (int)rightType) > 0
                                                        )
                       .Select(e => e.Key)
                       .ToList());
            }
        }
 protected void CheckRealEquation()
 {
     if (LeftType.Equals(SimpleType.Real) && RightType.Equals(SimpleType.Real))
     {
         GenerateFind(new RealEqualWarning(Token.Operator, Words, this is EqualToken));
     }
 }
Exemple #8
0
 public BExISEntityAuthorizeAttribute(Type entityType, string keyName, RightType rightType)
 {
     //this.entityName = entityName;
     this.entityType = entityType;
     this.keyName    = keyName;
     this.rightType  = rightType;
 }
        private string checkJobs(IList <Job> jobs, RightType right, string zoneId = null)
        {
            if (jobs == null || jobs.Count == 0)
            {
                throw new ArgumentException("List of job objects cannot be null or empty");
            }

            string name = null;

            foreach (Job job in jobs)
            {
                checkJob(job, right, zoneId);

                if (StringUtils.IsEmpty(name))
                {
                    name = job.Name;
                }

                if (!name.Equals(job.Name))
                {
                    throw new ArgumentException("All job objects must have the same name");
                }
            }
            return(name);
        }
 public AuthoriseAttribute(
     RightType type,
     Permission permission = Permission.None,
     string resourceKey    = ResourceKey.Id)
 {
     // here's the magic of a delimited string
     Policy = PolicyName.Make(type, permission, resourceKey).Serialise();
 }
Exemple #11
0
 public bool Exists(long?subjectId, long entityId, long key, RightType rightType)
 {
     using (var uow = this.GetUnitOfWork())
     {
         var entityPermissionRepository = uow.GetRepository <EntityPermission>();
         return(subjectId == null?entityPermissionRepository.Get(p => p.Subject == null && p.Entity.Id == entityId && p.Key == key && (p.Rights & (int)rightType) > 0).Count == 1 : entityPermissionRepository.Get(p => p.Subject.Id == subjectId && p.Entity.Id == entityId && p.Key == key && (p.Rights & (int)rightType) > 0).Count == 1);
     }
 }
Exemple #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OperationAuthorisationFilter" /> class.
 /// </summary>
 /// <param name="authorisationService">An instance of either the <see cref="IAuthorisationService" /> class.</param>
 /// <param name="sessionToken">Session token.</param>
 /// <param name="serviceName">The service name to check permissions.</param>
 /// <param name="permission">The permission requested. Any of: ADMIN, CREATE, DELETE, PROVIDE, QUERY, SUBSCRIBE, UPDATE</param>
 /// <param name="privilege">The access level requested. Any of APPROVED, REJECTED, SUPPORTED</param>
 public OperationAuthorisationFilter(IAuthorisationService authorisationService, string sessionToken, string serviceName, RightType permission, RightValue privilege)
 {
     this.authorisationService = authorisationService;
     this.sessionToken         = sessionToken;
     this.serviceName          = serviceName;
     this.permission           = permission;
     this.privilege            = privilege;
 }
Exemple #13
0
 /// <summary>
 /// Creates an Option Contract
 /// </summary>
 /// <param name="equitySymbol">Symbol of the equity. See <see cref="Contract.Symbol"/>.</param>
 /// <param name="optionSymbol">Symbol of the option for the underlying equity. See <see cref="Contract.LocalSymbol"/>.</param>
 /// <param name="year">Option Expiration Year. See <see cref="Contract.Expiry"/>.</param>
 /// <param name="month">Option Expiration Month. See <see cref="Contract.Expiry"/>.</param>
 /// <param name="right">Option Right (Put or Call). See <see cref="Contract.Right"/>.</param>
 /// <param name="strike">Option Strike Price. See <see cref="Contract.Strike"/>.</param>
 public Option(string equitySymbol, string optionSymbol, int year, int month,
 RightType right, decimal strike)
     : base(0, equitySymbol, SecurityType.Option, "", (double)strike,
 right, "100", "SMART", "USD", optionSymbol, "SMART", SecurityIdType.None, string.Empty)
 {
     StringBuilder ExpirationString = new StringBuilder();
     ExpirationString.AppendFormat("{0:0000}{1:00}", year, month);
     Expiry = ExpirationString.ToString();
 }
Exemple #14
0
 public static PolicyName Make(RightType type, Permission access, string resourceKey)
 {
     return(new PolicyName
     {
         Type = type,
         Access = access,
         ResourceKey = resourceKey
     });
 }
 private async Task <T> Get <T>(string userId, string resourceId, RightType type) where T : class
 {
     return(await _dbContext.SingleOrDefault <T>(new List <ScanCondition>
     {
         new ScanCondition(nameof(UserRight.UserId), ScanOperator.Equal, userId),
         new ScanCondition(nameof(UserRight.ResourceId), ScanOperator.Equal, resourceId),
         new ScanCondition(nameof(UserRight.Type), ScanOperator.Equal, type)
     }));
 }
        public async void Update(string userId, string resourceId, RightType rightType, Permission permission)
        {
            var userRight = (await Get(userId, resourceId, rightType))
                            .ThrowObjectNotFoundExceptionIfNull($"Users rights not found: '{userId}' '{resourceId}'");

            userRight.Rights = permission;

            await _dbContext.SaveAsync(userRight);
        }
 public HasPermissionsOnResourceRequirement(
     RightType rightType,
     Permission access       = Permission.None,
     string resourceKeyInUri = "id")
 {
     Type             = rightType;
     ResourceKeyInUri = resourceKeyInUri;
     Access           = access;
 }
Exemple #18
0
        private bool hasUserRights(long entityId, RightType rightType)
        {
            #region security permissions and authorisations check

            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();
            return(entityPermissionManager.HasEffectiveRight(GetUsernameOrDefault(), "Dataset", typeof(Dataset), entityId, rightType));

            #endregion security permissions and authorisations check
        }
Exemple #19
0
        /// <summary>
        /// ** 功能描述:	由ViewValue判断是否有权限
        ///						ViewValue的存储方式:将二进制数转为十进制数存储
        ///							第四位:Export权限
        ///							第三位:Read权限
        ///							第二位:Write权限
        ///							第一位:Delete权限
        ///							如数字5即为二进制101,表示有Read和Delete权限,没有Write权限
        /// ** 作 者:		Jane Shu
        /// ** 日 期:		2005-03-10
        /// ** 修 改:		Jane Shu  2005-04-27
        /// </summary>
        /// <param name="viewValue">ViewValue</param>
        /// <param name="rightType">权限类型:Read/Write/Delete/Export</param>
        /// <param name="merge">是否做权限的拼合</param>
        /// <returns>有权限返回true,没有返回false</returns>
        public bool HasRight(string viewValue, RightType rightType, bool merge)
        {
            if (viewValue == null)
            {
                return(false);
            }

            if (rightType == RightType.Access)
            {
                return(true);
            }

            int value = 0;

            try
            {
                value = System.Int32.Parse(viewValue);
            }
            catch
            {
                ExceptionManager.Raise(this.GetType(), "$Error_ViewValue_Format");

                return(false);
            }

            if (rightType == RightType.Export)
            {
                return((value & 8) == 8);
            }

            if (rightType == RightType.Read)
            {
                if (merge)
                {
                    return((value & 4) == 4 ||
                           (value & 2) == 2 ||                      // 有写权限表示有读权限
                           (value & 1) == 1);                       // 有删除权限表示有读权限
                }
                else
                {
                    return((value & 4) == 4);
                }
            }

            if (rightType == RightType.Write)
            {
                return((value & 2) == 2);
            }

            if (rightType == RightType.Delete)
            {
                return((value & 1) == 1);
            }

            return(true);
        }
Exemple #20
0
 private void createRightFromDatarow(DataRow sysRightRow)
 {
     if ((sysRightRow != null) && (sysRightRow.ItemArray.Length > 0))
     {
         this.id    = sysRightRow["F_ID"].ToString();
         this.name  = sysRightRow["F_MENU"].ToString();
         this.eType = (RightType)Convert.ToUInt16(sysRightRow["F_TYPE"]);
         this.mapID = sysRightRow["F_MAPID"].ToString();
     }
 }
Exemple #21
0
        /// <summary>
        /// Creates an Option Contract
        /// </summary>
        /// <param name="equitySymbol">Symbol of the equity. See <see cref="Contract.Symbol"/>.</param>
        /// <param name="optionSymbol">Symbol of the option for the underlying equity. See <see cref="Contract.LocalSymbol"/>.</param>
        /// <param name="year">Option Expiration Year. See <see cref="Contract.Expiry"/>.</param>
        /// <param name="month">Option Expiration Month. See <see cref="Contract.Expiry"/>.</param>
        /// <param name="right">Option Right (Put or Call). See <see cref="Contract.Right"/>.</param>
        /// <param name="strike">Option Strike Price. See <see cref="Contract.Strike"/>.</param>
        public Option(string equitySymbol, string optionSymbol, int year, int month,
                      RightType right, decimal strike)
            : base(0, equitySymbol, SecurityType.Option, "", (double)strike,
                   right, "100", "SMART", "USD", optionSymbol, "SMART", SecurityIdType.None, string.Empty)
        {
            StringBuilder ExpirationString = new StringBuilder();

            ExpirationString.AppendFormat("{0:0000}{1:00}", year, month);
            Expiry = ExpirationString.ToString();
        }
 private async Task <IEnumerable <UserInheritRight> > GetInheritRights(
     RightType resourceType,
     string resourceId,
     RightType inheritType)
 {
     return(await _dbContext.Where <UserInheritRight>(new List <ScanCondition>
     {
         new ScanCondition(nameof(UserInheritRight.Type), ScanOperator.Equal, resourceType),
         new ScanCondition(nameof(UserInheritRight.ResourceId), ScanOperator.Equal, resourceId),
         new ScanCondition(nameof(UserInheritRight.InheritType), ScanOperator.Equal, inheritType)
     }));
 }
Exemple #23
0
 public static OptionType?RightTypeToOptionType(RightType right)
 {
     if (right == RightType.Undefined)
     {
         return(null);
     }
     if (right == RightType.Call)
     {
         return(OptionType.Call);
     }
     return(OptionType.Put);
 }
Exemple #24
0
        public bool HasEffectiveRight(string username, Type entityType, long key, RightType rightType)
        {
            using (var uow = this.GetUnitOfWork())
            {
                var userRepository   = uow.GetReadOnlyRepository <User>();
                var entityRepository = uow.GetReadOnlyRepository <Entity>();

                var user     = userRepository.Query(s => s.Name.ToUpperInvariant() == username.ToUpperInvariant()).FirstOrDefault();
                var entities = entityRepository.Query(e => e.EntityType == entityType).Select(e => e.Id).ToList();

                return(HasEffectiveRight(user?.Id, entities, key, rightType));
            }
        }
Exemple #25
0
 /// <summary>
 /// New employee right without any link to database
 /// </summary>
 /// <returns>Employee right instance</returns>
 public EmployeeRight NewEmployeeRight(Employee employee, RightType rightType)
 {
     try
     {
         var right = Get(rightType);
         return NewEmployeeRight(employee, right);
     }
     catch (Exception ex)
     {
         RaiseDatabaseLog(ex.GetExceptionText($"{nameof(Repository)}.{System.Reflection.MethodBase.GetCurrentMethod().Name}<{typeof(EmployeeRight).Name}>()"));
         throw;
     }
 }
Exemple #26
0
        public bool HasRight(long?subjectId, List <long> entityIds, long key, RightType rightType)
        {
            using (var uow = this.GetUnitOfWork())
            {
                var entityPermissionRepository = uow.GetRepository <EntityPermission>();

                if (entityIds.Count != 1)
                {
                    return(false);
                }

                return(subjectId == null ? (entityPermissionRepository.Get(p => p.Subject == null && entityIds.Contains(p.Entity.Id) && p.Key == key).FirstOrDefault()?.Rights & (int)rightType) > 0 : (entityPermissionRepository.Get(p => (p.Subject.Id == subjectId || p.Subject == null) && entityIds.Contains(p.Entity.Id) && p.Key == key).FirstOrDefault()?.Rights & (int)rightType) > 0);
            }
        }
        private void checkJob(Job job, RightType right, string zoneId = null, Boolean ignoreId = false)
        {
            Model.Infrastructure.Service service = checkJob(job, zoneId);

            if (!ignoreId && !right.Equals(RightType.CREATE) && job.Id == null)
            {
                throw new ArgumentException("Job must have an Id for any non-creation operation");
            }

            if (service.Rights[right.ToString()].Value.Equals(RightValue.REJECTED.ToString()))
            {
                throw new ArgumentException("The attempted operation is not permitted in the ACL of the current environment");
            }
        }
        protected virtual void ConvertOperands()
        {
            LeftType  = LeftOperand.GetSemanticType();
            RightType = RightOperand.GetSemanticType();

            if (LeftType.Equals(SimpleType.Integer) && RightType.Equals(SimpleType.Real))
            {
                LeftType = SimpleType.Real;
            }

            if (LeftType.Equals(SimpleType.Real) && RightType.Equals(SimpleType.Integer))
            {
                RightType = SimpleType.Real;
            }
        }
Exemple #29
0
 /// <summary>
 /// Creates an Option Contract
 /// </summary>
 /// <param name="equitySymbol">Symbol of the equity. See <see cref="Contract.Symbol"/>.</param>
 /// <param name="optionSymbol">Symbol of the option for the underlying equity. See <see cref="Contract.LocalSymbol"/>.</param>
 /// <param name="expiry">Option Expiration String. See <see cref="Contract.Expiry"/>.</param>
 /// <param name="right">Option Right (Put or Call). See <see cref="Contract.Right"/>.</param>
 /// <param name="strike">Option Strike Price. See <see cref="Contract.Strike"/>.</param>
 public Option(string equitySymbol, string optionSymbol, string expiry, RightType right, double strike)
 {
     ConId       = 0;
     Symbol      = equitySymbol;
     SecType     = EnumDescConverter.GetEnumDescription(SecurityType.Option);
     Expiry      = expiry;
     Strike      = strike;
     Right       = EnumDescConverter.GetEnumDescription(right);
     Multiplier  = "100";
     Exchange    = "SMART";
     Currency    = "USD";
     LocalSymbol = optionSymbol;
     PrimaryExch = "SMART";
     SecIdType   = EnumDescConverter.GetEnumDescription(SecurityIdType.None);
     SecId       = string.Empty;
 }
Exemple #30
0
 /// <summary>
 /// Creates an Option Contract
 /// </summary>
 /// <param name="symbol">This is the symbol of the underlying asset.</param>
 /// <param name="exchange">The order destination, such as Smart.</param>
 /// <param name="securityType">This is the security type.</param>
 /// <param name="currency">Specifies the currency.</param>
 /// <param name="expiry">The expiration date. Use the format YYYYMM.</param>
 /// <param name="strike">The strike price.</param>
 /// <param name="right">Specifies a Put or Call.</param>
 public Option(string symbol, string exchange, SecurityType securityType, string currency, string expiry, double strike, RightType right)
 {
     ConId       = 0;
     Symbol      = symbol;
     SecType     = EnumDescConverter.GetEnumDescription(securityType);
     Expiry      = expiry;
     Strike      = strike;
     Right       = EnumDescConverter.GetEnumDescription(right);
     Multiplier  = null;
     Exchange    = exchange;
     Currency    = currency;
     LocalSymbol = null;
     PrimaryExch = null;
     SecIdType   = EnumDescConverter.GetEnumDescription(SecurityIdType.None);
     SecId       = string.Empty;
 }
Exemple #31
0
 /// <summary>
 /// Creates an Option Contract
 /// </summary>
 /// <param name="equitySymbol">Symbol of the equity. See <see cref="Contract.Symbol"/>.</param>
 /// <param name="optionSymbol">Symbol of the option for the underlying equity. See <see cref="Contract.LocalSymbol"/>.</param>
 /// <param name="expiry">Option Expiration String. See <see cref="Contract.Expiry"/>.</param>
 /// <param name="right">Option Right (Put or Call). See <see cref="Contract.Right"/>.</param>
 /// <param name="strike">Option Strike Price. See <see cref="Contract.Strike"/>.</param>
 public Option(string equitySymbol, string optionSymbol, string expiry, RightType right, double strike)
 {
     ConId   = 0;
     Symbol  = equitySymbol;
     SecType = SecurityType.Option.Value;
     LastTradeDateOrContractMonth = expiry;
     Strike      = strike;
     Right       = right.Value;
     Multiplier  = "100";
     Exchange    = "SMART";
     Currency    = "USD";
     LocalSymbol = optionSymbol;
     PrimaryExch = "SMART";
     SecIdType   = SecurityIdType.None.Value;
     SecId       = string.Empty;
 }
Exemple #32
0
 /// <summary>
 /// Creates an Option Contract
 /// </summary>
 /// <param name="equitySymbol">Symbol of the equity. See <see cref="Contract.Symbol"/>.</param>
 /// <param name="optionSymbol">Symbol of the option for the underlying equity. See <see cref="Contract.LocalSymbol"/>.</param>
 /// <param name="expiry">Option Expiration String. See <see cref="Contract.Expiry"/>.</param>
 /// <param name="right">Option Right (Put or Call). See <see cref="Contract.Right"/>.</param>
 /// <param name="strike">Option Strike Price. See <see cref="Contract.Strike"/>.</param>
 public Option(string equitySymbol, string optionSymbol, string expiry, RightType right, double strike)
 {
     ConId       = 0;
     Symbol      = equitySymbol;
     SecType     = EnumDescConverter.GetEnumDescription(SecurityType.Option);
     Expiry      = expiry;
     Strike      = strike;
     Right       = EnumDescConverter.GetEnumDescription(right);
     Multiplier  = "100";
     Exchange    = "SMART";
     Currency    = "USD";
     LocalSymbol = optionSymbol;
     PrimaryExch = "SMART";
     SecIdType   = EnumDescConverter.GetEnumDescription(SecurityIdType.None);
     SecId       = string.Empty;
 }
        private bool hasUserRights(long instanceId, RightType rightType)
        {
            EntityManager entityManager = new EntityManager();

            try
            {
                var entity = entityManager.FindByName("Dataset");
                return(hasUserRights(instanceId, entity.Id, rightType));
            }
            catch
            {
                return(false);
            }
            finally
            {
                entityManager.Dispose();
            }
        }
Exemple #34
0
        public bool HasEffectiveRight(Subject subject, Entity entity, long key, RightType rightType)
        {
            using (var uow = this.GetUnitOfWork())
            {
                var entityPermissionRepository = uow.GetReadOnlyRepository <EntityPermission>();

                if (subject == null)
                {
                    return((entityPermissionRepository.Get(m => m.Subject == null && m.Entity.Id == entity.Id && m.Key == key).FirstOrDefault()?.Rights & (int)rightType) > 0);
                }
                if (entity == null)
                {
                    return(false);
                }

                return((GetEffectiveRights(subject.Id, entity.Id, key) & (int)rightType) > 0);
            }
        }
Exemple #35
0
        /// <summary>
        /// Creates an Option Contract
        /// </summary>
        /// <param name="equitySymbol">Symbol of the equity. See <see cref="Contract.Symbol"/>.</param>
        /// <param name="optionSymbol">Symbol of the option for the underlying equity. See <see cref="Contract.LocalSymbol"/>.</param>
        /// <param name="year">Option Expiration Year. See <see cref="Contract.Expiry"/>.</param>
        /// <param name="month">Option Expiration Month. See <see cref="Contract.Expiry"/>.</param>
        /// <param name="right">Option Right (Put or Call). See <see cref="Contract.Right"/>.</param>
        /// <param name="strike">Option Strike Price. See <see cref="Contract.Strike"/>.</param>
        public Option(string equitySymbol, string optionSymbol, int year, int month, RightType right, double strike)
        {
            ConId       = 0;
            Symbol      = equitySymbol;
            SecType     = EnumDescConverter.GetEnumDescription(SecurityType.Option);
            Expiry      = "";
            Strike      = strike;
            Right       = EnumDescConverter.GetEnumDescription(right);
            Multiplier  = "100";
            Exchange    = "SMART";
            Currency    = "USD";
            LocalSymbol = optionSymbol;
            PrimaryExch = "SMART";
            SecIdType   = EnumDescConverter.GetEnumDescription(SecurityIdType.None);
            SecId       = string.Empty;

            var ExpirationString = new StringBuilder();
            ExpirationString.AppendFormat("{0:0000}{1:00}", year, month);
            Expiry = ExpirationString.ToString();
        }
Exemple #36
0
        public DataPermission CreateDataPermission(long subjectId, long entityId, long dataId, RightType rightType, PermissionType permissionType = PermissionType.Grant)
        {
            DataPermission dataPermission = new DataPermission()
            {
                Subject = SubjectsRepo.Get(subjectId),
                Entity = EntitiesRepo.Get(entityId),
                DataId = dataId,
                RightType = rightType,
                PermissionType = permissionType
            };

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<DataPermission> featuresRepo = uow.GetRepository<DataPermission>();
                featuresRepo.Put(dataPermission);

                uow.Commit();
            }

            return (dataPermission);
        }
Exemple #37
0
 public Right(RightType rightType, string administrativeDivisionId, string initiativeId)
 {
     RightType = rightType;
     AdministrativeDivisionId = administrativeDivisionId;
     InitiativeId = initiativeId;
 }
Exemple #38
0
        public bool HasRight(RightType rightType, string administrativeDivisionId, string initiativeId)
        {
            var hasRightByRightType = RightType == rightType;

            var hasRightByAdministrativeDivision = false;
            var currentAdministrativeDivisionId = administrativeDivisionId;
            do
            {
                if (currentAdministrativeDivisionId == AdministrativeDivisionId)
                {
                    hasRightByAdministrativeDivision = true;
                    break;
                }

                var administrativeDivision = _administrativeDivisionProvider.GetAdministrativeDivision(currentAdministrativeDivisionId);

                currentAdministrativeDivisionId = administrativeDivision.ParentId;
            } while (currentAdministrativeDivisionId != null);

            var hasRightByInitiative = (InitiativeId == initiativeId) || (InitiativeId == null);
            
            var hasRight = hasRightByRightType && hasRightByAdministrativeDivision && hasRightByInitiative;

            return hasRight;
        }
Exemple #39
0
 protected bool HasRight(RightType rightType)
 {
     return SecurityUser.HasRight(rightType);
 }
Exemple #40
0
        public bool HasUserDataAccess(long userId, long entityId, long dataId, RightType rightType)
        {
            User user = UsersRepo.Get(userId);

            List<long> subjectIds = new List<long>(user.Groups.Select(g => g.Id));
            subjectIds.Add(user.Id);

            return ExistsDataPermission(subjectIds, entityId, dataId, rightType);
        }
Exemple #41
0
 public static OptionType? RightTypeToOptionType(RightType right)
 {
     if (right == RightType.Undefined) return null;
     if (right == RightType.Call) return OptionType.Call;
     return OptionType.Put;
 }
Exemple #42
0
 public bool HasRight(RightType rightType, Initiative initiative)
 {
     return HasRight(rightType, AdministrativeDivision.RootAdministrativeDivisionId, initiative.Id);
 }
Exemple #43
0
 /// <summary>
 /// Creates an Option Contract
 /// </summary>
 /// <param name="equitySymbol">Symbol of the equity. See <see cref="Contract.Symbol"/>.</param>
 /// <param name="optionSymbol">Symbol of the option for the underlying equity. See <see cref="Contract.LocalSymbol"/>.</param>
 /// <param name="expiry">Option Expiration String. See <see cref="Contract.Expiry"/>.</param>
 /// <param name="right">Option Right (Put or Call). See <see cref="Contract.Right"/>.</param>
 /// <param name="strike">Option Strike Price. See <see cref="Contract.Strike"/>.</param>
 public Option(string equitySymbol, string optionSymbol, string expiry,
 RightType right, decimal strike)
     : base(0, equitySymbol, SecurityType.Option, expiry, (double)strike,
 right, "100", "SMART", "USD", optionSymbol, "SMART", SecurityIdType.None, string.Empty)
 {
 }
Exemple #44
0
 public ActionType(RightType ActionType, string ParentAction="")
 {
     this.RightType = ActionType;
      this.ParentAction = ParentAction;
 }
Exemple #45
0
        public bool HasUserDataAccess(string username, long entityId, long dataId, RightType rightType)
        {
            Group everyone = GroupsRepo.Get(g => g.Name == "everyone").FirstOrDefault();

            if (ExistsDataPermission(everyone.Id, entityId, dataId, rightType))
            {
                return true;
            }
            else
            {
                User user = UsersRepo.Get(u => u.Name.ToLower() == username.ToLower()).FirstOrDefault();

                if (user == null)
                {
                    return false;
                }
                else
                {
                    List<long> subjectIds = new List<long>(user.Groups.Select(g => g.Id));
                    subjectIds.Add(user.Id);

                    return ExistsDataPermission(subjectIds, entityId, dataId, rightType);
                }
            }
        }
 /// <summary>
 /// Sets the control.
 /// </summary>
 /// <param name="control">The control.</param>
 /// <param name="rightType">Type of the right.</param>
 private static void SetControl(System.Windows.Forms.Control control, RightType rightType)
 {
     switch (rightType)
     {
         case RightType.Enable:
             control.Visible = true;
             control.Enabled = true;
             break;
         case RightType.Disable:
             control.Visible = true;
             control.Enabled = false;
             break;
         case RightType.Visible:
             control.Visible = true;
             break;
         case RightType.Hidden:
             control.Visible = false;
             break;
         default:
             control.Enabled = true;
             control.Visible = true;
             break;
     }
 }
Exemple #47
0
 public bool HasRight(RightType rightType)
 {
     return HasRight(rightType, AdministrativeDivision.RootAdministrativeDivisionId, null);
 }
Exemple #48
0
 public bool HasRight(RightType rightType, string administrativeDivisionId, string initiativeId)
 {
     return Rights.Any(right => right.HasRight(rightType, administrativeDivisionId, initiativeId));
 }
Exemple #49
0
 public bool HasRight(RightType rightType, AdministrativeDivision administrativeDivision)
 {
     return HasRight(rightType, administrativeDivision.Id, null);
 }
Exemple #50
0
 public IQueryable<long> GetAllDataIds(IEnumerable<long> subjectIds, long entityId, RightType rightType)
 {
     return DataPermissionsRepo.Query(p => p.Entity.Id == entityId && subjectIds.Contains(p.Subject.Id) && p.RightType == rightType).Select(p => p.DataId);
 }
Exemple #51
0
        public bool DeleteDataPermission(long subjectId, long entityId, long dataId, RightType rightType)
        {
            DataPermission dataPermission = GetDataPermission(subjectId, entityId, dataId, rightType);

            if (dataPermission != null)
            {
                using (IUnitOfWork uow = this.GetUnitOfWork())
                {
                    IRepository<DataPermission> dataPermissionsRepo = uow.GetRepository<DataPermission>();

                    dataPermissionsRepo.Delete(dataPermission);
                    uow.Commit();
                }

                return (true);
            }

            return (false);
        }
Exemple #52
0
 public DataPermission GetDataPermission(long subjectId, long entityId, long dataId, RightType rightType)
 {
     return DataPermissionsRepo.Get(p => p.Subject.Id == subjectId && p.Entity.Id == entityId && p.DataId == dataId && p.RightType == rightType).FirstOrDefault();
 }
Exemple #53
0
 public bool ExistsDataPermission(long subjectId, long entityId, long dataId, RightType rightType)
 {
     if (DataPermissionsRepo.Get(p => p.Subject.Id == subjectId && p.Entity.Id == entityId && p.DataId == dataId && p.RightType == rightType).Count() == 1)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Exemple #54
0
 /// <summary>
 /// Creates an Option Contract
 /// </summary>
 /// <param name="symbol">This is the symbol of the underlying asset.</param>
 /// <param name="exchange">The order destination, such as Smart.</param>
 /// <param name="securityType">This is the security type.</param>
 /// <param name="currency">Specifies the currency.</param>
 /// <param name="expiry">The expiration date. Use the format YYYYMM.</param>
 /// <param name="strike">The strike price.</param>
 /// <param name="right">Specifies a Put or Call.</param>
 public Option(string symbol, string exchange, SecurityType securityType, string currency, string expiry, double strike, RightType right) :
     base(0, symbol, securityType, expiry, strike, right, null, exchange, currency, null, null, SecurityIdType.None, string.Empty)
 {
 }
Exemple #55
0
 public bool ExistsDataPermission(IEnumerable<long> subjectIds, long entityId, long dataId, RightType rightType)
 {
     if (DataPermissionsRepo.Query(p => subjectIds.Contains(p.Subject.Id) && p.Entity.Id == entityId && p.DataId == dataId && p.RightType == rightType).Count() > 0)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Exemple #56
0
        public IQueryable<long> GetAllDataIds(long userId, long entityId, RightType rightType)
        {
            User user = UsersRepo.Get(userId);

            List<long> subjectIds = new List<long>(user.Groups.Select(g => g.Id));
            subjectIds.Add(user.Id);

            return GetAllDataIds(subjectIds, entityId, rightType);
        }
Exemple #57
0
        /// <summary>
        /// Default Contract Constructor
        /// </summary>
        /// <param name="contractId">The unique contract identifier.</param>
        /// <param name="symbol">This is the symbol of the underlying asset.</param>
        /// <param name="securityType">This is the security type.</param>
        /// <param name="expiry">The expiration date. Use the format YYYYMM.</param>
        /// <param name="strike">The strike price.</param>
        /// <param name="right">Specifies a Put or Call.</param>
        /// <param name="multiplier">Allows you to specify a future or option contract multiplier.
        /// This is only necessary when multiple possibilities exist.</param>
        /// <param name="exchange">The order destination, such as Smart.</param>
        /// <param name="currency">Specifies the currency.</param>
        /// <param name="localSymbol">This is the local exchange symbol of the underlying asset.</param>
        /// <param name="primaryExchange">Identifies the listing exchange for the contract (do not list SMART).</param>
        public Contract(int contractId, String symbol, SecurityType securityType, String expiry, double strike, RightType right,
                        String multiplier, string exchange, string currency, string localSymbol, string primaryExchange)
        {
            this.contractId = contractId;
            this.symbol = symbol;
            this.securityType = securityType;
            this.expiry = expiry;
            this.strike = strike;
            this.right = right;
            this.multiplier = multiplier;
            this.exchange = exchange;

            this.currency = currency;
            this.localSymbol = localSymbol;
            this.primaryExchange = primaryExchange;
        }
Exemple #58
0
        /// <summary>
        /// Get new right by right type
        /// </summary>
        /// <returns>Right</returns>
        public Right Get(RightType rightType)
        {
#pragma warning disable 618
            return Get<Right>(r => string.Compare(r.SystemName, rightType.ToString(), true) == 0).FirstOrDefault();
#pragma warning restore 618
        }