public LicenseModel GetById(int id) { return(_context.Licenses.Where(x => x.Id == id).Select(x => new LicenseModel { Id = x.Id, IdClient = x.IdClients, ClientName = ClientClass.GetClientName(x.IdClients), IsActive = x.IsActive, Creation = x.Creation, IdApplication = x.IdApplication, PermissionsModel = PermissionClass.ConvertPermission(x.Permissions), Number = x.Number, AssignedVersion = x.AssignedVersion, Inclusion = x.Inclusion, IsActivated = x.IsActivated, IdentityNumber = x.IdentityNumber, Expiration = x.Expiration, ApplicationModel = ApplicationClass.ConvertPermission(x.Application) }).FirstOrDefault()); }
public IEnumerable <LicenseModel> GetLicensesModelByApplication(int idApp) { return(_context.Licenses.Where(x => x.IdApplication == idApp).Select(x => new LicenseModel() { Id = x.Id, IdClient = x.IdClients, ClientName = ClientClass.GetClientName(x.IdClients), IsActive = x.IsActive, Creation = x.Creation, IdApplication = x.IdApplication, PermissionsModel = PermissionClass.ConvertPermission(x.Permissions), Number = x.Number, AssignedVersion = x.AssignedVersion, Inclusion = x.Inclusion, IsActivated = x.IsActivated, IdentityNumber = x.IdentityNumber, Expiration = x.Expiration, ApplicationModel = ApplicationClass.ConvertPermission(x.Application) })); }
/// <summary> /// Load permission from files. /// </summary> /// <returns></returns> public async Task LoadPermissions() { if (!Directory.Exists("Permissions")) { Directory.CreateDirectory("Permissions"); } int succsess = 0; string[] paths = Directory.GetFiles("Permissions", "*.prm", SearchOption.AllDirectories); for (int i = 0; i < paths.Length; i++) { using (StreamReader reader = new StreamReader(paths[i])) { string name = Path.GetFileNameWithoutExtension(paths[i]); string file = await reader.ReadToEndAsync(); lexer.Lex(file.Split(new[] { Environment.NewLine, " " }, StringSplitOptions.None)); try { PermissionClass @class = PermissionClass.Parse(lexer, name); Permissions.Add(@class.Name, @class); succsess++; } catch (Exception e) { await Bot.LoggingManager.LogMessage(LogLevel.Warning, $"Unable to parse {name}.prm", "PermissionManager"); await Bot.LoggingManager.LogMessage(e, "PermissionManager"); } } } await Bot.LoggingManager.LogMessage(LogLevel.Message, $"Parsed {succsess}/{paths.Length} permission{(paths.Length == 1 ? "" : "s")} files.", "PermissionManager"); }
/// <summary> /// Checks whether the user has permission to export an object group to an OAR. /// </summary> /// <param name="user">The user</param> /// <param name="objGroup">The object group</param> /// <param name="filterContent">Which permissions to check: "C" = Copy, "T" = Transfer</param> /// <param name="permissionsModule">The scene's permissions module</param> /// <returns>Whether the user is allowed to export the object to an OAR</returns> private bool CanUserArchiveObject(UUID user, SceneObjectGroup objGroup, string filterContent, IPermissionsModule permissionsModule) { if (filterContent == null) { return(true); } if (permissionsModule == null) { return(true); // this shouldn't happen } // Check whether the user is permitted to export all of the parts in the SOG. If any // part can't be exported then the entire SOG can't be exported. bool permitted = true; //int primNumber = 1; foreach (SceneObjectPart obj in objGroup.Parts) { uint perm; PermissionClass permissionClass = permissionsModule.GetPermissionClass(user, obj); switch (permissionClass) { case PermissionClass.Owner: perm = obj.BaseMask; break; case PermissionClass.Group: perm = obj.GroupMask | obj.EveryoneMask; break; case PermissionClass.Everyone: default: perm = obj.EveryoneMask; break; } bool canCopy = (perm & (uint)PermissionMask.Copy) != 0; bool canTransfer = (perm & (uint)PermissionMask.Transfer) != 0; // Special case: if Everyone can copy the object then this implies it can also be // Transferred. // However, if the user is the Owner then we don't check EveryoneMask, because it seems that the mask // always (incorrectly) includes the Copy bit set in this case. But that's a mistake: the viewer // does NOT show that the object has Everyone-Copy permissions, and doesn't allow it to be copied. if (permissionClass != PermissionClass.Owner) { canTransfer |= (obj.EveryoneMask & (uint)PermissionMask.Copy) != 0; } bool partPermitted = true; if (filterContent.Contains("C") && !canCopy) { partPermitted = false; } if (filterContent.Contains("T") && !canTransfer) { partPermitted = false; } // If the user is the Creator of the object then it can always be included in the OAR bool creator = (obj.CreatorID.Guid == user.Guid); if (creator) { partPermitted = true; } //string name = (objGroup.PrimCount == 1) ? objGroup.Name : string.Format("{0} ({1}/{2})", obj.Name, primNumber, objGroup.PrimCount); //m_log.DebugFormat("[ARCHIVER]: Object permissions: {0}: Base={1:X4}, Owner={2:X4}, Everyone={3:X4}, permissionClass={4}, checkPermissions={5}, canCopy={6}, canTransfer={7}, creator={8}, permitted={9}", // name, obj.BaseMask, obj.OwnerMask, obj.EveryoneMask, // permissionClass, checkPermissions, canCopy, canTransfer, creator, partPermitted); if (!partPermitted) { permitted = false; break; } //++primNumber; } return(permitted); }
/// <summary> /// Checks whether the user has permission to export an object group to an OAR. /// </summary> /// <param name="user">The user</param> /// <param name="objGroup">The object group</param> /// <param name="checkPermissions">Which permissions to check: "C" = Copy, "T" = Transfer</param> /// <returns>Whether the user is allowed to export the object to an OAR</returns> private bool CanUserArchiveObject(UUID user, ISceneEntity objGroup, string checkPermissions) { if (checkPermissions == null) { return(true); } IPermissionsModule module = m_scene.RequestModuleInterface <IPermissionsModule>(); if (module == null) { return(true); // this shouldn't happen } // Check whether the user is permitted to export all of the parts in the SOG. If any // part can't be exported then the entire SOG can't be exported. bool permitted = true; foreach (ISceneChildEntity obj in objGroup.ChildrenEntities()) { uint perm; PermissionClass permissionClass = module.GetPermissionClass(user, obj); switch (permissionClass) { case PermissionClass.Owner: perm = obj.BaseMask; break; case PermissionClass.Group: perm = obj.GroupMask | obj.EveryoneMask; break; case PermissionClass.Everyone: default: perm = obj.EveryoneMask; break; } bool canCopy = (perm & (uint)PermissionMask.Copy) != 0; bool canTransfer = (perm & (uint)PermissionMask.Transfer) != 0; // Special case: if Everyone can copy the object then this implies it can also be // Transferred. // However, if the user is the Owner then we don't check EveryoneMask, because it seems that the mask // always (incorrectly) includes the Copy bit set in this case. But that's a mistake: the viewer // does NOT show that the object has Everyone-Copy permissions, and doesn't allow it to be copied. if (permissionClass != PermissionClass.Owner) { canTransfer |= (obj.EveryoneMask & (uint)PermissionMask.Copy) != 0; } bool partPermitted = true; if (checkPermissions.Contains("C") && !canCopy) { partPermitted = false; } if (checkPermissions.Contains("T") && !canTransfer) { partPermitted = false; } //string name = (objGroup.PrimCount == 1) ? objGroup.Name : string.Format("{0} ({1}/{2})", obj.Name, primNumber, objGroup.PrimCount); //MainConsole.Instance.DebugFormat("[ARCHIVER]: Object permissions: {0}: Base={1:X4}, Owner={2:X4}, Everyone={3:X4}, permissionClass={4}, checkPermissions={5}, canCopy={6}, canTransfer={7}, permitted={8}", // name, obj.BaseMask, obj.OwnerMask, obj.EveryoneMask, // permissionClass, checkPermissions, canCopy, canTransfer, permitted); if (!partPermitted) { permitted = false; break; } } return(permitted); }
public ResponseModel <int> PostReturnId([FromBody] LicenseModel dataToAdd) { var resp = new ResponseModel <int>(); try { if (dataToAdd is null) { resp.Data = 0; resp.Status = 500; resp.Description = "Data is null"; return(resp); } var licenseClass = new LicenseClass { LicenseRepository = AppRepo, PermissionsRepository = PermissionsRepository }; var validate = licenseClass.ValidateLicenseAdd(dataToAdd); if (validate != null) { resp.Data = 0; resp.Status = 500; resp.Description = validate.Message; return(resp); } var licNumber = licenseClass.GetNewLicenseString(); if (string.IsNullOrEmpty(licNumber)) { throw new Exception("Number can't be generate"); } var model = new Licenses { Creation = DateTime.Now, IdClients = dataToAdd.IdClient, IsActive = dataToAdd.IsActive, AssignedVersion = dataToAdd.AssignedVersion, Expiration = dataToAdd.Expiration, IdApplication = dataToAdd.IdApplication, IdentityNumber = dataToAdd.IdentityNumber, Inclusion = dataToAdd.Inclusion, IsActivated = dataToAdd.IsActivated, Number = licNumber, Permissions = PermissionClass.ConvertPermission(dataToAdd.PermissionsModel) }; if (AppRepo.Insert(model)) { if (model.Permissions != null) { if (!licenseClass.InsertPermissions(model)) { throw new Exception("Error in insert permissions"); } } resp.Data = model.Id; resp.Status = 200; resp.Description = "OK"; return(resp); } throw new Exception("Unkown insert error"); } catch (Exception ex) { resp.Status = 500; resp.Description = $"Error: {ex.Message}"; resp.Data = 0; return(resp); } }