Ejemplo n.º 1
0
        /// <summary>
        /// 实现对权限的删除
        /// </summary>
        /// <param name="permissionInfo">权限的实体类</param>
        /// <returns>返回执行成功的标志</returns>
        public ActionResult UpdatePermissionInfo(BasePermission permissionInfo)
        {
            var editPermissionInfo = _permissionInfoService.LoadEntities(c => c.ID == permissionInfo.ID).FirstOrDefault();

            if (editPermissionInfo == null)
            {
                return(Content("请您检查,错误信息"));
            }
            editPermissionInfo.PerMission      = permissionInfo.PerMission;
            editPermissionInfo.RequestHttpType = permissionInfo.RequestHttpType;
            editPermissionInfo.RequestURL      = permissionInfo.RequestURL;
            editPermissionInfo.ActionType      = permissionInfo.ActionType;
            editPermissionInfo.SortCode        = permissionInfo.SortCode;
            editPermissionInfo.AllowDelete     = permissionInfo.AllowDelete;
            editPermissionInfo.AllowEdit       = permissionInfo.AllowEdit;
            editPermissionInfo.IsVisible       = permissionInfo.IsVisible;
            editPermissionInfo.Enabled         = permissionInfo.Enabled;
            editPermissionInfo.Description     = permissionInfo.Description;
            editPermissionInfo.ModifiedOn      = DateTime.Parse(DateTime.Now.ToString());
            BaseUser user = Session["UserInfo"] as BaseUser;

            editPermissionInfo.ModifiedUserID = user.Code;     //获取修改信息的ID
            editPermissionInfo.ModifiedBy     = user.UserName; //获取修改此用户的用户名
            if (_permissionInfoService.UpdateEntity() > 0)
            {
                return(Content("OK"));
            }
            return(Content("Error"));
        }
Ejemplo n.º 2
0
        public static async Task <PermissionStatus> CheckPermissions(BasePermission permission)
        {
            var permissionStatus = await permission.CheckPermissionStatusAsync();

            bool request = false;

            if (permissionStatus == PermissionStatus.Denied)
            {
                if (Device.RuntimePlatform == Device.iOS)
                {
                    var title    = $"{permission} Permission";
                    var question = $"To use this plugin the {permission} permission is required. Please go into Settings and turn on {permission} for the app.";
                    var positive = "Settings";
                    var negative = "Maybe Later";
                    var task     = Application.Current?.MainPage?.DisplayAlert(title, question, positive, negative);
                    if (task == null)
                    {
                        return(permissionStatus);
                    }

                    var result = await task;
                    if (result)
                    {
                        CrossPermissions.Current.OpenAppSettings();
                    }

                    return(permissionStatus);
                }

                request = true;
            }

            if (request || permissionStatus != PermissionStatus.Granted)
            {
                permissionStatus = await permission.RequestPermissionAsync();


                if (permissionStatus != PermissionStatus.Granted)
                {
                    var title    = $"{permission} Permission";
                    var question = $"To use the plugin the {permission} permission is required.";
                    var positive = "Settings";
                    var negative = "Maybe Later";
                    var task     = Application.Current?.MainPage?.DisplayAlert(title, question, positive, negative);
                    if (task == null)
                    {
                        return(permissionStatus);
                    }

                    var result = await task;
                    if (result)
                    {
                        CrossPermissions.Current.OpenAppSettings();
                    }
                    return(permissionStatus);
                }
            }

            return(permissionStatus);
        }
Ejemplo n.º 3
0
        public static bool HasBasePermission(NWPlayer player, Guid pcBaseID, BasePermission permission)
        {
            if (player.IsDM)
            {
                return(true);
            }

            return(HasBasePermission(player.GlobalID, pcBaseID, permission));
        }
