Beispiel #1
0
 public void Add(PermissionTypeEnum permissionType)
 {
     if (!Permissions.Contains(permissionType))
     {
         Permissions.Add(permissionType);
     }
 }
Beispiel #2
0
        private IList <Permission> GetSpecialPermissionsList(PermissionTypeEnum pEnmPermissionType, long pLonPermissionId)
        {
            List <Permission> lLstObjPermissions = (
                pEnmPermissionType == PermissionTypeEnum.USER_TYPE ?
                mObjSecurityServiceFactory.GetPermissionService().GetUserTypePermissions(pLonPermissionId) :
                mObjSecurityServiceFactory.GetPermissionService().GetUserPermissions(pLonPermissionId)
                ).Where(x => x.AccessType == AccessTypeEnum.SPECIAL_FUNCTION).ToList();

            foreach (SpecialFunctionDTO lObjFunction in mLstObjSpecialPermissions)
            {
                //Update if exists in the permissions list
                if (lLstObjPermissions.Where(x => x.AccessId == lObjFunction.Id).Count() > 0)
                {
                    foreach (Permission lObjPermission in lLstObjPermissions.Where(x => x.AccessId == lObjFunction.Id))
                    {
                        lObjPermission.AllowAccess = lObjFunction.Active;
                    }
                }
                //Add if is new and allow access
                else
                {
                    lLstObjPermissions.Add(new Permission()
                    {
                        PermissionType = pEnmPermissionType,
                        AccessType     = AccessTypeEnum.SPECIAL_FUNCTION,
                        AllowAccess    = lObjFunction.Active,
                        PermissionId   = mLonPermissionId,
                        AccessId       = lObjFunction.Id,
                    });
                }
            }

            return(lLstObjPermissions);
        }
        public bool EditPermission(long id, string key, PermissionTypeEnum permissionType)
        {
            bool       flag       = false;
            Permission permission = new Permission
            {
                Id  = id,
                Key = key,
                PermissionTypeId = permissionType
            };

            using (var db = new TimeTrackerModelContainer())
            {
                var result = db.Permission.First(x => x.Id == id);
                var s      = db.Set <Permission>().Local.FirstOrDefault(x => x.Id == id);

                if (s != null)
                {
                    db.Entry(s).State = EntityState.Detached;
                }

                if (result.Id == id)
                {
                    db.Entry(permission).State = EntityState.Modified;

                    db.SaveChanges();

                    flag = true;
                }
            }

            return(flag);
        }
Beispiel #4
0
        private IList <Permission> GetMenuPermissionsList(PermissionTypeEnum pEnmPermissionType, long pLonPermissionId)
        {
            List <Permission> lLstObjPermissions = (
                pEnmPermissionType == PermissionTypeEnum.USER_TYPE ?
                mObjSecurityServiceFactory.GetPermissionService().GetUserTypePermissions(pLonPermissionId) :
                mObjSecurityServiceFactory.GetPermissionService().GetUserPermissions(pLonPermissionId)
                ).Where(x => x.AccessType == AccessTypeEnum.MODULE && x.AccessType == AccessTypeEnum.SECTION).ToList();

            foreach (ModuleDTO lObjModule in mLstObjModulesPermissions)
            {
                //Update if exists in the permissions list
                if (lLstObjPermissions.Where(x => x.AccessType == AccessTypeEnum.MODULE && x.AccessId == lObjModule.Id).Count() > 0)
                {
                    foreach (Permission lObjPermission in lLstObjPermissions.Where(x => x.AccessType == AccessTypeEnum.MODULE && x.AccessId == lObjModule.Id))
                    {
                        lObjPermission.AllowAccess = lObjModule.Active;
                    }
                }
                //Add if is new and allow access
                else
                {
                    lLstObjPermissions.Add(new Permission()
                    {
                        PermissionType = pEnmPermissionType,
                        AccessType     = AccessTypeEnum.MODULE,
                        AllowAccess    = lObjModule.Active,
                        PermissionId   = mLonPermissionId,
                        AccessId       = lObjModule.Id,
                    });
                }

                //For each section in the module
                foreach (SectionDTO lObjSection in lObjModule.Sections)
                {
                    //Update if exists in the permissions list
                    if (lLstObjPermissions.Where(x => x.AccessType == AccessTypeEnum.SECTION && x.AccessId == lObjSection.Id).Count() > 0)
                    {
                        foreach (Permission lObjPermission in lLstObjPermissions.Where(x => x.AccessType == AccessTypeEnum.SECTION && x.AccessId == lObjSection.Id))
                        {
                            lObjPermission.AllowAccess = lObjSection.Active;
                        }
                    }
                    //Add if is new and allow access
                    else
                    {
                        lLstObjPermissions.Add(new Permission()
                        {
                            PermissionType = pEnmPermissionType,
                            AccessType     = AccessTypeEnum.SECTION,
                            AllowAccess    = lObjSection.Active,
                            PermissionId   = mLonPermissionId,
                            AccessId       = lObjSection.Id,
                        });
                    }
                }
            }

            return(lLstObjPermissions);
        }
