DeleteWatchedProjects: Don't fail on delete of non-existing watch

The DeleteWatchedProjects REST endpoint no longer fails if a user
tries to delete a non-existing project watch. This change is done
because it simplifies the implementation when project watches are
stored in git. This change should have almost no impact on users of
this REST endpoint.

Change-Id: I17426d338a7d0a8d2412173d71713ec07f448f66
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2016-07-08 11:50:07 +02:00
parent aa0c08238e
commit ded97ccb90
2 changed files with 4 additions and 6 deletions

View File

@@ -111,7 +111,7 @@ public class WatchedProjectsIT extends AbstractDaemonTest {
}
@Test
public void deleteNonExistingProject() throws Exception {
public void deleteNonExistingProjectWatch() throws Exception {
String projectName = project.get();
// Let another user watch a project
@@ -131,8 +131,8 @@ public class WatchedProjectsIT extends AbstractDaemonTest {
List<ProjectWatchInfo> d = Lists.newArrayList(pwi);
gApi.accounts().self().deleteWatchedProjects(d);
// Check that trying to delete a non-existing watch doesn't fail
setApiUser(user);
exception.expect(UnprocessableEntityException.class);
gApi.accounts().self().deleteWatchedProjects(d);
}

View File

@@ -75,11 +75,9 @@ public class DeleteWatchedProjects
for (ProjectWatchInfo projectInfo : input) {
AccountProjectWatch.Key key = new AccountProjectWatch.Key(accountId,
new Project.NameKey(projectInfo.project), projectInfo.filter);
if (!watchedProjectsMap.containsKey(key)) {
throw new UnprocessableEntityException(projectInfo.project
+ " is not currently watched by this user.");
if (watchedProjectsMap.containsKey(key)) {
watchesToDelete.add(watchedProjectsMap.get(key));
}
watchesToDelete.add(watchedProjectsMap.get(key));
}
dbProvider.get().accountProjectWatches().delete(watchesToDelete);
accountCache.evict(accountId);