Ejemplo n.º 4
0
        private void DeletePlayerPermission(Guid playerID, BasePermission permission, bool isPublicPermission)
        {
            var data         = BaseService.GetPlayerTempData(GetPC());
            var dbPermission = isPublicPermission ?
                               DataService.PCBasePermission.GetPublicPermissionOrDefault(data.PCBaseID) :
                               DataService.PCBasePermission.GetPlayerPrivatePermissionOrDefault(playerID, data.PCBaseID);

            DataService.SubmitDataChange(dbPermission, DatabaseActionType.Delete);
        }
Ejemplo n.º 5
0
        private static async Task <PermissionStatus> CheckAndRequestPermissionAsync(BasePermission permission)
        {
            var status = await permission.CheckStatusAsync();

            if (status != PermissionStatus.Granted)
            {
                status = await permission.RequestAsync();
            }
            return(status);
        }
Ejemplo n.º 6
0
 async Task <PermissionInfo> CreatePermission(BasePermission permission, string icon, string name, string description)
 {
     return(new PermissionInfo()
     {
         Icon = icon,
         Permission = permission,
         Name = name,
         Description = description,
         IsGranted = await permission.CheckStatusAsync() == PermissionStatus.Granted
     });
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 实现删除权限的信息
        /// </summary>
        /// <param name="permissionInfo">权限的实体类</param>
        /// <param name="ID">权限的ID</param>
        /// <param name="Not">表示进行了什么操作</param>
        /// <returns>返回对权限操作的标识</returns>
        public ActionResult DeletePermission(BasePermission permissionInfo, string ID, string Not)
        {
            //判断是否传递过来了信息,如果没有传递过来信息,则提示错误
            if (string.IsNullOrEmpty(ID))
            {
                return(Content("请您选择需要删除/还原的权限信息"));
            }
            //解析传递过来的字符串
            var        idStrs = ID.Split(',');
            List <int> list   = new List <int>();

            foreach (var idStr in idStrs)
            {
                list.Add(int.Parse(idStr));
            }
            //伪删除角色信息
            if (Not == "not")
            {
                foreach (var permissionID in list)
                {
                    var deletePermissionInfo = _permissionInfoService.LoadEntities(c => c.ID == permissionID).FirstOrDefault();
                    deletePermissionInfo.DeletionStateCode = 1;
                    _permissionInfoService.UpdateEntity(permissionInfo);
                }
                return(Content("OK"));
            }
            //还原被伪删除掉的数据
            else if (Not == "back")
            {
                foreach (var permissionID in list)
                {
                    var backPermissionInfo = _permissionInfoService.LoadEntities(c => c.ID == permissionID).FirstOrDefault();
                    backPermissionInfo.DeletionStateCode = 0;
                    _permissionInfoService.UpdateEntity(permissionInfo);
                }
                return(Content("OK"));
            }
            //直接删除数据
            else
            {
                if (_permissionInfoService.DeletePermission(list) > 0)
                {
                    return(Content("OK"));
                }
            }
            return(Content("Error"));
        }
        public static async Task RequirePermissionToExecute(Func <Task> task, BasePermission permission, Func <Task> taskToNotPermission = null)
        {
            var status = await PermissionService.CheckAndRequestPermissionAsync(permission);

            if (status != Xamarin.Essentials.PermissionStatus.Granted)
            {
                //await App.Current.MainPage.DisplayAlert("Não é possive continuar, permissão não concedida");

                if (taskToNotPermission != null)
                {
                    await taskToNotPermission.Invoke();
                }

                return;
            }

            await task.Invoke();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 实现对权限的增加功能
        /// </summary>
        /// <param name="permission">权限的实体类</param>
        /// <returns>返回是否执行成功的权限的类型</returns>
        public ActionResult AddPermission(BasePermission permissionInfo)
        {
            permissionInfo.Code = Guid.NewGuid().ToString();
            //permissionInfo.ActionType
            permissionInfo.AllowEdit         = 1;
            permissionInfo.AllowDelete       = 1;
            permissionInfo.IsVisible         = 1;
            permissionInfo.DeletionStateCode = 0;
            permissionInfo.Enabled           = 1;
            permissionInfo.CreateOn          = DateTime.Parse(DateTime.Now.ToString());
            BaseUser user = Session["UserInfo"] as BaseUser;

            permissionInfo.CreateUserID = user.Code;
            permissionInfo.CreateBy     = user.UserName;
            //执行添加权限代码,返回OK
            _permissionInfoService.AddEntity(permissionInfo);
            return(Content("OK"));
        }
Ejemplo n.º 10
0
        public async Task <PermissionStatus> CheckAndRequestAsync(BasePermission permission)
        {
            // https://docs.microsoft.com/zh-cn/xamarin/essentials/permissions?context=xamarin%2Fandroid&tabs=android#general-usage
            var status = await permission.CheckStatusAsync();

            if (status == PermissionStatus.Granted)
            {
                return(status);
            }

            if (status == PermissionStatus.Denied && DeviceInfo.Platform == DevicePlatform.iOS)
            {
                // Prompt the user to turn on in settings
                // 提示用户在“设置”中启用
                // On iOS once a permission has been denied it may not be requested again from the application
                // 在iOS上,一旦权限被拒绝,就不能再次从应用程序请求权限
                PromptUserGoToSettings(permission);
                return(status);
            }

            if (permission.ShouldShowRationale())
            {
                // Prompt the user with additional information as to why the permission is needed
                // 提示用户需要权限的其他信息
                ShowRationale(permission);
            }

            status = await permission.RequestAsync();

            if (status == PermissionStatus.Denied)
            {
                PromptUserGoToSettings(permission);
            }

            return(status);
        }
Ejemplo n.º 11
0
        public bool HasBasePermission(NWPlayer player, Guid pcBaseID, BasePermission permission)
        {
            if (player.IsDM)
            {
                return(true);
            }

            var dbPermission = _data.GetAll <PCBasePermission>().SingleOrDefault(x => x.PCBaseID == pcBaseID && x.PlayerID == player.GlobalID);

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

            if (permission == BasePermission.CanPlaceEditStructures && dbPermission.CanPlaceEditStructures)
            {
                return(true);
            }
            if (permission == BasePermission.CanAccessStructureInventory && dbPermission.CanAccessStructureInventory)
            {
                return(true);
            }
            if (permission == BasePermission.CanManageBaseFuel && dbPermission.CanManageBaseFuel)
            {
                return(true);
            }
            if (permission == BasePermission.CanExtendLease && dbPermission.CanExtendLease)
            {
                return(true);
            }
            if (permission == BasePermission.CanAdjustPermissions && dbPermission.CanAdjustPermissions)
            {
                return(true);
            }
            if (permission == BasePermission.CanEnterBuildings && dbPermission.CanEnterBuildings)
            {
                return(true);
            }
            if (permission == BasePermission.CanRetrieveStructures && dbPermission.CanRetrieveStructures)
            {
                return(true);
            }
            if (permission == BasePermission.CanCancelLease && dbPermission.CanCancelLease)
            {
                return(true);
            }
            if (permission == BasePermission.CanRenameStructures && dbPermission.CanRenameStructures)
            {
                return(true);
            }
            if (permission == BasePermission.CanEditPrimaryResidence && dbPermission.CanEditPrimaryResidence)
            {
                return(true);
            }
            if (permission == BasePermission.CanRemovePrimaryResidence && dbPermission.CanRemovePrimaryResidence)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 12
0
        public static async Task <PermissionStatus> CheckPermissions(BasePermission permission)
        {
            var permissionStatus = await permission.CheckPermissionStatusAsync();

            bool request = false;

            if (permissionStatus == PermissionStatus.Denied)
            {
                if (Device.RuntimePlatform == Device.iOS)
                {
                    // The following lines have been added
                    // `permission.ToString()` Starts as "Plugin.Permissions.LocationPermission", trim to "LocationPermission"
                    var permissionString = permission.ToString().Split('.')[2];
                    permissionString = permissionString.Substring(0, permissionString.Length - 10);
                    // The above lines have been added

                    // The following 4 lines have been edited
                    var title    = $"{permissionString} permissions required";
                    var question = $"Please open Settings and allow {permissionString}.";
                    var positive = "Open Settings";
                    var negative = "Deny permission";
                    // The above 4 lines have been edited

                    var task = Application.Current?.MainPage?.DisplayAlert(title, question, positive, negative);
                    if (task == null)
                    {
                        return(permissionStatus);
                    }

                    var result = await task;
                    if (result)
                    {
                        CrossPermissions.Current.OpenAppSettings();
                    }

                    return(permissionStatus);
                }

                request = true;
            }

            if (request || permissionStatus != PermissionStatus.Granted)
            {
                permissionStatus = await permission.RequestPermissionAsync();


                if (permissionStatus != PermissionStatus.Granted)
                {
                    // The following lines have been added
                    // `permission.ToString()` Starts as "Plugin.Permissions.LocationPermission", trim to "LocationPermission"
                    var permissionString = permission.ToString().Split('.')[2];
                    permissionString = permissionString.Substring(0, permissionString.Length - 10);
                    // The above lines have been added

                    // The following 4 lines have been edited
                    var title    = $"{permissionString} permissions required";
                    var question = $"Please open Settings and allow {permissionString}.";
                    var positive = "Open Settings";
                    var negative = "Deny permission";
                    // The above 4 lines have been edited

                    var task = Application.Current?.MainPage?.DisplayAlert(title, question, positive, negative);
                    if (task == null)
                    {
                        return(permissionStatus);
                    }

                    var result = await task;
                    if (result)
                    {
                        CrossPermissions.Current.OpenAppSettings();
                    }
                    return(permissionStatus);
                }
            }

            return(permissionStatus);
        }
Ejemplo n.º 13
0
        private void TogglePermission(NWPlayer player, BasePermission permission)
        {
            var data         = _base.GetPlayerTempData(GetPC());
            var dbPermission = _data.SingleOrDefault <PCBasePermission>(x => x.PlayerID == player.GlobalID && x.PCBaseID == data.PCBaseID);

            DatabaseActionType action = DatabaseActionType.Update;

            if (dbPermission == null)
            {
                dbPermission = new PCBasePermission
                {
                    PCBaseID = data.PCBaseID,
                    PlayerID = player.GlobalID
                };
                action = DatabaseActionType.Insert;
            }

            switch (permission)
            {
            case BasePermission.CanPlaceEditStructures:
                dbPermission.CanPlaceEditStructures = !dbPermission.CanPlaceEditStructures;
                break;

            case BasePermission.CanAccessStructureInventory:
                dbPermission.CanAccessStructureInventory = !dbPermission.CanAccessStructureInventory;
                break;

            case BasePermission.CanManageBaseFuel:
                dbPermission.CanManageBaseFuel = !dbPermission.CanManageBaseFuel;
                break;

            case BasePermission.CanExtendLease:
                dbPermission.CanExtendLease = !dbPermission.CanExtendLease;
                break;

            case BasePermission.CanEnterBuildings:
                dbPermission.CanEnterBuildings = !dbPermission.CanEnterBuildings;
                break;

            case BasePermission.CanRetrieveStructures:
                dbPermission.CanRetrieveStructures = !dbPermission.CanRetrieveStructures;
                break;

            case BasePermission.CanRenameStructures:
                dbPermission.CanRenameStructures = !dbPermission.CanRenameStructures;
                break;

            case BasePermission.CanEditPrimaryResidence:
                dbPermission.CanEditPrimaryResidence = !dbPermission.CanEditPrimaryResidence;
                break;

            case BasePermission.CanRemovePrimaryResidence:
                dbPermission.CanRemovePrimaryResidence = !dbPermission.CanRemovePrimaryResidence;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(permission), permission, null);
            }

            _data.SubmitDataChange(dbPermission, action);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// 权限被拒绝,可提示用户在“设置”中启用,通常应有不再提示的选项
 /// </summary>
 /// <param name="permission"></param>
 protected virtual void PromptUserGoToSettings(BasePermission permission)
 {
     // 可由平台重写此函数实现,通常为显示一个UI上的弹窗,上有复选框不再显示
 }
Ejemplo n.º 15
0
        private void TogglePermission(Guid playerID, BasePermission permission, bool isPublicPermission)
        {
            var data         = BaseService.GetPlayerTempData(GetPC());
            var dbPermission = isPublicPermission ?
                               DataService.SingleOrDefault <PCBasePermission>(x => x.PCBaseID == data.PCBaseID &&
                                                                              x.IsPublicPermission) :
                               DataService.SingleOrDefault <PCBasePermission>(x => x.PlayerID == playerID &&
                                                                              x.PCBaseID == data.PCBaseID &&
                                                                              !x.IsPublicPermission);

            DatabaseActionType action = DatabaseActionType.Update;

            if (dbPermission == null)
            {
                dbPermission = new PCBasePermission
                {
                    PCBaseID           = data.PCBaseID,
                    PlayerID           = playerID,
                    IsPublicPermission = isPublicPermission
                };
                action = DatabaseActionType.Insert;
            }

            switch (permission)
            {
            case BasePermission.CanPlaceEditStructures:
                dbPermission.CanPlaceEditStructures = !dbPermission.CanPlaceEditStructures;
                break;

            case BasePermission.CanAccessStructureInventory:
                dbPermission.CanAccessStructureInventory = !dbPermission.CanAccessStructureInventory;
                break;

            case BasePermission.CanManageBaseFuel:
                dbPermission.CanManageBaseFuel = !dbPermission.CanManageBaseFuel;
                break;

            case BasePermission.CanExtendLease:
                dbPermission.CanExtendLease = !dbPermission.CanExtendLease;
                break;

            case BasePermission.CanEnterBuildings:
                dbPermission.CanEnterBuildings = !dbPermission.CanEnterBuildings;
                break;

            case BasePermission.CanRetrieveStructures:
                dbPermission.CanRetrieveStructures = !dbPermission.CanRetrieveStructures;
                break;

            case BasePermission.CanRenameStructures:
                dbPermission.CanRenameStructures = !dbPermission.CanRenameStructures;
                break;

            case BasePermission.CanEditPrimaryResidence:
                dbPermission.CanEditPrimaryResidence = !dbPermission.CanEditPrimaryResidence;
                break;

            case BasePermission.CanRemovePrimaryResidence:
                dbPermission.CanRemovePrimaryResidence = !dbPermission.CanRemovePrimaryResidence;
                break;

            case BasePermission.CanChangeStructureMode:
                dbPermission.CanChangeStructureMode = !dbPermission.CanChangeStructureMode;
                break;

            case BasePermission.CanAdjustPublicPermissions:
                dbPermission.CanAdjustPublicPermissions = !dbPermission.CanAdjustPublicPermissions;
                break;

            case BasePermission.CanFlyStarship:
                dbPermission.CanFlyStarship = !dbPermission.CanFlyStarship;
                break;

            case BasePermission.CanDockStarship:
                dbPermission.CanDockStarship = !dbPermission.CanDockStarship;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(permission), permission, null);
            }

            DataService.SubmitDataChange(dbPermission, action);
        }
Ejemplo n.º 16
0
        public static bool HasBasePermission(Guid player, Guid pcBaseID, BasePermission permission)
        {
            // Public permissions take priority over all other permissions. Check those first.
            var publicBasePermission = DataService.SingleOrDefault <PCBasePermission>(x => x.PCBaseID == pcBaseID &&
                                                                                      x.IsPublicPermission);

            if (publicBasePermission != null)
            {
                if (permission == BasePermission.CanPlaceEditStructures && publicBasePermission.CanPlaceEditStructures)
                {
                    return(true);
                }
                if (permission == BasePermission.CanAccessStructureInventory && publicBasePermission.CanAccessStructureInventory)
                {
                    return(true);
                }
                if (permission == BasePermission.CanManageBaseFuel && publicBasePermission.CanManageBaseFuel)
                {
                    return(true);
                }
                if (permission == BasePermission.CanExtendLease && publicBasePermission.CanExtendLease)
                {
                    return(true);
                }
                if (permission == BasePermission.CanAdjustPermissions && publicBasePermission.CanAdjustPermissions)
                {
                    return(true);
                }
                if (permission == BasePermission.CanEnterBuildings && publicBasePermission.CanEnterBuildings)
                {
                    return(true);
                }
                if (permission == BasePermission.CanRetrieveStructures && publicBasePermission.CanRetrieveStructures)
                {
                    return(true);
                }
                if (permission == BasePermission.CanCancelLease && publicBasePermission.CanCancelLease)
                {
                    return(true);
                }
                if (permission == BasePermission.CanRenameStructures && publicBasePermission.CanRenameStructures)
                {
                    return(true);
                }
                if (permission == BasePermission.CanEditPrimaryResidence && publicBasePermission.CanEditPrimaryResidence)
                {
                    return(true);
                }
                if (permission == BasePermission.CanRemovePrimaryResidence && publicBasePermission.CanRemovePrimaryResidence)
                {
                    return(true);
                }
                if (permission == BasePermission.CanChangeStructureMode && publicBasePermission.CanChangeStructureMode)
                {
                    return(true);
                }
                if (permission == BasePermission.CanAdjustPublicPermissions && publicBasePermission.CanAdjustPublicPermissions)
                {
                    return(true);
                }
                if (permission == BasePermission.CanDockStarship && publicBasePermission.CanDockStarship)
                {
                    return(true);
                }
            }

            // No matching public permissions. Now check the base permissions for this player.
            var dbPermission = DataService.GetAll <PCBasePermission>()
                               .SingleOrDefault(x => x.PCBaseID == pcBaseID &&
                                                x.PlayerID == player &&
                                                !x.IsPublicPermission);

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

            if (permission == BasePermission.CanPlaceEditStructures && dbPermission.CanPlaceEditStructures)
            {
                return(true);
            }
            if (permission == BasePermission.CanAccessStructureInventory && dbPermission.CanAccessStructureInventory)
            {
                return(true);
            }
            if (permission == BasePermission.CanManageBaseFuel && dbPermission.CanManageBaseFuel)
            {
                return(true);
            }
            if (permission == BasePermission.CanExtendLease && dbPermission.CanExtendLease)
            {
                return(true);
            }
            if (permission == BasePermission.CanAdjustPermissions && dbPermission.CanAdjustPermissions)
            {
                return(true);
            }
            if (permission == BasePermission.CanEnterBuildings && dbPermission.CanEnterBuildings)
            {
                return(true);
            }
            if (permission == BasePermission.CanRetrieveStructures && dbPermission.CanRetrieveStructures)
            {
                return(true);
            }
            if (permission == BasePermission.CanCancelLease && dbPermission.CanCancelLease)
            {
                return(true);
            }
            if (permission == BasePermission.CanRenameStructures && dbPermission.CanRenameStructures)
            {
                return(true);
            }
            if (permission == BasePermission.CanEditPrimaryResidence && dbPermission.CanEditPrimaryResidence)
            {
                return(true);
            }
            if (permission == BasePermission.CanRemovePrimaryResidence && dbPermission.CanRemovePrimaryResidence)
            {
                return(true);
            }
            if (permission == BasePermission.CanChangeStructureMode && dbPermission.CanChangeStructureMode)
            {
                return(true);
            }
            if (permission == BasePermission.CanAdjustPublicPermissions && dbPermission.CanAdjustPublicPermissions)
            {
                return(true);
            }
            if (permission == BasePermission.CanDockStarship && dbPermission.CanDockStarship)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// 提示用户需要权限的其他信息
 /// </summary>
 /// <param name="permission"></param>
 protected virtual void ShowRationale(BasePermission permission)
 {
     // 可由平台重写此函数实现,通常为显示一个吐司消息,因调用此函数后会立即开始重新申请权限
 }