Beispiel #5
0
        public List <int> GetPermissionList(long objectId, PermissionTypeEnum type)
        {
            var query = from defaults in this.Permissions
                        where defaults.PermissionTypeId == type && defaults.ObjectId == objectId
                        select defaults.ReferenceId;

            return(query.ToList());
        }
Beispiel #6
0
 public CreateCommandModel(Guid gid, string permissionname, PermissionTypeEnum permissiontype, string permissionaction, string permissionparentid, bool isvalid)
 {
     this.PermissionId       = gid;
     this.PermissionName     = permissionname;
     this.PermissionType     = permissiontype;
     this.PermissionAction   = permissionaction;
     this.PermissionParentId = permissionparentid;
     this.IsValid            = isvalid;
 }
Beispiel #7
0
        public UCPermissionDialog(PermissionTypeEnum pEnmPermissionType, string pStrPermission, long pLonPermissionId)
        {
            mObjSecurityServiceFactory = new SecurityServicesFactory();
            mObjSystemServiceFactory   = new SystemServicesFactory();

            mEnmPermissionType = pEnmPermissionType;
            mStrPermissionType = pEnmPermissionType.GetDescription();
            mLonPermissionId   = pLonPermissionId;

            InitializeComponent();
            lblPermission.Content = pStrPermission;
        }
Beispiel #8
0
        public List <SpecialFunctionDTO> GetSpecialPermissions(PermissionTypeEnum pEnmPermissionType, long pLonPermissionId)
        {
            List <SpecialFunctionDTO> lLstObjList        = new List <SpecialFunctionDTO>();
            List <Permission>         lLstObjPermissions = pEnmPermissionType == PermissionTypeEnum.USER_TYPE ?
                                                           mObjSecurityServiceFactory.GetPermissionService().GetUserTypePermissions(pLonPermissionId).ToList() :
                                                           mObjSecurityServiceFactory.GetPermissionService().GetUserPermissions(pLonPermissionId).ToList();

            foreach (EnumItem lObjItem in EnumExtension.GetEnumItemList <SpecialFunctionsEnum>())
            {
                lLstObjList.Add(new SpecialFunctionDTO(lObjItem)
                {
                    Active = lLstObjPermissions.Where(x => x.AccessType == AccessTypeEnum.SPECIAL_FUNCTION && (int)x.AccessId == lObjItem.Value).Count() > 0
                });
            }

            return(lLstObjList);
        }
Beispiel #9
0
 private void SaveChanges(PermissionTypeEnum pEnmPermissionType, long pLonPermissionId)
 {
     FormLoading();
     try
     {
         this.mObjSecurityServiceFactory.GetPermissionService().SaveOrUpdateSystemPermissions(pEnmPermissionType, GetMenuPermissionsList(pEnmPermissionType, pLonPermissionId));
         this.mObjSecurityServiceFactory.GetPermissionService().SaveOrUpdateSpecialPermissions(pEnmPermissionType, GetSpecialPermissionsList(pEnmPermissionType, pLonPermissionId));
         this.Dispatcher.Invoke(() => CustomMessageBox.Show("Permisos", "Los cambios se han guardado correctamente", this.GetParent()));
     }
     catch (Exception lObjException)
     {
         this.Dispatcher.Invoke(() => CustomMessageBox.Show("Error", lObjException.Message, this.GetParent()));
     }
     finally
     {
         FormDefault();
     }
 }
Beispiel #10
0
        public void SaveOrUpdateSpecialPermissions(PermissionTypeEnum pEnmTypePermission, IList <Permission> pLstObjPermissions)
        {
            if (pLstObjPermissions != null && pLstObjPermissions.Count > 0)
            {
                //Get permissions to update
                IList <Permission> lLstObjPermissionsToSaveOrUpdate = (from Current in mObjPermissionDAO.GetEntitiesList().Where(p => p.PermissionType == pEnmTypePermission &&
                                                                                                                                 p.AccessType == AccessTypeEnum.SPECIAL_FUNCTION).ToList()
                                                                       join New in pLstObjPermissions on Current.Id equals New.Id
                                                                       where Current.AllowAccess != New.AllowAccess
                                                                       select Current).Select(x => { x.AllowAccess = !x.AllowAccess; return(x); }).ToList();

                //Get permissions to add
                lLstObjPermissionsToSaveOrUpdate = lLstObjPermissionsToSaveOrUpdate.Concat(pLstObjPermissions.Where(x => x.Id == 0)).ToList();

                //Save changes
                mObjPermissionDAO.SaveOrUpdateEntitiesList(lLstObjPermissionsToSaveOrUpdate);
            }
        }
        public async Task <PermissionDto> AddPermission(long id, string key, PermissionTypeEnum permissionType)
        {
            string uri     = "api/permission/addpermission";
            var    request = new PermissionRequest
            {
                Id  = id,
                Key = key,
                PermissionTypeId = permissionType
            };

            var addPermissionToDb = await httpServices.Post <PermissionDto, PermissionRequest>(uri, request);

            if (addPermissionToDb == null)
            {
                throw new Exception("Save the new permission did not successful!");
            }

            return(addPermissionToDb);
        }
