Mark
Mark

Reputation: 11

Is it possible to combine multiple baseDirs in one CKFinder view?

I would like to have a single CKFinder view that retrieves the content from two completely different source folders. Both folders will be the same resourceType, for example Images. The user would then also be able to drag files.

In my case, one folder would be a shared location, and the other would be a dynamic private folder based on the current user. I have already made the path dynamic by modifying the getBaseDir function in the ConfigurationPathBuilder but I have not been able to add both paths to the same CKFinder instance.

For instance, I would have the following three folders:

Would it be possible to have both the "C:/images/shared" folder and "C:/images/users/user1" folder in a single CKFinder view without exposing any other folders? Using C:/images as the baseDir would not be an option because it will include the users and user2 folders.

I'm currently using CKFinder2 but I would also accept answers for CKFinder3.

I have found the following resource but this would not work in my case since I also have different resourceTypes defined (like Documents) which I would also like to use in the same way:

https://ckeditor.com/old/forums/Support/How-can-I-provide-a-shared-folder

I have created a mock screenshot with my expectations, instead of having a single "Images" folder, there would be two folders, one for each source:

https://i.sstatic.net/OXC47.png

Upvotes: 1

Views: 535

Answers (1)

j.swiderski
j.swiderski

Reputation: 2445

Judging from your description it looks to me that you are using CKFinder 2.x for Java (I have heard they have CKFinder 3 for Java in Alpha stage at the moment so there is a chance new version will be released soon). If that is the case then here is how I see it:

Your directory structure should look as follows:

Userfiles
   adam
      files
      images
      flash
   joe
      files
      images
      flash
   …
   john
     files
      images
      flash
Public

Which after loading (E.g. for joe) into CKFinder should be visible as (Square Brackets is what you see in CKFinder and next to it is directory path):

(Userfiles == userfiles/joe)
[Files] -  /userfiles/joe/files/
[Images] -  /userfiles/joe/images/ 
[Flash] -  /userfiles/joe/flash/
[Public]  
[Basket]

The user private folder is treated as userfiles folder inside which you will have 3 default resource types: Files, Images, Flash and one new Public (you can remove the ones you don't need). Such approach works well when you are using CKFinder with CKEditor because you have the default resource type structure kept which CKfinder expects thus you don't need to make further adjustments.

Those resource types have to be defined in config file for CKFinder but you probably know that. Default resource types are already there but new ones have to be added.

The baseURL changes based on user credentials. It can be E.g. http://yourapp:8080/ckfinder/userfiles/joe or http://yourapp:8080/ckfinder/userfiles/john. In connectors like ASP.NET or PHP you can check user credentials and apply correct userfiles folder directly in config file e.g.

If( user.name.equals('joe') )
baseUrl = 'http://yourapp:8080/ckfinder/userfiles/' + request.get( ’joe’);

In Java you will need to use Pathbuilder for it: https://docs-old.ckeditor.com/CKFinder_2.x/Developers_Guide/Java/Configuration/Extending#Creating_a_Custom_PathBuilder_Class. You have to return correct baseUrl and baseDir based on session variables (user credentials).

You can also adjust ACL if necessary. Let's say you want to all full access to private folder and read-only access to pblic folder:

<accessControl>
 <role>*</role>
 <resourceType>*</resourceType>//Full access to any folder or file by default
 <folder>/</folder>
 <folderView>true</folderView>
 <folderCreate>true</folderCreate>
 <folderRename>true</folderRename>
 <folderDelete> true</folderDelete>
 <fileView>true</fileView>
 <fileUpload>true</fileUpload>
 <fileRename>true</fileRename>
 <fileDelete>true</fileDelete>
</accessControl>
<accessControl>
 <role>*</role>
 <resourceType>Public</resourceType> // Restricted access to Public resource type.
 <folder>/</folder>
 <folderView>true</folderView>
 <folderCreate> false </folderCreate>
 <folderRename>false</folderRename>
 <folderDelete>false</folderDelete>
 <fileView>true</fileView>
 <fileUpload> false </fileUpload>
 <fileRename> false </fileRename>
 <fileDelete> false </fileDelete>
</accessControl>

Please remember that CKFinder is merely an add-on to your application which makes decisions who and how can access CKFinder only based on data which comes from that application. All user configurations like ACL, mapping to appropriate user folder, his credentials and other CKFinder settings you wish to personalize should be kept in DB and loaded when user logs in. Next it is your application which has to put that data into e.g. session to allow CKFinder to read and apply it.

NOTE: When CKFinder is integrated with CKEditor it uses default resource types by default. This may cause problems with Public folder which is not default. It may be visible only for Link button but not for Images. There are two solutions here – you can have either limited access to public folder (only from link dialog) or show all folders no matter which button is pressed (by default only images folder is shown when CKFinder is invoked from Image dialog). For that second solution you will need manual integration method (where you will have to lose type parameter from URL) https://docs-old.ckeditor.com/CKFinder_2.x/Developers_Guide/Java/CKEditor_Integration#Manual_Integration

Upvotes: 0

Related Questions