Skip to content

Commit

Permalink
Merged in makepublic-fix (pull request #6)
Browse files Browse the repository at this point in the history
Filegroup makepublic fixes and test case.
  • Loading branch information
Shashank Agrawal committed Feb 29, 2016
2 parents 4440884 + 19d9a23 commit 18cac16
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
40 changes: 40 additions & 0 deletions grails-app/conf/Config.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2011, CauseCode Technologies Pvt Ltd, India.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are not permitted.
*/

import com.lucastex.grails.fileuploader.CDNProvider
import com.lucastex.grails.fileuploader.util.Time

fileuploader {
AmazonKey = "RANDOM_KEY"
AmazonSecret = "RANDOM_SECRET"
persistence.provider = "mongodb"
user {
maxSize = 1024 * 1024 * 2 // 2 MB
allowedExtensions = ["jpg","jpeg","gif","png"]
storageTypes = "CDN"
container = "causecode-1"
provider = CDNProvider.AMAZON
makePublic = true
}
image {
maxSize = 1024 * 1024 * 2 // 2 MB
allowedExtensions = ["jpg","jpeg","gif","png"]
storageTypes = "CDN"
container = "causecode-1"
provider = CDNProvider.AMAZON
expirationPeriod = Time.DAY * 365
}
profile {
maxSize = 1024 * 1024 * 2 // 2 MB
allowedExtensions = ["jpg","jpeg","gif","png"]
storageTypes = "CDN"
container = "causecode-1"
provider = CDNProvider.AMAZON
expirationPeriod = Time.DAY * 365
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,6 @@ class FileUploaderService {
* @author Priyanshu Chauhan
*/
Boolean isPublicGroup(String fileGroup) {
return Holders.getFlatConfig()["fileuploader.$fileGroup"] ? true : false
return Holders.getFlatConfig()["fileuploader.${fileGroup}.makePublic"] ? true : false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ class AmazonCDNFileUploaderImpl extends CDNFileUploader {
CannedAccessPolicy cannedAccessPolicy = makePublic ? CannedAccessPolicy.PUBLIC_READ : CannedAccessPolicy.PRIVATE
copyObjectOptions.overrideAcl(cannedAccessPolicy)

// Copying the same file with the same name to the location so that we can override the previous file with new meta data.
client.copyObject(containerName, fileName, containerName, fileName, copyObjectOptions)
try {
// Copying the same file with the same name to the location so that we can override the previous file with new meta data.
client.copyObject(containerName, fileName, containerName, fileName, copyObjectOptions)
} catch(KeyNotFoundException) {
log.info("Blob cannot be located in the container for file $fileName.")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2011, CauseCode Technologies Pvt Ltd, India.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are not permitted.
*/

package com.lucastex.grails.fileuploader

import grails.test.mixin.TestFor
import grails.test.mixin.TestMixin
import grails.test.mixin.support.GrailsUnitTestMixin
import org.codehaus.groovy.grails.plugins.codecs.HTMLCodec
import spock.lang.Specification

@TestFor(FileUploaderService)
@TestMixin(GrailsUnitTestMixin)
class FileUploaderServiceSpec extends Specification {

void "test isPublicGroup for various file groups"() {
mockCodec(HTMLCodec)

expect: "Following conditions should pass"
service.isPublicGroup("user") == true
service.isPublicGroup("image") == false
service.isPublicGroup("profile") == false
service.isPublicGroup() == false
}
}

0 comments on commit 18cac16

Please sign in to comment.