Skip to content

Commit

Permalink
#13309 - Webdav - Uploading multiple files to a new folder throws uni…
Browse files Browse the repository at this point in the history
…que constraint exception
  • Loading branch information
acurionedotcms committed Jan 4, 2018
1 parent 66d4238 commit 74e9f4d
Showing 1 changed file with 61 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,7 @@ private void deletePermission(Permission p) {
}

@SuppressWarnings("unchecked")
private List<Permission> loadPermissions(Permissionable permissionable) throws DotDataException {
private synchronized List<Permission> loadPermissions(Permissionable permissionable) throws DotDataException {

if(permissionable == null || ! UtilMethods.isSet(permissionable.getPermissionId())){
throw new DotDataException("Invalid Permissionable passed in. permissionable:" + permissionable.getPermissionId());
Expand All @@ -2193,73 +2193,71 @@ private List<Permission> loadPermissions(Permissionable permissionable) throws D
}
//Check permission reference
if(bitPermissionsList == null || bitPermissionsList.isEmpty()) {
synchronized(permissionable.getPermissionId().intern()) {
//Need to determine who this asset should inherit from
String type = permissionable.getPermissionType();
if(permissionable instanceof Host ||
(permissionable instanceof Contentlet &&
((Contentlet)permissionable).getStructure() != null &&
((Contentlet)permissionable).getStructure().getVelocityVarName() != null &&
((Contentlet)permissionable).getStructure().getVelocityVarName().equals("Host"))){
type = Host.class.getCanonicalName();
} else if ( permissionable instanceof Contentlet &&
BaseContentType.FILEASSET.getType() == ((Contentlet) permissionable).getStructure().getStructureType()) {
type = Contentlet.class.getCanonicalName();
} else if ( permissionable instanceof IHTMLPage ||
(permissionable instanceof Contentlet && BaseContentType.HTMLPAGE.getType() == ((Contentlet) permissionable).getStructure().getStructureType())) {
type = IHTMLPage.class.getCanonicalName();
}else if(permissionable instanceof Event){
type = Contentlet.class.getCanonicalName();
}else if(permissionable instanceof Identifier){
Permissionable perm = InodeFactory.getInode(permissionable.getPermissionId(), Inode.class);
Logger.error(this, "PermissionBitFactoryImpl : loadPermissions Method : was passed an identifier. This is a problem. We will get inode as a fallback but this should be reported");
if(perm!=null){
if ( perm instanceof IHTMLPage ||
(perm instanceof Contentlet && BaseContentType.HTMLPAGE.getType() == ((Contentlet) perm).getStructure().getStructureType())) {
type = IHTMLPage.class.getCanonicalName();
}else if(perm instanceof Container){
type = Container.class.getCanonicalName();
}else if(perm instanceof Folder){
type = Folder.class.getCanonicalName();
}else if(perm instanceof Link){
type = Link.class.getCanonicalName();
}else if(perm instanceof Template){
type = Template.class.getCanonicalName();
} else if (perm instanceof Structure || perm instanceof ContentType) {
type = Structure.class.getCanonicalName();
}else if(perm instanceof Contentlet || perm instanceof Event){
type = Contentlet.class.getCanonicalName();
}
//Need to determine who this asset should inherit from
String type = permissionable.getPermissionType();
if(permissionable instanceof Host ||
(permissionable instanceof Contentlet &&
((Contentlet)permissionable).getStructure() != null &&
((Contentlet)permissionable).getStructure().getVelocityVarName() != null &&
((Contentlet)permissionable).getStructure().getVelocityVarName().equals("Host"))){
type = Host.class.getCanonicalName();
} else if ( permissionable instanceof Contentlet &&
BaseContentType.FILEASSET.getType() == ((Contentlet) permissionable).getStructure().getStructureType()) {
type = Contentlet.class.getCanonicalName();
} else if ( permissionable instanceof IHTMLPage ||
(permissionable instanceof Contentlet && BaseContentType.HTMLPAGE.getType() == ((Contentlet) permissionable).getStructure().getStructureType())) {
type = IHTMLPage.class.getCanonicalName();
}else if(permissionable instanceof Event){
type = Contentlet.class.getCanonicalName();
}else if(permissionable instanceof Identifier){
Permissionable perm = InodeFactory.getInode(permissionable.getPermissionId(), Inode.class);
Logger.error(this, "PermissionBitFactoryImpl : loadPermissions Method : was passed an identifier. This is a problem. We will get inode as a fallback but this should be reported");
if(perm!=null){
if ( perm instanceof IHTMLPage ||
(perm instanceof Contentlet && BaseContentType.HTMLPAGE.getType() == ((Contentlet) perm).getStructure().getStructureType())) {
type = IHTMLPage.class.getCanonicalName();
}else if(perm instanceof Container){
type = Container.class.getCanonicalName();
}else if(perm instanceof Folder){
type = Folder.class.getCanonicalName();
}else if(perm instanceof Link){
type = Link.class.getCanonicalName();
}else if(perm instanceof Template){
type = Template.class.getCanonicalName();
} else if (perm instanceof Structure || perm instanceof ContentType) {
type = Structure.class.getCanonicalName();
}else if(perm instanceof Contentlet || perm instanceof Event){
type = Contentlet.class.getCanonicalName();
}
}
}

if(permissionable instanceof Template && UtilMethods.isSet(((Template) permissionable).isDrawed()) && ((Template) permissionable).isDrawed()) {
type = TemplateLayout.class.getCanonicalName();
}
if(permissionable instanceof Template && UtilMethods.isSet(((Template) permissionable).isDrawed()) && ((Template) permissionable).isDrawed()) {
type = TemplateLayout.class.getCanonicalName();
}

if(permissionable instanceof NavResult) {
type = ((NavResult)permissionable).getEnclosingPermissionClassName();
}
if(permissionable instanceof NavResult) {
type = ((NavResult)permissionable).getEnclosingPermissionClassName();
}

Permissionable parentPermissionable = permissionable.getParentPermissionable();
Permissionable newReference = null;
List<Permission> inheritedPermissions = new ArrayList<Permission>();
while(parentPermissionable != null) {
newReference = parentPermissionable;
inheritedPermissions = getInheritablePermissions(parentPermissionable, type);
if(inheritedPermissions.size() > 0) {
break;
}
parentPermissionable = parentPermissionable.getParentPermissionable();
Permissionable parentPermissionable = permissionable.getParentPermissionable();
Permissionable newReference = null;
List<Permission> inheritedPermissions = new ArrayList<Permission>();
while(parentPermissionable != null) {
newReference = parentPermissionable;
inheritedPermissions = getInheritablePermissions(parentPermissionable, type);
if(inheritedPermissions.size() > 0) {
break;
}
HostAPI hostAPI = APILocator.getHostAPI();
if(newReference == null)
newReference = hostAPI.findSystemHost();
parentPermissionable = parentPermissionable.getParentPermissionable();
}
HostAPI hostAPI = APILocator.getHostAPI();
if(newReference == null)
newReference = hostAPI.findSystemHost();

deleteInsertPermission(permissionable, type, newReference);
deleteInsertPermission(permissionable, type, newReference);

bitPermissionsList = inheritedPermissions;
}
bitPermissionsList = inheritedPermissions;
}

Thread.currentThread().setName(threadName);
Expand All @@ -2269,7 +2267,7 @@ private List<Permission> loadPermissions(Permissionable permissionable) throws D
}

@WrapInTransaction
private void deleteInsertPermission(Permissionable permissionable, String type,
private synchronized void deleteInsertPermission(Permissionable permissionable, String type,
Permissionable newReference) throws DotDataException {

final String permissionId = permissionable.getPermissionId();
Expand All @@ -2291,6 +2289,8 @@ private void deleteInsertPermission(Permissionable permissionable, String type,
dc1.executeUpdate(DELETE_PERMISSIONABLE_REFERENCE_SQL, permissionId);

dc1.executeUpdate(INSERT_PERMISSION_REFERENCE_SQL, permissionId, newReference.getPermissionId(), type);

DbConnectionFactory.commit();
}

} catch(Exception exception){
Expand Down

0 comments on commit 74e9f4d

Please sign in to comment.