ow
This commit is contained in:
1 parent
211d2cd253
commit
7fb4503e0e
27 files changed
+2218
-1202
No files matched your search
@@ -56,21 +56,28 @@ namespace CloudBuilder.Master.Service
|
||||
};
|
||||
|
||||
data.FamilyGroups = q.ToArray();
|
||||
if (publish.OwnerName != service.UserId && !YesNoPolicy.IsYes(publish.OpenIndc) && data.FamilyGroups.Length == 0)
|
||||
|
||||
IRepository<FamilyGroupManagerEntity> repositoryFamilyGroupManager = repository.GetRepository<IRepository<FamilyGroupManagerEntity>>();
|
||||
|
||||
//归属与群组身份:所有者全权;群管理员可删/改信息;群成员仅可改明细
|
||||
data.IsOwner = publish.OwnerName == service.UserId;
|
||||
data.IsMember = data.IsOwner;
|
||||
data.IsManager = data.IsOwner;
|
||||
if (!data.IsOwner && data.FamilyGroups.Length > 0)
|
||||
{
|
||||
string[] familyNames = data.FamilyGroups.Select(x => x.FamilyName).ToArray();
|
||||
FamilyGroupManagerEntity[] mine = repositoryFamilyGroupManager.DetachedEntities
|
||||
.Where(x => x.UserName == service.UserId && x.ValidIndc == YesNoPolicy.YES && familyNames.Contains(x.FamilyName))
|
||||
.ToArray();
|
||||
|
||||
data.IsMember = mine.Length > 0;
|
||||
data.IsManager = mine.Any(x => x.ManagerIndc == YesNoPolicy.YES);
|
||||
}
|
||||
|
||||
if (!data.IsOwner && !YesNoPolicy.IsYes(publish.OpenIndc) && !data.IsMember)
|
||||
{
|
||||
throw new ValidatedException("没有权限.");
|
||||
}
|
||||
else if (publish.OwnerName != service.UserId && !YesNoPolicy.IsYes(publish.OpenIndc) && data.FamilyGroups.Length > 0)
|
||||
{
|
||||
IRepository<FamilyGroupManagerEntity> repositoryFamilyGroupManager = repository.GetRepository<IRepository<FamilyGroupManagerEntity>>();
|
||||
|
||||
IQueryable<string>? fgm = from e in repositoryFamilyGroupManager.DetachedEntities
|
||||
where e.UserName == service.UserId && data.FamilyGroups.Where(x => x.FamilyName == e.FamilyName).Count() > 0
|
||||
select e.UserName;
|
||||
|
||||
if (fgm.Count() == 0)
|
||||
throw new ValidatedException("没有权限.");
|
||||
}
|
||||
|
||||
data.PublishPhoto = publish;
|
||||
|
||||
@@ -215,21 +222,68 @@ namespace CloudBuilder.Master.Service
|
||||
[UnitOfWork]
|
||||
public PublishPhotoData Update(PublishPhotoData data)
|
||||
{
|
||||
//只有自己创建的才能修改
|
||||
PublishPhotoEntity publishEntity = repository.DetachedEntities.Where(x => x.OwnerName == service.UserId && x.PublishName == data.PublishPhoto.PublishName).FirstOrDefault();
|
||||
if (publishEntity == null)
|
||||
//归属校验:所有者可全改;公开群组管理员可改信息/群组;普通群成员只能改明细
|
||||
PublishPhotoEntity original = repository.DetachedEntities.Where(x => x.PublishName == data.PublishPhoto.PublishName).FirstOrDefault();
|
||||
if (original == null)
|
||||
{
|
||||
throw new ValidatedException("记录不存在.");
|
||||
}
|
||||
|
||||
bool isOwner = original.OwnerName == service.UserId;
|
||||
bool isManager = false;
|
||||
bool isMember = false;
|
||||
if (!isOwner)
|
||||
{
|
||||
IRepository<PublishPhotoFamilyGroupEntity> repositoryPublishPhotoFamilyGroup = repository.GetRepository<IRepository<PublishPhotoFamilyGroupEntity>>();
|
||||
IRepository<FamilyGroupManagerEntity> repositoryFamilyGroupManager = repository.GetRepository<IRepository<FamilyGroupManagerEntity>>();
|
||||
|
||||
string[] familyNames = repositoryPublishPhotoFamilyGroup.DetachedEntities
|
||||
.Where(x => x.PublishName == original.PublishName)
|
||||
.Select(x => x.FamilyName)
|
||||
.ToArray();
|
||||
if (familyNames.Length == 0)
|
||||
{
|
||||
throw new ValidatedException("没有权限.");
|
||||
}
|
||||
|
||||
FamilyGroupManagerEntity[] mine = repositoryFamilyGroupManager.DetachedEntities
|
||||
.Where(x => x.UserName == service.UserId && x.ValidIndc == YesNoPolicy.YES && familyNames.Contains(x.FamilyName))
|
||||
.ToArray();
|
||||
isMember = mine.Length > 0;
|
||||
isManager = mine.Any(x => x.ManagerIndc == YesNoPolicy.YES);
|
||||
if (!isMember)
|
||||
{
|
||||
throw new ValidatedException("没有权限.");
|
||||
}
|
||||
}
|
||||
|
||||
//非所有者保留归属与建单信息,防客户端伪造
|
||||
data.PublishPhoto.OwnerName = original.OwnerName;
|
||||
data.PublishPhoto.CreatedBy = original.CreatedBy;
|
||||
data.PublishPhoto.CreatedDatetime = original.CreatedDatetime;
|
||||
if (!isOwner && !isManager)
|
||||
{
|
||||
//非所有者且非管理员(普通群成员)只能改明细:专辑展示字段一律以库中为准
|
||||
data.PublishPhoto.PublishLocalName = original.PublishLocalName;
|
||||
data.PublishPhoto.Notice = original.Notice;
|
||||
data.PublishPhoto.OpenIndc = original.OpenIndc;
|
||||
data.PublishPhoto.ExpireDatetime = original.ExpireDatetime;
|
||||
data.PublishPhoto.OrderBy = original.OrderBy;
|
||||
}
|
||||
if (!isOwner)
|
||||
{
|
||||
//默认专辑是所有者个人偏好,群管理员也不能改
|
||||
data.PublishPhoto.DefaultIndc = original.DefaultIndc;
|
||||
}
|
||||
|
||||
ValidateHelper.Validate(service, data.PublishPhoto, PublishPhotoEntity.DB_NAME_PUBLISH_PHOTO);
|
||||
|
||||
if (data.PublishPhoto.DefaultIndc == YesNoPolicy.YES)
|
||||
if (isOwner && data.PublishPhoto.DefaultIndc == YesNoPolicy.YES)
|
||||
{
|
||||
CancelDefaultIndc(data.PublishPhoto.PublishName);
|
||||
}
|
||||
|
||||
publishEntity = new PublishPhotoEntity();
|
||||
PublishPhotoEntity publishEntity = new PublishPhotoEntity();
|
||||
ObjectCopyHelper.Copy(data.PublishPhoto, publishEntity);
|
||||
|
||||
repository.UpdateNow(publishEntity);
|
||||
@@ -237,11 +291,34 @@ namespace CloudBuilder.Master.Service
|
||||
//只有删除和更新,没有插入
|
||||
SavePublishPhotoDetails(publishEntity.PublishName, data.Details);
|
||||
|
||||
SavePublishPhotoFamilyGroup(publishEntity.PublishName, data.FamilyGroups);
|
||||
//群组增删只对所有者/群管理员开放;普通成员提交的 FamilyGroups 不落库
|
||||
if (isOwner || isManager)
|
||||
{
|
||||
SavePublishPhotoFamilyGroup(publishEntity.PublishName, data.FamilyGroups);
|
||||
}
|
||||
|
||||
return FindByKey(publishEntity.PublishName);
|
||||
}
|
||||
|
||||
/// <summary>当前登录人是否为该相册任一公开群组的管理员(正式成员且 ManagerIndc=Y)</summary>
|
||||
private bool IsGroupManagerOfPublish(string publishName)
|
||||
{
|
||||
IRepository<PublishPhotoFamilyGroupEntity> repositoryFamilyGroup = repository.GetRepository<IRepository<PublishPhotoFamilyGroupEntity>>();
|
||||
IRepository<FamilyGroupManagerEntity> repositoryFamilyGroupManager = repository.GetRepository<IRepository<FamilyGroupManagerEntity>>();
|
||||
|
||||
string[] familyNames = repositoryFamilyGroup.DetachedEntities
|
||||
.Where(x => x.PublishName == publishName)
|
||||
.Select(x => x.FamilyName)
|
||||
.ToArray();
|
||||
if (familyNames.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return repositoryFamilyGroupManager.DetachedEntities
|
||||
.Any(x => x.UserName == service.UserId && x.ValidIndc == YesNoPolicy.YES && x.ManagerIndc == YesNoPolicy.YES && familyNames.Contains(x.FamilyName));
|
||||
}
|
||||
|
||||
private void SavePublishPhotoFamilyGroup(string publishName, PublishPhotoFamilyGroupEntity[] familyGroups)
|
||||
{
|
||||
IRepository<PublishPhotoFamilyGroupEntity> repositoryPublishPhotoFamilyGroup = repository.GetRepository<IRepository<PublishPhotoFamilyGroupEntity>>();
|
||||
@@ -317,11 +394,16 @@ namespace CloudBuilder.Master.Service
|
||||
[UnitOfWork]
|
||||
public void Delete(string key)
|
||||
{
|
||||
PublishPhotoEntity publishEntity = repository.DetachedEntities.Where(x => x.OwnerName == service.UserId && x.PublishName == key).FirstOrDefault();
|
||||
PublishPhotoEntity publishEntity = repository.DetachedEntities.Where(x => x.PublishName == key).FirstOrDefault();
|
||||
if (publishEntity == null)
|
||||
{
|
||||
throw new ValidatedException("记录不存在.");
|
||||
}
|
||||
//删除相册:所有者或该相册任一公开群组的管理员
|
||||
if (publishEntity.OwnerName != service.UserId && !IsGroupManagerOfPublish(key))
|
||||
{
|
||||
throw new ValidatedException("没有权限.");
|
||||
}
|
||||
|
||||
repository.DeleteNow(publishEntity);
|
||||
|
||||
|
||||
Reference in new issue
Block a user