implement predefined circles usage
This commit is contained in:
3
Makefile
3
Makefile
@ -62,4 +62,5 @@ yavscd: src/Yavsc/bin/$(CONFIG)/dnx451/Yavsc.dll src/Yavsc.Server/bin/$(CONFIG)/
|
|||||||
version-increment-patch:
|
version-increment-patch:
|
||||||
scripts/version.sh $$(cat version.txt) patch > version.txt
|
scripts/version.sh $$(cat version.txt) patch > version.txt
|
||||||
|
|
||||||
sPHONY: packages
|
|
||||||
|
.PHONY: packages
|
||||||
|
@ -23,6 +23,11 @@ MINCSS=wwwroot/css/coiffure.min.css wwwroot/css/dev.min.css wwwroot/c
|
|||||||
web: project.lock.json
|
web: project.lock.json
|
||||||
MCS_OPTIONS=$(MCS_OPTIONS) MONO_OPTIONS=$(MONO_OPTIONS) ASPNET_LOG_LEVEL=$(ASPNET_LOG_LEVEL) ASPNET_ENV=$(ASPNET_ENV) dnx web --configuration=$(CONFIGURATION) |tee web.log
|
MCS_OPTIONS=$(MCS_OPTIONS) MONO_OPTIONS=$(MONO_OPTIONS) ASPNET_LOG_LEVEL=$(ASPNET_LOG_LEVEL) ASPNET_ENV=$(ASPNET_ENV) dnx web --configuration=$(CONFIGURATION) |tee web.log
|
||||||
|
|
||||||
|
|
||||||
|
start_debug:
|
||||||
|
ASPNET_ENV=Development mono --debugger-agent=transport=dt_socket,server=y,address=127.0.0.1:4669 /home/paul/.dnx/runtimes/dnx-mono.1.0.0-rc1-update2/bin/Microsoft.Dnx.Host.Mono.dll web
|
||||||
|
|
||||||
|
|
||||||
nweb:
|
nweb:
|
||||||
MONO_PATH=$(MONO_PATH):~/.dnx/runtimes/dnx-mono.1.0.0-rc1-update2/bin ~/.dnx/runtimes/dnx-mono.1.0.0-rc1-update2/bin/ndnx web
|
MONO_PATH=$(MONO_PATH):~/.dnx/runtimes/dnx-mono.1.0.0-rc1-update2/bin ~/.dnx/runtimes/dnx-mono.1.0.0-rc1-update2/bin/ndnx web
|
||||||
|
|
||||||
|
@ -7,11 +7,29 @@ using Microsoft.Extensions.Logging;
|
|||||||
using Microsoft.Extensions.OptionsModel;
|
using Microsoft.Extensions.OptionsModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using rules;
|
using rules;
|
||||||
|
using Microsoft.Data.Entity;
|
||||||
|
|
||||||
namespace Yavsc.Services
|
namespace Yavsc.Services
|
||||||
{
|
{
|
||||||
public class FileSystemAuthManager : IFileSystemAuthManager
|
public class FileSystemAuthManager : IFileSystemAuthManager
|
||||||
{
|
{
|
||||||
|
class BelongsToCircle : UserMatch
|
||||||
|
{
|
||||||
|
public override bool Match(string userId)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class OutOfCircle : UserMatch
|
||||||
|
{
|
||||||
|
public override bool Match(string userId)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UserMatch Out = new OutOfCircle();
|
||||||
|
UserMatch In = new BelongsToCircle();
|
||||||
|
|
||||||
readonly ApplicationDbContext _dbContext;
|
readonly ApplicationDbContext _dbContext;
|
||||||
readonly ILogger _logger;
|
readonly ILogger _logger;
|
||||||
|
|
||||||
@ -41,23 +59,41 @@ namespace Yavsc.Services
|
|||||||
if (parts.Length < 4) return FileAccessRight.None;
|
if (parts.Length < 4) return FileAccessRight.None;
|
||||||
|
|
||||||
var fileDir = string.Join("/", parts.Take(parts.Length - 1));
|
var fileDir = string.Join("/", parts.Take(parts.Length - 1));
|
||||||
|
var fileName = parts[parts.Length - 1];
|
||||||
|
|
||||||
|
|
||||||
var firstFileNamePart = parts[3];
|
var firstFileNamePart = parts[3];
|
||||||
if (firstFileNamePart == "pub")
|
if (firstFileNamePart == "pub" && aclfileName != fileName)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Serving public file.");
|
_logger.LogInformation("Serving public file.");
|
||||||
return FileAccessRight.Read;
|
return FileAccessRight.Read;
|
||||||
}
|
}
|
||||||
|
if (user == null) return FileAccessRight.None;
|
||||||
|
|
||||||
var funame = parts[2];
|
var funame = parts[2];
|
||||||
_logger.LogInformation($"Accessing {normalizedFullPath} from {funame}");
|
var cusername = user.GetUserName();
|
||||||
|
if (funame == cusername)
|
||||||
if (funame == user?.GetUserName())
|
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Serving file to owner.");
|
_logger.LogInformation("Serving file to owner.");
|
||||||
return FileAccessRight.Read | FileAccessRight.Write;
|
return FileAccessRight.Read | FileAccessRight.Write;
|
||||||
}
|
}
|
||||||
|
if (aclfileName == fileName)
|
||||||
|
return FileAccessRight.None;
|
||||||
|
|
||||||
|
_logger.LogInformation($"Access to {normalizedFullPath} for {cusername}");
|
||||||
|
|
||||||
ruleSetParser.Reset();
|
ruleSetParser.Reset();
|
||||||
|
var cuserid = user.GetUserId();
|
||||||
|
var fuserid = _dbContext.Users.Single(u => u.UserName == funame).Id;
|
||||||
|
var circles = _dbContext.Circle.Include(mb => mb.Members).Where(c => c.OwnerId == fuserid).ToArray();
|
||||||
|
foreach (var circle in circles)
|
||||||
|
{
|
||||||
|
if (circle.Members.Any(m => m.MemberId == cuserid))
|
||||||
|
ruleSetParser.Definitions.Add(circle.Name, In);
|
||||||
|
else ruleSetParser.Definitions.Add(circle.Name, Out);
|
||||||
|
}
|
||||||
|
|
||||||
|
// _dbContext.Circle.Select(c => c.OwnerId == )
|
||||||
for (int dirlevel = parts.Length - 1; dirlevel>0; dirlevel--)
|
for (int dirlevel = parts.Length - 1; dirlevel>0; dirlevel--)
|
||||||
{
|
{
|
||||||
var aclfi = new FileInfo(Path.Combine(Environment.CurrentDirectory, fileDir, aclfileName));
|
var aclfi = new FileInfo(Path.Combine(Environment.CurrentDirectory, fileDir, aclfileName));
|
||||||
|
Reference in New Issue
Block a user