Beispiel #12
0
        private static string getWhereSql(Guid userID, string tableName, PermissionTypeEnum permissionType)
        {
            if (isAdmin(userID))
            {
                return(AllWhere);
            }
            var tableRightDic = getTableRight(userID);

            if (tableRightDic == null)
            {
                return(NoneWhere);
            }
            var rightDic = new SysUserTableRight(userID, tableName, permissionType);

            if (tableRightDic.TryGetValue(rightDic.getKey(), out rightDic))
            {
                return(rightDic.getWhereSql());
            }
            return(NoneWhere);
        }
        public async Task <bool> EditPermission(long id, string key, PermissionTypeEnum permissionType)
        {
            string uri = "api/permission/editpermission";

            var request = new PermissionRequest
            {
                Id  = id,
                Key = key,
                PermissionTypeId = permissionType
            };

            var editPermissiontoDb = await httpServices.Put(uri, request);

            if (editPermissiontoDb == false)
            {
                throw new Exception("The permission edit did not successful!");
            }

            return(editPermissiontoDb);
        }
Beispiel #14
0
        public List <ModuleDTO> GetMenuPermissions(PermissionTypeEnum pEnmPermissionType, long pLonPermissionId)
        {
            IList <Module> lLstObjModules = mObjSystemServiceFactory.GetModuleService().GetList().Where(x => x.Active == true).ToList();

            IList <Permission> lLstObjPermissions = pEnmPermissionType == PermissionTypeEnum.USER_TYPE ?
                                                    mObjSecurityServiceFactory.GetPermissionService().GetUserTypePermissions(pLonPermissionId) :
                                                    mObjSecurityServiceFactory.GetPermissionService().GetUserPermissions(pLonPermissionId);

            foreach (Module lObjModule in lLstObjModules)
            {
                //Is active if exists on permissions list and allow it access
                lObjModule.Active = lLstObjPermissions.Where(x => x.AccessType == AccessTypeEnum.MODULE && x.AccessId == lObjModule.Id && x.AllowAccess).Count() > 0;

                //For each section in the module
                foreach (UGRS.Core.Auctions.Entities.System.Section lObjSection in lObjModule.Sections)
                {
                    //Is active if exists on permissions list and allow it access
                    lObjSection.Active = lLstObjPermissions.Where(x => x.AccessType == AccessTypeEnum.MODULE && x.AccessId == lObjModule.Id && x.AllowAccess).Count() > 0;
                }
            }

            return(lLstObjModules.Select(x => new ModuleDTO(x)).ToList());
        }
Beispiel #15
0
        private EntityEnum GetEntityReferenceByPermissionType(PermissionTypeEnum type)
        {
            switch (type)
            {
            case PermissionTypeEnum.Brand:
                return(EntityEnum.Brand);

            case PermissionTypeEnum.CityArea:
                return(EntityEnum.CityArea);

            case PermissionTypeEnum.ProductFamily:
                return(EntityEnum.ProductFamily);

            case PermissionTypeEnum.SystemAccess:
                return(EntityEnum.SystemAccess);

            case PermissionTypeEnum.Tool:
                return(EntityEnum.Tool);

            default:
                return(EntityEnum.Unknown);
            }
        }
Beispiel #16
0
 /// <summary>
 /// Get if the permission is set, the address of the device.
 /// </summary>
 /// <param name="permissionType"></param>
 /// <returns></returns>
 public AddressRequestResult GetAddress(PermissionTypeEnum permissionType)
 {
     return(GetAddressAsync(permissionType).Result);
 }
Beispiel #17
0
        public long AddPermission(long?parentPermissionId, EntityEnum objectEntityType, long objectId, EntityEnum?entityReferenceType, int referenceId, PermissionTypeEnum type)
        {
            var newPermissionId = this.Context.GenerateNextLongId();

            this.Context.Permissions.Add(new Permission
            {
                PermissionId       = newPermissionId,
                ParentPermissionId = parentPermissionId,
                ObjectEntityId     = objectEntityType,
                ObjectId           = objectId,
                PermissionTypeId   = type,
                ReferenceEntityId  = entityReferenceType,
                ReferenceId        = referenceId
            });

            return(newPermissionId);
        }
