public async Task <IActionResult> GetPermissionsByGroupIdAsync([FromRoute] int groupId, [FromQuery] PermissionGetModel model) { var currentFunctionCodes = GetCurrentAccountFunctionCodes(); if (!currentFunctionCodes.Contains("Group_Full") && !currentFunctionCodes.Contains("Group_Read_All")) { var currentAccount = await _accountRepository.GetAccountByIdAsync(CurrentAccountId); if (currentAccount.GroupId != groupId) { throw new ForbiddenException(); } } model.Validate(); var permissions = await _groupRepository.GetPermissionsByGroupIdAsync(groupId, model.Page, model.PageSize); var functions = await _functionRepository.GetFunctionsAsync(null, null, 1, int.MaxValue); if (permissions.Items.Count == 0) { throw new NotFound404Exception("page"); } return(Ok(PermissionList.GetFrom(permissions, functions.Items))); }
public IPermissionItem Insert(int resourceId, int roleNumber, int permValue) { PermissionList list; var fake = new FakePerm() { Id = counter, ResourceId = resourceId, RoleNumber = roleNumber, PermValue = permValue }; if (db.TryGetValue(resourceId, out list)) { if (list.Contains(roleNumber)) { list[roleNumber].PermValue = permValue; return(list[roleNumber]); } else { counter++; list.Add(fake); } } else { list = new PermissionList { fake }; db.Add(resourceId, list); } return(fake); }
/// <summary> /// آيا به اين منبع دسترسي دارد يا نه /// </summary> /// <param name="resourceCode">شناسه منبع</param> /// <returns></returns> public bool HasAccess(string resourceCode) { if (PermissionList.ContainsKey(resourceCode) == false) { throw new Exception("resource not found: " + resourceCode.ToString()); } PermissionsEnum permission = (PermissionsEnum)PermissionList[resourceCode]; if (permission == PermissionsEnum.Undecided) // undecided { return(false); } if (permission == PermissionsEnum.Allow || permission == PermissionsEnum.AllowForce) { return(true); } if (permission == PermissionsEnum.Deny || permission == PermissionsEnum.DenyForce) { return(false); } return(false); }
/// <summary> /// Create Permission on Item. /// </summary> /// <param name="ItemID">ID of the item to create permission for.</param> /// <param name="EmailAddress"> /// Email Address of the user or group to which this permission refers. /// </param> /// <param name="type"> /// The values are "user", "group", "domain" or "anyone". /// </param> /// <param name="role"> /// The values are "owner", "organizer", "fileOrganizer", "writer", "commenter" or "reader". /// </param> public static IList <Permission> CreatePermission(String ItemID, String EmailAddress, String PermissionID, String Role, String Type) { var file = GetItem(ItemID); if (file == null) { throw new Exception($"Invalid Item ID/Path '{ItemID}'"); } Permission permission = new Permission { EmailAddress = EmailAddress, Id = PermissionID, Role = Role, Type = Type, }; try { _service.Permissions.Create(permission, file.Id).Execute(); PermissionList list = _service.Permissions.List(file.Id).Execute(); return(list.Permissions); } catch (Exception Ex) { throw new Exception("Error in Creating Permission : " + Ex.Message); } }
public override void WriteToStream(IndentStream stream) { stream.Write("GRANT "); PermissionList.Select(x => x.ToUpper()).WriteToStreamWithComma(stream); if (OnObjectId != null) { stream.WriteLine(); stream.Write("ON "); OnObjectId.WriteToStream(stream); } stream.Write(" TO "); TargetList.WriteToStreamWithComma(stream); if (AsDbo != null) { stream.Write(" AS "); AsDbo.WriteToStream(stream); } if (IsSemicolon) { stream.Write(" ;"); } }
/// <summary> /// Retrieves list of Permission objects from SqlCommand, after database query /// number of rows retrieved and returned depends upon the rows field value /// </summary> /// <param name="cmd">The command object to use for query</param> /// <param name="rows">Number of rows to process</param> /// <returns>A list of Permission objects</returns> private PermissionList GetList(SqlCommand cmd, long rows) { // Select multiple records SqlDataReader reader; long result = SelectRecords(cmd, out reader); //Permission list PermissionList list = new PermissionList(); using ( reader ) { // Read rows until end of result or number of rows specified is reached while (reader.Read() && rows-- != 0) { Permission permissionObject = new Permission(); FillObject(permissionObject, reader); list.Add(permissionObject); } // Close the reader in order to receive output parameters // Output parameters are not available until reader is closed. reader.Close(); } return(list); }
/// <summary> /// Kiểm tra quyền user theo mã quyền /// </summary> /// <param name="permissionCode">Mã quyền</param> /// <returns></returns> public bool CheckRight(string permissionCode) { if (PermissionList != null) { return(PermissionList.Where(permission => permission.PermissionCode.Equals(permissionCode)).ToList().Count > 0); } return(false); }
/// <summary> /// Kiểm tra quyền user theo đối tượng quyền /// </summary> /// <param name="permissionCode">Mã quyền</param> /// <returns></returns> public bool CheckRight(Permission permission) { if (PermissionList != null) { return(PermissionList.Where(perm => perm.Id.Equals(permission.Id)).ToList().Count > 0); } return(false); }
private async Task <PermissionList> GetRecords() { var dbRec = await _context.ApplicationPermission.ToListAsync(); PermissionList permissions = new PermissionList { UserHandler = _userHandler, Permissions = _mapper.Map <List <ApplicationPermission>, List <Permission> >(dbRec) }; return(permissions); }
public void RetrieveAllFiles() { List <tbl_User> list = DirectorySync.GetAllUsers(); List <Google.Apis.Drive.v2.Data.File> result = new List <Google.Apis.Drive.v2.Data.File>(); foreach (var item in list) { var drvService = CreateDriveService(item.Email); FilesResource.ListRequest request = drvService.Files.List(); //request.Q = "'" + item.Email + "'" + " in owners"; Google.Apis.Drive.v2.Data.About about = drvService.About.Get().Fetch(); DirectorySync.UpdateUserMetadata(about, item.Email); result.Clear(); do { try { FileList files = request.Fetch(); result.AddRange(files.Items); request.PageToken = files.NextPageToken; } catch (Exception e) { Response.Write("An error occurred: " + e.Message); request.PageToken = null; } }while (!String.IsNullOrEmpty(request.PageToken)); if (result != null || result.Count > 0) { PermissionList permList = new PermissionList(); List <PermissionLight> permLight = new List <PermissionLight>(); foreach (var f in result.Where(a => !a.MimeType.ToLower().Contains("folder"))) { if (f.Shared == true) { permList = drvService.Permissions.List(f.Id).Fetch(); permLight.Add(new PermissionLight() { DocID = f.Id, Permissions = permList }); } } DirectorySync.PushFiles(item.UserID, result, permLight); } } }
public async Task <ActionResult <PermissionList> > Permissions([FromQuery] string siteUrl, [FromQuery] string listName, [FromQuery] int id) { try { PermissionList result = await _csomService.GetPermissions(siteUrl, listName, id); return(Ok(result)); } catch (Exception Ex) { return(BadRequest("Error: " + Ex.Message)); } }
public static IList <Permission> RetrievePermissions(DriveService service, String fileId) { try { PermissionList permissions = service.Permissions.List(fileId).Execute(); return(permissions.Permissions); } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); } return(null); }
public JsonResult SaveAccessList(PermissionList model) { try { var item = _context.Group.Single(x => x.StatusId != GroupStatus.Deleted.Id && x.Id == model.id); item.Permission = Permission.GetPermissionCode(model.permission); _context.SaveChanges(); return(Success("اطلاعات با موفقیت ذخیره شد.")); } catch (Exception ex) { return(ServerError(ex)); } }
/// <summary> /// Retrieves all Permission objects by PageRequest /// </summary> /// <returns>A list of Permission objects</returns> public PermissionList GetPaged(PagedRequest request) { using (SqlCommand cmd = GetSPCommand(GETPAGEDPERMISSION)) { AddParameter(cmd, pInt32Out("TotalRows")); AddParameter(cmd, pInt32("PageIndex", request.PageIndex)); AddParameter(cmd, pInt32("RowPerPage", request.RowPerPage)); AddParameter(cmd, pNVarChar("WhereClause", 4000, request.WhereClause)); AddParameter(cmd, pNVarChar("SortColumn", 128, request.SortColumn)); AddParameter(cmd, pNVarChar("SortOrder", 4, request.SortOrder)); PermissionList _PermissionList = GetList(cmd, ALL_AVAILABLE_RECORDS); request.TotalRows = Convert.ToInt32(GetOutParameter(cmd, "TotalRows")); return(_PermissionList); } }
/// <summary> /// Retrieve list of Permission. /// </summary> /// <param name="fillChild"></param> /// <returns>List of Permission</returns> public PermissionList GetAll(bool fillChild) { PermissionList permissionList = new PermissionList(); using (PermissionDataAccess data = new PermissionDataAccess(ClientContext)) { permissionList = data.GetAll(); } if (fillChild) { foreach (Permission permissionObject in permissionList) { FillPermissionWithChilds(permissionObject, fillChild); } } return(permissionList); }
public async Task <PermissionList> GetPermissions(string url, string listName, int id) { PermissionList result = new PermissionList(); ClientContext context = GetSharepointContext(url); List list = context.Web.Lists.GetByTitle(listName); context.Load(list); await context.ExecuteQueryAsync(); var item = list.GetItemById(id); context.Load(item, a => a.HasUniqueRoleAssignments); await context.ExecuteQueryAsync(); if (item.HasUniqueRoleAssignments) { result.IsInheriting = false; } else { result.IsInheriting = true; } context.Load(item, a => a.RoleAssignments.Include(roleAsg => roleAsg.Member.LoginName, roleAsg => roleAsg.RoleDefinitionBindings.Include(roleDef => roleDef.Name, roleDef => roleDef.Description))); await context.ExecuteQueryAsync(); foreach (var roleAsg in item.RoleAssignments) { Permission p = new Permission(); p.GroupName = roleAsg.Member.LoginName; List <string> roles = new List <string>(); foreach (var role in roleAsg.RoleDefinitionBindings) { p.Roles.Add(role.Name); } if ((p.Roles.Contains("Limited Access") && p.Roles.Count() == 1) || (p.GroupName.Contains("SharingLinks"))) { } else { result.Permissions.Add(p); } } return(result); }
public JsonResult AccessList(int id) { try { var item = _context.Group.Single(x => x.StatusId != GroupStatus.Deleted.Id && x.Id == id); var permissionList = Permission.GetPermissionCodeList(item.Permission); var result = new PermissionList() { id = id, permission = permissionList }; return(Success(result)); } catch (Exception ex) { return(ServerError(ex)); } }
public static IList <Permission> GetPermission(String ItemID) { var file = GetItem(ItemID); if (file == null) { throw new Exception($"Invalid Item ID/Path '{ItemID}'"); } try { PermissionList list = _service.Permissions.List(file.Id).Execute(); return(list.Permissions); } catch (Exception Ex) { throw new Exception("Error in Creating Permission : " + Ex.Message); } }
public async Task <IActionResult> AllPermissionList(int offset, int limit, string order, string search) { PermissionList plist = new PermissionList(); //List<Claim> claims =new List<Claim>(); List <ApplicationPermission> aplist = new List <ApplicationPermission>(); var allroles = _roleMangeer.Roles; foreach (var role in allroles) { foreach (var claims in await _roleMangeer.GetClaimsAsync(role)) { ApplicationPermission ap = new ApplicationPermission(); ap.RoleName = role.Name; ap.PermissionType = claims.Type; ap.PermissionValue = claims.Value; aplist.Add(ap); } //claims.AddRange(_roleMangeer.GetClaimsAsync(role).Result.ToList()); } if (!string.IsNullOrEmpty(search)) { aplist = aplist.Where(c => c.PermissionValue.Contains(search)).ToList(); } plist.total = aplist.Count(); if (limit != 0) { if (order.Equals("desc")) { aplist = aplist.OrderByDescending(c => c.PermissionType).Skip(offset).Take(limit).ToList(); } else { aplist = aplist.OrderBy(c => c.PermissionType).Skip(offset).Take(limit).ToList(); } } plist.rows = aplist; return(Json(plist)); }
//移除权限 protected void RemovePermissionButton_Click(object sender, System.EventArgs e) { //if(this.PermissionList.SelectedIndex>-1) //{ // int currentRole = Convert.ToInt32(Request["RoleID"]); // Role bizRole = new Role(currentRole); // bizRole.RemovePermission( Convert.ToInt32(this.PermissionList.SelectedValue) ); // CategoryDownList_SelectedIndexChanged(sender,e); //} int[] items = PermissionList.GetSelectedIndices(); if (items.Length > 0) { int currentRole = Convert.ToInt32(Request["RoleID"]); Role bizRole = new Role(currentRole); foreach (int i in items) { int permid = Convert.ToInt32(this.PermissionList.Items[i].Value); bizRole.RemovePermission(permid); } } CategoryDownList_SelectedIndexChanged(sender, e); }
public void SavePermissions(DataContext db) { var pl = PermissionList.Split <int>(","); var forDel = db.UserPermissions.Where(x => x.UserID == this.ID && !pl.Contains(x.PermissionID)); if (forDel.Any()) { db.UserPermissions.DeleteAllOnSubmit(forDel); db.SubmitChanges(); } foreach (var pid in pl) { var exist = db.UserPermissions.FirstOrDefault(x => x.UserID == ID && x.PermissionID == pid); if (exist == null) { db.UserPermissions.InsertOnSubmit(new UserPermission() { UserID = ID, PermissionID = pid }); } } db.SubmitChanges(); }
static FakePermissionDataAdapter() { var res8 = new PermissionList(); res8.Add(new FakePerm() { Id = 1, ResourceId = 8, RoleNumber = 200, PermValue = 3 }); res8.Add(new FakePerm() { Id = 2, ResourceId = 8, RoleNumber = 300, PermValue = 1 }); res8.Add(new FakePerm() { Id = 5, ResourceId = 8, RoleNumber = 400, PermValue = 2 }); res8.Add(new FakePerm() { Id = 6, ResourceId = 8, RoleNumber = 500, PermValue = 16 }); db.Add(8, res8); var res11 = new PermissionList(); res11.Add(new FakePerm() { Id = 3, ResourceId = 11, RoleNumber = 200, PermValue = 15 }); res11.Add(new FakePerm() { Id = 4, ResourceId = 11, RoleNumber = 300, PermValue = 3 }); db.Add(11, res11); }
public void SaveMainRow() { if (SelectedBrandSectionPermission != null) { var valiationCollection = new List <ValidationResult>(); var isvalid = Validator.TryValidateObject(SelectedBrandSectionPermission, new ValidationContext(SelectedBrandSectionPermission, null, null), valiationCollection, true); if (isvalid) { var save = SelectedBrandSectionPermission.Iserial == 0; var saveRow = new TblBrandSectionPermission(); saveRow.InjectFrom(SelectedBrandSectionPermission); saveRow.BrandCode = SelectedBrand.Brand_Code; saveRow.TblLkpBrandSection = SelectedBrandSection.Iserial; Client.UpdateOrInsertTblBrandSectionPermissionAsync(saveRow, save, PermissionList.IndexOf(SelectedBrandSectionPermission)); } } }
public void DeleteMainRow() { if (SelectedMainRows != null) { var res = MessageBox.Show("Are You To Delete SelectedRecords From Database ?", "Delete", MessageBoxButton.OKCancel); if (res == MessageBoxResult.OK) { foreach (var row in SelectedMainRows) { if (row.Iserial != 0) { Client.DeleteTblBrandSectionPermissionAsync( (TblBrandSectionPermission) new TblBrandSectionPermission().InjectFrom(row), PermissionList.IndexOf(row)); } else { row.Iserial = 0; row.Financial = row.Retail = row.Technical = false; } } } } }
public BrandSectionPermissionViewModel() { if (DesignerProperties.IsInDesignTool) { return; } Client.GetAllBrandsAsync(LoggedUserInfo.Iserial); Client.GetAllBrandsCompleted += (d, s) => { BrandList = s.Result; }; lkpClient.GetTblBrandSectionLinkCompleted += (s, sv) => { BrandSectionList.Clear(); foreach (var row in sv.Result) { BrandSectionList.Add(row.TblLkpBrandSection1); } }; Client.GetUserSpectialPermissionsAsync(); Client.GetUserSpectialPermissionsCompleted += (s, sv) => { foreach (var row in sv.Result) { PermissionList.Add(new TblBrandSectionPermissionViewModel { TblAuthPermission = row.Iserial, Ename = row.Ename, }); } }; Client.GetTblBrandSectionPermissionCompleted += (s, sv) => { foreach (var oldrow in PermissionList) { oldrow.Iserial = 0; oldrow.Financial = oldrow.Retail = oldrow.Technical = false; } foreach (var row in sv.Result) { var permissionRow = PermissionList.SingleOrDefault(x => x.TblAuthPermission == row.TblAuthPermission && row.BrandCode == SelectedBrand.Brand_Code && row.TblLkpBrandSection == SelectedBrandSection.Iserial ); if (permissionRow != null) { permissionRow.InjectFrom(row); } } }; Client.UpdateOrInsertTblBrandSectionPermissionCompleted += (s, x) => { var savedRow = (TblBrandSectionPermissionViewModel)PermissionList.GetItemAt(x.outindex); if (savedRow != null) { savedRow.InjectFrom(x.Result); } }; Client.DeleteTblBrandSectionPermissionCompleted += (s, ev) => { var oldrow = PermissionList.FirstOrDefault(x => x.Iserial == ev.Result); if (oldrow != null) { oldrow.Iserial = 0; oldrow.Financial = oldrow.Retail = oldrow.Technical = false; } }; }
public UserBrandViewModel() { if (DesignerProperties.IsInDesignTool) { return; } Client.GetAllBrandsAsync(0); Client.GetAllBrandsCompleted += (d, s) => { BrandList = s.Result; }; Client.GetAllUsersAsync(0, int.MaxValue, "it.Ename", null, null); Client.GetAllUsersCompleted += (d, s) => { UsersList = s.Result; SelectedUser = s.Result.FirstOrDefault(); }; //Client.GetGenericCompleted += (s, sv) => //{ // foreach (var row in sv.Result) // { // var newrow = new TblUserBrandSectionViewModel // { // Aname = row.Aname, // Ename = row.Ename, // Iserial = row.Iserial, // Code = row.Code, // TblLkpBrandSection = row.Iserial, // BrandCode = SelectedBrand.Brand_Code, // TblAuthUser = SelectedUser.Iserial, // }; // BrandSectionList.Add(newrow); // } //}; lkpClient.GetTblAllBrandSectionLinkCompleted += (s, sv) => { BrandSectionList = new ObservableCollection <TblUserBrandSectionViewModel>(); foreach (var row in sv.Result) { var newrow = new TblUserBrandSectionViewModel { Aname = row.TblLkpBrandSection1.Aname, Ename = row.TblLkpBrandSection1.Ename, TblLkpBrandSection = row.TblLkpBrandSection, Code = row.TblLkpBrandSection1.Code, BrandCode = row.TblBrand, TblAuthUser = SelectedUser.Iserial, TblBrandSectionPermissions = row.TblLkpBrandSection1.TblBrandSectionPermissions }; BrandSectionList.Add(newrow); } GetBrandSectionPerUser(); }; Client.GetUserSpectialPermissionsAsync(); Client.GetUserSpectialPermissionsCompleted += (s, sv) => { foreach (var row in sv.Result) { PermissionList.Add(new TblUserBrandSectionPermissionViewModel { TblAuthPermission = row.Iserial, Ename = row.Ename, }); } }; Client.GetTblUserBrandSectionPermissionCompleted += (s, sv) => { foreach (var row in PermissionList) { row.UpdatedAllowed = false; row.Retail = row.Technical = row.Financial = row.RetailEnabled = row.TechnicalEnabled = row.FinancialEnabled = row.Checked = false; var brandSectionPermissions = SelectedUserBrandSection.TblBrandSectionPermissions.SingleOrDefault( x => x.TblAuthPermission == row.TblAuthPermission && x.BrandCode == SelectedBrand.Brand_Code); var permissionRow = PermissionList.SingleOrDefault(x => x.TblAuthPermission == row.TblAuthPermission ); if (permissionRow != null) { if (brandSectionPermissions != null) { permissionRow.FinancialEnabled = brandSectionPermissions.Financial; permissionRow.TechnicalEnabled = brandSectionPermissions.Technical; permissionRow.RetailEnabled = brandSectionPermissions.Retail; } } } foreach (var row in sv.Result) { if (SelectedUserBrandSection != null) { var permissionRow = PermissionList.SingleOrDefault(x => x.TblAuthPermission == row.TblAuthPermission && SelectedUserBrandSection.Iserial == row.TblUserBrandSection ); if (permissionRow != null) { permissionRow.Checked = true; permissionRow.TblUserBrandSection = row.Iserial; permissionRow.Retail = row.Retail; permissionRow.Technical = row.Technical; permissionRow.Financial = row.Financial; } } } }; Client.GetTblUserBrandSectionCompleted += (s, sv) => { foreach (var row in BrandSectionList) { row.UpdatedAllowed = false; row.Checked = false; } foreach (var row in sv.Result) { var brandSectionRow = BrandSectionList.SingleOrDefault(x => x.TblLkpBrandSection == row.TblLkpBrandSection && x.TblAuthUser == row.TblAuthUser ); if (brandSectionRow != null) { brandSectionRow.Iserial = row.Iserial; brandSectionRow.Checked = true; } } }; }
public void ClearPermissionList() { PermissionList.Clear(); }
public void AddPermissionToList(int permissionID, string legalText) { PermissionList.Add(new Permission(permissionID, legalText)); }
public static bool HasPermission(this WebViewPage wvp, RoleAccessType roleAccessType, PermissionList code) { string username = wvp.GetCurrentUsername(); string permissionCode = code.ToString(); return(DependencyResolver.Current.GetService <IUserService>().HasPermission(username, roleAccessType, permissionCode));; }