How to restrict users from deleting a file + How to get back a deleted file?
Hi,
#1 - Is there a way to restrict users from being able to delete ANY files in component? I checked the "team configuration > Permissions" and it didn't have any.
#2 - Also, a user deleted a file and he doesn't recollect which component or workitem he used while deleting it. Is there a way to get this file back?
Please let me know.
2 answers
1. I don't think you can prevent the users to delete a file and check-in from his workspace, but you can prevent him deliver that change set to the stream by using "Restrict Changes by Item Name" pre-condition in "Deliver Phase 2 (server)" operation behavior.
2. To restore the file, you have to know from which component and change set you made the deletion, then discard or reverse the change set.
2. To restore the file, you have to know from which component and change set you made the deletion, then discard or reverse the change set.
This advisor code would be able to prevent delivery of deletions. It is from somewhere in the wiki.
You can search for deletions. In general I do think that deletion is common enough that people should be allowed to do them.
/******************************************************************************* * Licensed Materials - Property of IBM (c) Copyright IBM Corporation 2005-2012. * All Rights Reserved. * * Note to U.S. Government Users Restricted Rights: Use, duplication or * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. ******************************************************************************/ package advisor.example; import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; import com.ibm.team.process.common.IProcessConfigurationElement; import com.ibm.team.process.common.advice.AdvisableOperation; import com.ibm.team.process.common.advice.IAdvisorInfo; import com.ibm.team.process.common.advice.IAdvisorInfoCollector; import com.ibm.team.process.common.advice.runtime.IOperationAdvisor; import com.ibm.team.repository.common.IItemHandle; import com.ibm.team.repository.common.TeamRepositoryException; import com.ibm.team.repository.service.AbstractService; import com.ibm.team.repository.service.IItemServiceIterator; import com.ibm.team.repository.service.IRepositoryItemService; import com.ibm.team.repository.service.ItemServiceIteratorFactory; import com.ibm.team.scm.common.IChange; import com.ibm.team.scm.common.IChangeSet; import com.ibm.team.scm.common.IChangeSetHandle; import com.ibm.team.scm.common.IScmService; import com.ibm.team.scm.common.IVersionable; import com.ibm.team.scm.common.IVersionableHandle; import com.ibm.team.scm.common.dto.IAncestorReport; import com.ibm.team.scm.common.dto.INameItemPair; import com.ibm.team.scm.common.internal.dto.ServiceConfigurationProvider; import com.ibm.team.scm.common.process.DeliverOperationData; @SuppressWarnings("unchecked") public class RestrictDeliverOfDeletionsAdvisor extends AbstractService implements IOperationAdvisor { public void run(AdvisableOperation operation, IProcessConfigurationElement advisorConfiguration, IAdvisorInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException { Object operationData = operation.getOperationData(); if (!(operationData instanceof DeliverOperationData)) { return; } DeliverOperationData data = (DeliverOperationData) operationData; ListchangeSetHandles = data.getChangeSetHandles(); IRepositoryItemService itemService = getService(IRepositoryItemService.class); IScmService scmService = getService(IScmService.class); IItemServiceIterator changeSetIterator = ItemServiceIteratorFactory.INSTANCE.createFetchItemsIterator(itemService, changeSetHandles.toArray(new IItemHandle[changeSetHandles.size()]), IRepositoryItemService.COMPLETE); while (changeSetIterator.hasNext()) { IChangeSet changeSet = (IChangeSet) changeSetIterator.next(); if (changeSet == null) { // It's possible that we don't have read access to this change set? continue; } for (IChange change : (List ) changeSet.changes()) { if (change.kind() == IChange.DELETE) { IVersionableHandle versionableHandle = change.beforeState(); ServiceConfigurationProvider configProvider = ServiceConfigurationProvider.FACTORY.create( data.getDestWorkspace(), changeSet.getComponent()); IVersionable item = (IVersionable) scmService.fetchState(versionableHandle, null, null); IAncestorReport reports[] = scmService.configurationLocateAncestors( configProvider, new IVersionableHandle[] {versionableHandle}, null, null); IAdvisorInfo info = collector.createProblemInfo( "Deliver of deleted files is prohibited", "The file " + toFullPath(item, reports[0].getNameItemPairs()) + " is not allowed to be deleted.", "error"); collector.addInfo(info); } } } } private String toFullPath(IVersionable versionable, List segments) { StringBuffer path = new StringBuffer(); if(segments.isEmpty()) { return versionable.getName(); } for (INameItemPair nameItemPair : segments) { if(path.length() != 0) { path.append(Path.SEPARATOR); } // ignore the root folder which doesn't have a name if(nameItemPair.getName() != null) path.append(nameItemPair.getName()); } return path.toString(); } }