Beispiel #18
0
        public void UpdatePermissionAudit(EntityEnum UserType,
                                          User entity,
                                          List <Permission> permissionList,
                                          PermissionTypeEnum type,
                                          UserSessionModel admin,
                                          List <Permission> dbSelection
                                          )
        {
            var removeList = dbSelection.Where(dbs => !permissionList.Any(ns => ns.ReferenceId == dbs.ReferenceId)).ToList();
            var addList    = permissionList.Where(ns => !dbSelection.Any(dbs => dbs.ReferenceId == ns.ReferenceId)).ToList();

            foreach (var item in removeList)
            {
                PermissionAudit permissionAuditModel = new PermissionAudit();
                permissionAuditModel.EffectedUserId     = entity.UserId;
                permissionAuditModel.EffectedUserTypeId = (int)entity.UserTypeId;
                permissionAuditModel.ModifyByUserId     = admin.UserId;
                permissionAuditModel.ModifyByUserTypeId = (int)admin.UserTypeId;
                permissionAuditModel.ModifyDate         = DateTime.Now;
                permissionAuditModel.ObjectEntityId     = (int)UserType;
                permissionAuditModel.ObjectId           = entity.UserId;
                permissionAuditModel.ReferenceId        = item.ReferenceId;
                permissionAuditModel.ReferenceEntityId  = (int)item.ReferenceEntityId.Value;
                permissionAuditModel.PermissionTypeId   = (byte)item.PermissionTypeId;
                permissionAuditModel.PermissionId       = item.PermissionId;
                permissionAuditModel.ParentPermissionId = item.ParentPermissionId;
                permissionAuditModel.TypeOfAction       = "Removed";
                permissionAuditModel.BusinessId         = entity.BusinessId.Value;

                this.Context.PermissionAudits.Add(permissionAuditModel);
            }

            foreach (var item in addList)
            {
                var Id = this.Context.Permissions
                         .Where(p => p.ObjectId == entity.UserId &&
                                p.PermissionTypeId == PermissionTypeEnum.SystemAccess &&
                                p.ReferenceId == item.ReferenceId
                                ).Select(P => P.PermissionId).FirstOrDefault();

                PermissionAudit permissionAuditModel = new PermissionAudit();
                permissionAuditModel.EffectedUserId     = entity.UserId;
                permissionAuditModel.EffectedUserTypeId = (int)entity.UserTypeId;
                permissionAuditModel.ModifyByUserId     = admin.UserId;
                permissionAuditModel.ModifyByUserTypeId = (int)admin.UserTypeId;
                permissionAuditModel.ModifyDate         = DateTime.Now;
                permissionAuditModel.ObjectEntityId     = (int)entity.UserTypeId;
                permissionAuditModel.ObjectId           = entity.UserId;
                permissionAuditModel.ReferenceId        = item.ReferenceId;
                permissionAuditModel.ReferenceEntityId  = (int)item.ReferenceEntityId;
                permissionAuditModel.PermissionTypeId   = (byte)type;
                permissionAuditModel.BusinessId         = entity.BusinessId.Value;

                var parentPermissionId = this.Context.Permissions
                                         .Where(p => p.PermissionId == Id)
                                         .Select(p => p.ParentPermissionId).FirstOrDefault();

                permissionAuditModel.PermissionId = Id;

                if (parentPermissionId == null)
                {
                    parentPermissionId = this.Context.Permissions
                                         .Where(p => p.ObjectId == entity.UserId &&
                                                p.ParentPermissionId != null
                                                ).OrderByDescending(p => p.PermissionId)
                                         .Select(p => p.ParentPermissionId).FirstOrDefault();
                }

                permissionAuditModel.ParentPermissionId = parentPermissionId;

                permissionAuditModel.TypeOfAction = "Added";

                this.Context.PermissionAudits.Add(permissionAuditModel);
            }

            this.Context.SaveChanges();
        }
Beispiel #19
0
        public List <long> PermissionsUpdate(EntityEnum parentObjectEntity, long?parentObjectId, EntityEnum objectEntity, long?objectId, List <PermissionListModel> permissionList, PermissionTypeEnum type)
        {
            if (objectId == null || default(long) == objectId || permissionList == null)
            {
                return(null);
            }

            var dbSelection = this.Context.Permissions.Where(p => p.ObjectId == objectId && p.PermissionTypeId == type).Select(r => r).ToList();

            var dbSelectionIds = dbSelection.Select(p =>
                                                    new
            {
                p.ReferenceId,
                p.ReferenceEntityId
            }).ToList();

            var newSelection = permissionList.Where(s => s.IsSelected).Select(i => new
            {
                i.ReferenceId,
                i.ReferenceEntityId
            }).ToList();

            // Remove any permissions not selected and in permissions table.
            dbSelection.ForEach(p =>
            {
                if (newSelection.Any(w => w.ReferenceId == p.ReferenceId) == false)
                {
                    var list = this.Context.FnGetPermissionsUnderPermissionId(p.PermissionId).ToList();
                    list.ForEach(p1 => this.Context.Permissions.Remove(p1));
                }
            });

            List <long> newPermissionId = new List <long>();

            // Add any permissions selected but not in permissions table
            newSelection.ForEach(p =>
            {
                if (dbSelectionIds.Any(w => w.ReferenceId == p.ReferenceId) == false)
                {
                    newPermissionId.Add(this.AddPermission(parentObjectId, objectEntity, objectId.Value, p.ReferenceEntityId, p.ReferenceId, type));
                }
            });


            return(newPermissionId);
        }
