Restricting access for adding file/folder in a particular level of directories under components & Streams
Hi Ralph,
Please help on the requirement.
I need to avoid user to add file/folder into second level of component under Streams.
Example:
- Project-Area
- Source Control
- Stream 1
- Stream 2
- Stream 3
- Component 1
- Component 2
- Component 3
- Folder 1
- File 1
- File 2
- Folder 2
- File 1
- File 2
I want to restrict user not to add file/folder under components, but they should have rights to add file / folder into next level.
Shall i do this using IVersionHandle or IAncestorReport?
Thanks !!!
Sudar
Accepted answer
I think you should use both, and others as well:
IVersionHandle versionableH = ...Cheers.
IWorkspaceHandle wksH = ...
IComponentHandle componentH = ...
ServiceConfigurationProvider configProvider = ServiceConfigurationProvider.FACTORY.create(wksH, componentH);
IAncestorReport[] reports = scmService.configurationLocateAncestors(configProvider, new IVersionableHandle[]{ versionableH }, null, IRepositoryProgressMonitor.ITEM_FACTORY.createItem(monitor));
List<INameItemPair> segments = reports[0].getNameItemPairs();
if (segments.size() != 3) { // segments[0] is for root folder and always null.
throw new TeamRepositoryException("You can only add files in to 2nd level folders");
}
Comments
Instead of throwing an exception you should probably create a IAdvisorInfo:
IAdvisorInfo problem = collector.createProblemInfo( "You can only add files in to 2nd level folders","You can only add files in to 2nd level folders","advisor.reject");
collector.addInfo(problem);
Sure you can, though it depends on where that snippet will be used.
Of-course... I should have noted that if the snippet was to be used in an advisor then createProblemInfo would be advisable :-)
Thank you Servizi !!!
Thank you Martin !!