public AccessRights Get(UserRole sub, FileObject obj) { if (sub == null) { return(AccessRights.None); } if (AccessMatrix.ContainsKey(sub.Id) && AccessMatrix[sub.Id].ContainsKey(obj.Id)) { return(AccessMatrix[sub.Id][obj.Id]); } else { return(AccessRights.None); } }
// не переделан под сессии public void Rename(FileObject file, string newName) { core.CheckAccess(file, AccessRights.Write); CheckFileName(newName); File.Move(Path.Combine(core.Root, file.Path), Path.Combine(core.Root, newName)); // простой установки имени не происходит // т.к. нужно, чтобы коллекция заметила изменения file.Path = newName; int i = Files.IndexOf(file); Files[i] = null; Files[i] = file; }
public void Write(FileObject file, string data) { core.CheckAccess(file, AccessRights.Write); string path = core.Sessions.GetPath(core.SessionId, file.Path); if (!File.Exists(path)) { // при изменении файла добавляем его в сессию, если он еще не там File.Copy(Path.Combine(core.Root, file.Path), path); } File.WriteAllText(path, data); core.Log.Info($"{core.CurrentUser} изменил файл {file}"); }
public void SetRights(UserRole role, AccessRights rights, FileObject obj) { if (!AccessMatrix.ContainsKey(role.Id)) { AccessMatrix.Add(role.Id, new Dictionary <int, AccessRights>() { { obj.Id, rights } }); } else if (!AccessMatrix[role.Id].ContainsKey(obj.Id)) { AccessMatrix[role.Id].Add(obj.Id, rights); } else { AccessMatrix[role.Id][obj.Id] = rights; } }
public HasNoRightsException(AccessRights rights, FileObject obj) : base($"Для доступа к \"{obj.ToString()}\" недостаточно следующих прав: {rights.ToString()}") { Object = obj; NeededRights = rights; }
public bool Can(UserRole sub, AccessRights rights, FileObject obj) { return(Get(sub, obj).HasFlag(rights)); }
public void CheckAccess(FileObject file, AccessRights rights) { //if (CurrentUser.Type != UserType.Admin) RMon.Check(CurrentUserRole, rights, file); }
public bool HasAccess(FileObject file, AccessRights rights) { //if (CurrentUser.Type == UserType.Admin) return true; return(RMon.Can(CurrentUserRole, rights, file)); }