Beispiel #20
0
        /// <summary>
        /// Returns the list of permissions for a given permission type
        /// </summary>
        /// <param name="defaultId">The id of the default list</param>
        /// <param name="selectedId">The id of the selected list</param>
        /// <param name="permissionType">The permission type</param>
        /// <returns></returns>
        ///
        public List <PermissionListModel> GetPermissionResultListModel(long defaultId, long selectedId, PermissionTypeEnum permissionType, long?userId)
        {
            IQueryable <PermissionListModel> results = null;

            // get the default permissions and mark any as active if the active list contains identical records
            var query = (from defaults in this.Permissions
                         where defaults.PermissionTypeId == permissionType && defaults.ObjectId == defaultId

                         join selected in this.Permissions on new { a = selectedId, b = permissionType, c = defaults.ReferenceId } equals
                         new { a = selected.ObjectId, b = selected.PermissionTypeId, c = selected.ReferenceId } into Lca
                         from selected in Lca.DefaultIfEmpty()

                         select new { ReferenceId = defaults.ReferenceId, isActive = selected != null })

                        .Distinct();

            switch (permissionType)
            {
            case PermissionTypeEnum.CityArea:
                results = from perm in query
                          join reference in this.CityAreas on perm.ReferenceId equals reference.CityAreaId
                          select new PermissionListModel
                {
                    ReferenceId = perm.ReferenceId,
                    Description = reference.Name,
                    IsSelected  = perm.isActive
                };
                break;

            case PermissionTypeEnum.Brand:
                results = from perm in query
                          join reference in this.Brands on perm.ReferenceId equals reference.BrandId
                          select new PermissionListModel
                {
                    ReferenceId = perm.ReferenceId,
                    Description = reference.Name,
                    IsSelected  = perm.isActive
                };
                break;

            case PermissionTypeEnum.ProductFamily:
                results = from perm in query
                          join reference in this.ProductFamilies on perm.ReferenceId equals reference.ProductFamilyId
                          select new PermissionListModel
                {
                    ReferenceId = perm.ReferenceId,
                    Description = reference.Name,
                    IsSelected  = perm.isActive
                };
                break;

            case PermissionTypeEnum.Tool:
                results = from perm in query
                          join reference in this.Tools on perm.ReferenceId equals reference.ToolId
                          select new PermissionListModel
                {
                    ReferenceId = perm.ReferenceId,
                    Description = reference.Name,
                    IsSelected  = perm.isActive
                };
                break;

            case PermissionTypeEnum.SystemAccess:
                results = from perm in query
                          join reference in this.SystemAccesses on perm.ReferenceId equals reference.SystemAccessId
                          select new PermissionListModel
                {
                    ReferenceId = perm.ReferenceId,
                    Description = reference.Name,
                    IsSelected  = perm.isActive
                };
                break;
            }

            IQueryable <PermissionListModel> newResults = null;

            if (userId == null)
            {
                userId = selectedId;
            }

            if (permissionType == PermissionTypeEnum.ProductFamily)
            {
                var newQuery = (from defaults in this.Context.Permissions
                                where defaults.PermissionTypeId == permissionType && defaults.ObjectId == userId
                                select new
                {
                    ReferenceId = defaults.ReferenceId,
                    isActive = defaults != null
                }).Distinct();

                newResults = from q in newQuery
                             join reference in this.ProductFamilies on
                             q.ReferenceId equals reference.ProductFamilyId
                             select new PermissionListModel
                {
                    ReferenceId = q.ReferenceId,
                    Description = reference.Name,
                    IsSelected  = q.isActive
                };
            }

            List <PermissionListModel> values = new List <PermissionListModel>();

            values = results.ToList().OrderBy(o => o.ReferenceId).ToList();

            if (newResults != null)
            {
                foreach (var item in newResults)
                {
                    if (results.Where(r => r.ReferenceId == item.ReferenceId).Count() < 1)
                    {
                        values.Add(item);
                    }
                }
            }

            //return results.ToList().OrderBy(o => o.ReferenceId).ToList();
            return(values);
        }
