import org.sonar.core.issue.db.IssueFilterFavouriteDao;
import org.sonar.core.issue.db.IssueFilterFavouriteDto;
import org.sonar.core.permission.Permission;
-import org.sonar.core.user.AuthorizationDao;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
private final IssueFilterDao filterDao;
private final IssueFilterFavouriteDao favouriteDao;
private final IssueFinder finder;
- private final AuthorizationDao authorizationDao;
private final IssueFilterSerializer serializer;
- public IssueFilterService(IssueFilterDao filterDao, IssueFilterFavouriteDao favouriteDao, IssueFinder finder, AuthorizationDao authorizationDao,
+ public IssueFilterService(IssueFilterDao filterDao, IssueFilterFavouriteDao favouriteDao, IssueFinder finder,
IssueFilterSerializer serializer) {
this.filterDao = filterDao;
this.favouriteDao = favouriteDao;
this.finder = finder;
- this.authorizationDao = authorizationDao;
this.serializer = serializer;
}
import org.mockito.ArgumentCaptor;
import org.sonar.api.issue.IssueFinder;
import org.sonar.api.issue.IssueQuery;
-import org.sonar.api.web.UserRole;
import org.sonar.core.issue.DefaultIssueFilter;
import org.sonar.core.issue.IssueFilterSerializer;
import org.sonar.core.issue.db.IssueFilterDao;
import org.sonar.core.issue.db.IssueFilterFavouriteDao;
import org.sonar.core.issue.db.IssueFilterFavouriteDto;
import org.sonar.core.permission.Permission;
-import org.sonar.core.user.AuthorizationDao;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
private IssueFilterDao issueFilterDao;
private IssueFilterFavouriteDao issueFilterFavouriteDao;
private IssueFinder issueFinder;
- private AuthorizationDao authorizationDao;
private IssueFilterSerializer issueFilterSerializer;
private UserSession userSession;
issueFilterDao = mock(IssueFilterDao.class);
issueFilterFavouriteDao = mock(IssueFilterFavouriteDao.class);
issueFinder = mock(IssueFinder.class);
- authorizationDao = mock(AuthorizationDao.class);
issueFilterSerializer = mock(IssueFilterSerializer.class);
- service = new IssueFilterService(issueFilterDao, issueFilterFavouriteDao, issueFinder, authorizationDao, issueFilterSerializer);
+ service = new IssueFilterService(issueFilterDao, issueFilterFavouriteDao, issueFinder, issueFilterSerializer);
}
@Test
@Test
public void should_not_update_if_shared_and_not_admin() {
- when(authorizationDao.selectGlobalPermissions("john")).thenReturn(newArrayList(UserRole.USER));
+ UserSession userSession = MockUserSession.create().setLogin("john").setPermissions();
when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Old Filter").setUserLogin("arthur").setShared(true));
try {
String currentUser = "dave.loper";
IssueFilterDto sharedFilter = new IssueFilterDto().setId(1L).setName("My filter").setUserLogin(currentUser).setShared(true);
- when(authorizationDao.selectGlobalPermissions(currentUser)).thenReturn(newArrayList(Permission.DRY_RUN_EXECUTION.key()));
+ UserSession userSession = MockUserSession.create().setLogin(currentUser).setUserId(1).setPermissions();
when(issueFilterDao.selectById(1L)).thenReturn(sharedFilter);
try {
DefaultIssueFilter issueFilter = new DefaultIssueFilter().setId(1L).setName("My filter").setShared(true).setUser("new.owner");
- service.update(issueFilter, MockUserSession.create().setUserId(1).setLogin(currentUser));
+ service.update(issueFilter, userSession);
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage("User is not authorized to change the owner of this filter");
@Test
public void should_not_delete_not_shared_filter_if_user_is_admin() {
- when(authorizationDao.selectGlobalPermissions("john")).thenReturn(newArrayList(Permission.SYSTEM_ADMIN.key()));
+ UserSession userSession = MockUserSession.create().setLogin("john").setUserId(1).setPermissions(Permission.SYSTEM_ADMIN);
when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("arthur").setShared(false));
try {
@Test
public void should_not_delete_shared_filter_if_not_admin() {
- when(authorizationDao.selectGlobalPermissions("john")).thenReturn(newArrayList(UserRole.USER));
+ UserSession userSession = MockUserSession.create().setLogin("john").setUserId(1).setPermissions();
when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("arthur").setShared(true));
try {