Prevent changes on certain folders - by certain users
Hi All,
I want to restrict access on certain folders to particular users alone. I am doing a server plugin for this. I need the below:
1. Stream name - to which deliver is happening
2. Folder name - Lowest-level and the parent folders involved + filename
3. contributor name
How to get the path and stream details using server plugin? i tried using com.ibm.team.filesystem - but fails as its related to client plugin only...
Please advise and share any relevant codes or ideas that you have
Thanks..
3 answers
I think you are talking about an advisor on the delivery operation.
In this case the operation.getOperationData() is an instance of DeliverOperationData. With this object you can retrieve the source and the target workspaces or streams (which are the same type of object) and the change-set.
Then, for every change-set, you can get the single change. The path is more difficult to be obtained, but you can get it using IScmService.configurationLocateAncestors method and then cycling through the tree path.
Michele.
Comments
showing 5 of 6
show 1 more comments
You shouldn't use the stream name to check if the stream is what you want. You should use the stream's UUID. You can get that using IWorkspace.getItemId(). This prevents your advisor from misbehaving when the stream's name changes or another stream is created with the same name. To set the UUID properly, you should create an aspect editor that allows clients to configure the advisor.
You should be running on the "com.ibm.team.scm.service.changehistory.modification" operation. That's "Deliver (phase 2)" which is more appropriate to what you're trying to do. You can walk over the changes by looking at the update report:
<pre>public void run(AdvisableOperation operation, IProcessConfigurationElement advisorConfiguration, IAdvisorInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
IScmDeltaSource deltaSource = (IScmDeltaSource) operationData;
IScmItemService scmItemService = getService(IScmItemService.class);
for (IChangeHistoryModificationDelta mod : deltaSource.getDeltas(IChangeHistoryModificationDelta.class)) {
IUpdateReport updateReport = mod.getUpdateReport();
for (IComponentHandle comp : updateReport.getAffectedComponents()) {
Collection<IItemUpdateReport> updatesForComponent = updateReport.getUpdatesForComponent(comp);
//...</pre>
IScmDeltaSource deltaSource = (IScmDeltaSource) operationData;
IScmItemService scmItemService = getService(IScmItemService.class);
for (IChangeHistoryModificationDelta mod : deltaSource.getDeltas(IChangeHistoryModificationDelta.class)) {
IUpdateReport updateReport = mod.getUpdateReport();
for (IComponentHandle comp : updateReport.getAffectedComponents()) {
Collection<IItemUpdateReport> updatesForComponent = updateReport.getUpdatesForComponent(comp);
//...</pre>
To check the location of the versionable in the hierarchy, you should query the IScmService.configurationLocateAncestors() for each of the changed items (listed in the IUpdateReport) to see if they are descendants of the versionables you care about. Note that new items won't exist in the configuration, and that items that have been moved may have been moved under newly created items.
Hi All,
I have implemented this plugin and it works fine for modify/delete as there is a before and an after state. sample code that i used to get the path is as below:
for (IChange change : (List<IChange>) changeSet.changes()) {
ServiceConfigurationProvider configProvider = ServiceConfigurationProvider.FACTORY.create(data.getDestWorkspace(), changeSet.getComponent());
IVersionableHandle versionableHandle = change.beforeState();
IVersionable item = (IVersionable) scmService.fetchState(versionableHandle, null, null);
IAncestorReport reports[] = scmService.configurationLocateAncestors(
configProvider, new IVersionableHandle[] {versionableHandle}, null, null);
String Path = toFullPath(item, reports[0].getNameItemPairs());
but in case of add operation, the value of versionableHandle is null and so the above code does not work. Could you please suggest how this can be achieved for an add operation?
M
I have implemented this plugin and it works fine for modify/delete as there is a before and an after state. sample code that i used to get the path is as below:
for (IChange change : (List<IChange>) changeSet.changes()) {
ServiceConfigurationProvider configProvider = ServiceConfigurationProvider.FACTORY.create(data.getDestWorkspace(), changeSet.getComponent());
IVersionableHandle versionableHandle = change.beforeState();
IVersionable item = (IVersionable) scmService.fetchState(versionableHandle, null, null);
IAncestorReport reports[] = scmService.configurationLocateAncestors(
configProvider, new IVersionableHandle[] {versionableHandle}, null, null);
String Path = toFullPath(item, reports[0].getNameItemPairs());
but in case of add operation, the value of versionableHandle is null and so the above code does not work. Could you please suggest how this can be achieved for an add operation?
M
Comments
David Olsen
JAZZ DEVELOPER Jun 21 '12, 11:45 a.m.VK L
Jun 22 '12, 11:36 a.m.VK L
Jul 02 '12, 10:00 a.m.