Beispiel #21
0
 public void Remove(PermissionTypeEnum permissionType)
 {
     Permissions.Remove(permissionType);
 }
Beispiel #22
0
        public List <PermissionListModel> GetPermissonsForUserType(UserSessionModel currentUser, long businessId, UserTypeEnum?userType, PermissionTypeEnum permissonType, bool isEditing = false)
        {
            long defaultPermissionListId = default(long);

            if (!userType.HasValue)
            {
                return(new List <PermissionListModel>());
            }

            switch (permissonType)
            {
            case PermissionTypeEnum.Brand:
            case PermissionTypeEnum.CityArea:
            case PermissionTypeEnum.ProductFamily:
                defaultPermissionListId = (long)businessId;
                break;

            case PermissionTypeEnum.SystemAccess:
            case PermissionTypeEnum.Tool:
                defaultPermissionListId = currentUser.UserId;
                break;
            }

            return(this.Db.GetPermissionResultListModel(defaultPermissionListId, (long)userType, permissonType, null));
        }
Beispiel #23
0
        public async Task <AddressRequestResult> GetAddressAsync(PermissionTypeEnum permissionType)
        {
            if (string.IsNullOrEmpty(RequestEnvelope?.Context?.System?.Device?.DeviceId))
            {
                return(new AddressRequestResult(GetAdressResultEnum.Error_NoDeviceId));
            }

            if (string.IsNullOrEmpty(RequestEnvelope.Context.System.User.Permissions.ConsentToken))
            {
                return(new AddressRequestResult(GetAdressResultEnum.Error_NoConsentToken));
            }


            string _Url;

            switch (permissionType)
            {
            case PermissionTypeEnum.FullAddress:
                _Url = $"/v1/devices/{RequestEnvelope.Context.System.Device.DeviceId}/settings/address";
                break;

            case PermissionTypeEnum.CountryAndPostalCode:
                _Url = $"/v1/devices/{RequestEnvelope.Context.System.Device.DeviceId}/settings/address/countryAndPostalCode";
                break;

            default:
                return(new AddressRequestResult(GetAdressResultEnum.Error_RequestNotSupported));
            }

            var f = new System.Net.Http.HttpClient();

            f.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + RequestEnvelope.Context.System.User.Permissions.ConsentToken);

            try
            {
                var response = await f.GetAsync(RequestEnvelope.Context.System.ApiEndpoint + _Url).ConfigureAwait(false);

                switch (response.StatusCode)
                {
                case HttpStatusCode.NoContent:
                    return(new AddressRequestResult(GetAdressResultEnum.Error_NoContent));

                case HttpStatusCode.MethodNotAllowed:
                    return(new AddressRequestResult(GetAdressResultEnum.Error_Unkown));

                case HttpStatusCode.Forbidden:
                    return(new AddressRequestResult(GetAdressResultEnum.Error_Forbidden));

                case (HttpStatusCode)429:     // Too Many Requests
                    return(new AddressRequestResult(GetAdressResultEnum.Error_Too_Many_Requests));

                case HttpStatusCode.InternalServerError:
                    return(new AddressRequestResult(GetAdressResultEnum.Error_Unkown));

                case HttpStatusCode.OK:
                    break;

                default:
                    return(new AddressRequestResult(GetAdressResultEnum.Error_Unkown));
                }

                var address = Newtonsoft.Json.JsonConvert.DeserializeObject <User_Address>(
                    await response.Content.ReadAsStringAsync().ConfigureAwait(false),
                    Sdk.DeserializationSettings);

                return(new AddressRequestResult(GetAdressResultEnum.OK, address));
            }
            catch (Exception)
            {
                return(new AddressRequestResult(GetAdressResultEnum.Error_Unkown));
            }
        }
Beispiel #24
0
        public CheckBoxListModel CheckBoxListModelUserPermissions(UserSessionModel admin, long businessId, UserTypeEnum?userTypeId, CheckBoxListModel model, PermissionTypeEnum type, bool isEditing = false)
        {
            var permissionService = new PermissionServices(this.Context);

            // Return default permissions with selected items
            var permissions = permissionService.GetPermissonsForUserType(admin, businessId, userTypeId, type, isEditing);

            var result = GetCheckBoxListModel(admin, permissions, model);

            result.EntityReferenceId = GetEntityReferenceByPermissionType(type);

            return(result);
        }
Beispiel #25
0
 private int CountPermUser(UserSessionModel user, PermissionTypeEnum type)
 {
     return(db.Permissions.Where(p => p.ObjectId == user.UserId && p.PermissionTypeId == type).Count());
 }
Beispiel #26
0
        public List <PermissionListModel> GetPermissonsForBusiness(UserSessionModel currentUser, long businessId, PermissionTypeEnum permissonType)
        {
            long defaultPermissionListId = 0;
            List <PermissionListModel> permissionListModel = new List <PermissionListModel>();

            if (currentUser != null)
            {
                if (currentUser.UserTypeId == UserTypeEnum.DaikinSuperUser)
                {
                    defaultPermissionListId = (long)BusinessTypeEnum.Daikin;
                }
                else
                {
                    defaultPermissionListId = (long)this.Db.BusinessQueryByBusinessId(currentUser, businessId)
                                              .Select(g => g.BusinessTypeId)
                                              .FirstOrDefault();
                }

                permissionListModel = this.Db.GetPermissionResultListModel(defaultPermissionListId, businessId, permissonType, currentUser.UserId);
            }
            else
            {
                permissionListModel = this.Db.GetPermissionResultListModel(defaultPermissionListId, businessId, permissonType, null);
            }

            return(permissionListModel);
        }
Beispiel #27
0
        public List <PermissionListModel> GetPermissonsForUser(UserSessionModel currentUser, long userBeingEditedId, PermissionTypeEnum permissonType, bool isEditing = false)
        {
            long defaultPermissionListId = default(long);

            switch (permissonType)
            {
            case PermissionTypeEnum.Brand:
            case PermissionTypeEnum.CityArea:
            case PermissionTypeEnum.ProductFamily:
                defaultPermissionListId = currentUser.BusinessId.Value;
                break;

            case PermissionTypeEnum.SystemAccess:
            case PermissionTypeEnum.Tool:
                defaultPermissionListId = currentUser.UserId;
                break;
            }

            return(this.Db.GetPermissionResultListModel(defaultPermissionListId, userBeingEditedId, permissonType, null));
        }
Beispiel #28
0
        private static string checkWriteDeleteTableRigth <T>(Guid userID, List <T> entityList, PermissionTypeEnum permissionType) where T : Models.MyEntityBase
        {
            if (permissionType != PermissionTypeEnum.Write && permissionType != PermissionTypeEnum.Delete)
            {
                return($"{permissionType}权限类型不是 Write 或 Delete");
            }
            Dictionary <string, List <object> > tableIdDic     = new Dictionary <string, List <object> >();
            Dictionary <string, string>         tableIdNameDic = new Dictionary <string, string>();

            foreach (var entity in entityList)
            {
                var tableName = entity.getTableName();
                var id        = entity.getId();
                var idName    = entity.getIdName();
                if (!tableIdDic.ContainsKey(tableName))
                {
                    tableIdDic.Add(tableName, new List <object>());
                }
                var idLsit = tableIdDic[tableName];
                idLsit.Add(id);

                if (!tableIdNameDic.ContainsKey(tableName))
                {
                    tableIdNameDic.Add(tableName, idName);
                }
            }
            var whereSQL = string.Empty;

            foreach (var tableids in tableIdDic)
            {
                var ids       = tableids.Value;
                var tableName = tableids.Key;
                var idName    = tableIdNameDic[tableName];
                switch (permissionType)
                {
                case PermissionTypeEnum.Write:
                    whereSQL = getWriteWhereSql(userID, tableName);
                    break;

                case PermissionTypeEnum.Delete:
                    whereSQL = getDeleteWhereSql(userID, tableName);
                    break;
                }
                var sqlStr = $"select count(1) from {tableName} with(nolock) where [{idName}] in ('{string.Join("','", ids)}') and {whereSQL}";
                int cnt    = 0;
                using (IServiceScope serviceScope = _serviceProvider.GetService <IServiceScopeFactory>().CreateScope())
                {
                    using (var dbContext = serviceScope.ServiceProvider.GetService <EntityContext>())
                    {
                        cnt = dbContext.Database.SqlQueryScalar <int>(sqlStr);
                    }
                }

                if (cnt != ids.Count)
                {
                    return($"{{权限异常类型:{permissionType},权限异常描述:权限不够,用户OID:{userID},表名:{tableName}}}");
                }
            }


            return(string.Empty);
        }
Beispiel #29
0
        public void ReplacePermissions(EntityEnum fromEntity, long fromId, EntityEnum toEntity, long toId, PermissionTypeEnum type)
        {
            var permissionsToRemove = GetPermissionList(toId).Select(p => p)
                                      .Where(p => p.PermissionTypeId == type)
                                      .ToList();

            this.Context.Permissions.RemoveRange(permissionsToRemove);

            var permissionsToAdd = GetPermissionList(fromId)
                                   .Where(p => p.PermissionTypeId == type)
                                   .Select(p => new { permissionId = p.PermissionId, referenceId = p.ReferenceId, referenceEntityId = p.ReferenceEntityId }).ToList();

            permissionsToAdd.ForEach(p => AddPermission(p.permissionId, toEntity, toId, p.referenceEntityId, (int)p.referenceId, type));
        }
        /// <summary>
        /// Check whether the user has the permission to operate the corresponding behavior specified by permission. 
        /// </summary>
        /// <param name="permission">The permission flag specified in PidTagMemberRights</param>
        /// <param name="userName">The user whose permission is specified in permission argument.</param>
        /// <returns>The return value from the server. 0x00000000 indicates success, others indicates error occurs.</returns>
        public uint CheckPidTagMemberRightsBehavior(PermissionTypeEnum permission, string userName)
        {
            uint returnValue = UINT32FAILED;
            string freeBusy = string.Empty;
            string password = string.Empty;

            switch (permission)
            {
                case PermissionTypeEnum.Create:
                    returnValue = this.CreateMessageByLogonUser();

                    if (UINT32SUCCESS == returnValue)
                    {
                        this.VerifyCreateFlagValue();
                    }

                    return returnValue;

                case PermissionTypeEnum.CreateSubFolder:
                    returnValue = this.CreateSubFolder(userName);

                    if (UINT32SUCCESS == returnValue)
                    {
                        this.VerifyCreateSubFolderFlagValue();
                    }

                    return returnValue;

                case PermissionTypeEnum.DeleteAny:
                    returnValue = this.DeleteMessage(this.messageIdsCreatedByOther[0]);
                    if (UINT32SUCCESS != returnValue)
                    {
                        return returnValue;
                    }

                    returnValue = this.DeleteMessage(this.ownedMessageIds[0]);

                    if (UINT32SUCCESS == returnValue)
                    {
                        this.VerifyDeleteAnyFlagValue();
                    }

                    return returnValue;

                case PermissionTypeEnum.DeleteOwned:
                    returnValue = this.DeleteMessage(this.ownedMessageIds[0]);

                    if (UINT32SUCCESS == returnValue)
                    {
                        this.VerifyDeleteOwnedFlagValue();
                    }

                    return returnValue;

                case PermissionTypeEnum.EditAny:
                    returnValue = this.EditMessage(this.messageIdsCreatedByOther[0]);
                    if (UINT32SUCCESS != returnValue)
                    {
                        return returnValue;
                    }

                    returnValue = this.EditMessage(this.ownedMessageIds[0]);

                    if (UINT32SUCCESS == returnValue)
                    {
                        this.VerifyEditAnyFlagValue();
                    }

                    return returnValue;

                case PermissionTypeEnum.EditOwned:
                    returnValue = this.EditMessage(this.ownedMessageIds[0]);

                    if (UINT32SUCCESS == returnValue)
                    {
                        this.VerifyEditOwnedFlagValue();
                    }

                    return returnValue;

                case PermissionTypeEnum.FolderOwner:
                    returnValue = this.ModifyFolderProperty();

                    if (UINT32SUCCESS == returnValue)
                    {
                        this.VerifyFolderOwnerFlagValue();
                    }

                    return returnValue;

                case PermissionTypeEnum.FolderVisible:
                    returnValue = this.CheckFolderVisible();

                    if (UINT32SUCCESS == returnValue)
                    {
                        this.VerifyFolderVisibleFlagValue();
                    }

                    return returnValue;

                case PermissionTypeEnum.FreeBusyDetailed:
                    password = this.GetUserPassword(userName);
                    freeBusy = this.sutControlAdapter.GetUserFreeBusyStatus(userName, password);
                    if ("1" == freeBusy)
                    {
                        this.VerifyFreeBusyDetailedFlagValue();
                        return UINT32SUCCESS;
                    }
                    else if ("2" == freeBusy)
                    {
                        return 0x80070005; // AccessDenied
                    }
                    else
                    {
                        return UINT32FAILED;
                    }

                case PermissionTypeEnum.FreeBusySimple:
                    password = this.GetUserPassword(userName);
                    freeBusy = this.sutControlAdapter.GetUserFreeBusyStatus(userName, password);
                    if ("0" == freeBusy)
                    {
                        this.VerifyFreeBusySimpleFlagValue();
                        return UINT32SUCCESS;
                    }
                    else if ("2" == freeBusy)
                    {
                        return 0x80070005; // AccessDenied
                    }
                    else
                    {
                        return UINT32FAILED;
                    }

                case PermissionTypeEnum.ReadAny:

                    returnValue = this.ReadMessage(this.ownedMessageIds[0]);
                    if (UINT32SUCCESS != returnValue)
                    {
                        return returnValue;
                    }

                    returnValue = this.ReadMessage(this.messageIdsCreatedByOther[0]);

                    if (UINT32SUCCESS == returnValue)
                    {
                        this.VerifyReadAnyFlagValue();
                    }

                    return returnValue;

                default:
                    return UINT32FAILED;
            }
        }