* If a resource ID is passed, the search is made on users who have specifically subscribed for the given resource.
*
* @param notificationDispatcherKey the key of the notification dispatcher
- * @param notificationChannelKey the key of the notification channel
- * @param resourceId the resource id
+ * @param notificationChannelKey the key of the notification channel
+ * @param resourceId the resource id
* @return the list of logins (maybe be empty - obviously)
*/
public List<String> findUsersForNotification(String notificationDispatcherKey, String notificationChannelKey, @Nullable Long resourceId) {
}
}
+ public void deleteProjectProperty(String key, Long projectId) {
+ SqlSession session = mybatis.openSession();
+ PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
+ try {
+ mapper.deleteProjectProperty(key, projectId);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
public void deleteGlobalProperties() {
SqlSession session = mybatis.openSession();
PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
void insert(PropertyDto property);
+ void deleteProjectProperty(@Param("key") String key, @Param("rId") Long resourceId);
+
void deleteGlobalProperty(String key);
void deleteAllProperties(String key);
VALUES (#{key}, #{resourceId}, #{userId}, #{value})
</insert>
+ <delete id="deleteProjectProperty" parameterType="map">
+ delete from properties where prop_key=#{key} and resource_id=#{rId} and user_id is null
+ </delete>
+
<delete id="deleteGlobalProperty" parameterType="string">
delete from properties where prop_key=#{id} and resource_id is null and user_id is null
</delete>
checkTables("insert", "properties");
}
+ @Test
+ public void delete_project_property() {
+ setupData("delete_project_property");
+
+ dao.deleteProjectProperty("struts.one", 10L);
+
+ checkTables("delete_project_property", "properties");
+ }
+
@Test
public void deleteGlobalProperties() {
setupData("deleteGlobalProperties");
--- /dev/null
+<dataset>
+
+ <!-- global -->
+ <properties id="1" prop_key="global.one" text_value="one" resource_id="[null]" user_id="[null]"/>
+ <properties id="2" prop_key="global.two" text_value="two" resource_id="[null]" user_id="[null]"/>
+
+ <!-- struts -->
+ <!--<properties id="3" prop_key="struts.one" text_value="one" resource_id="10" user_id="[null]"/>-->
+
+ <!-- commons -->
+ <properties id="4" prop_key="commonslang.one" text_value="two" resource_id="11" user_id="[null]"/>
+
+ <!-- user -->
+ <properties id="5" prop_key="user.one" text_value="one" resource_id="[null]" user_id="100"/>
+ <properties id="6" prop_key="user.two" text_value="two" resource_id="10" user_id="100"/>
+
+ <properties id="7" prop_key="commonslang.one" text_value="one" resource_id="12" user_id="[null]"/>
+
+ <projects id="10" kee="org.struts:struts"/>
+ <projects id="11" kee="org.apache:commons-lang"/>
+ <projects id="12" kee="other"/>
+</dataset>
--- /dev/null
+<dataset>
+
+ <!-- global -->
+ <properties id="1" prop_key="global.one" text_value="one" resource_id="[null]" user_id="[null]"/>
+ <properties id="2" prop_key="global.two" text_value="two" resource_id="[null]" user_id="[null]"/>
+
+ <!-- struts -->
+ <properties id="3" prop_key="struts.one" text_value="one" resource_id="10" user_id="[null]"/>
+
+ <!-- commons -->
+ <properties id="4" prop_key="commonslang.one" text_value="two" resource_id="11" user_id="[null]"/>
+
+ <!-- user -->
+ <properties id="5" prop_key="user.one" text_value="one" resource_id="[null]" user_id="100"/>
+ <properties id="6" prop_key="user.two" text_value="two" resource_id="10" user_id="100"/>
+
+ <properties id="7" prop_key="commonslang.one" text_value="one" resource_id="12" user_id="[null]"/>
+
+ <projects id="10" kee="org.struts:struts"/>
+ <projects id="11" kee="org.apache:commons-lang"/>
+ <projects id="12" kee="other"/>
+</dataset>
propertiesDao.setProperty(new PropertyDto().setKey(PROPERTY_PREFIX + qualityProfile.getLanguage()).setValue(qualityProfile.getName()).setResourceId(component.getId()));
}
+ public void removeProject(Integer profileId, Long projectId, UserSession userSession) {
+ checkPermission(userSession);
+ Validation.checkMandatoryParameter(profileId, "profile");
+ QualityProfileDto qualityProfile = findNotNull(profileId);
+ removeProject(qualityProfile.getLanguage(), projectId);
+ }
+
+ public void removeProject(String language, Long projectId, UserSession userSession) {
+ checkPermission(userSession);
+ Validation.checkMandatoryParameter(language, "language");
+ removeProject(language, projectId);
+ }
+
+ private void removeProject(String language, Long projectId) {
+ Validation.checkMandatoryParameter(language, "project");
+ ComponentDto component = (ComponentDto) findNotNull(projectId);
+ propertiesDao.deleteProjectProperty(PROPERTY_PREFIX + language, component.getId());
+ }
+
private List<RulesProfile> readProfilesFromXml(NewProfileResult result, Map<String, String> xmlProfilesByPlugin) {
List<RulesProfile> profiles = newArrayList();
ValidationMessages messages = ValidationMessages.create();
return operations.projects(profileId);
}
+ /**
+ * Used in /project/profile
+ */
+ public QProfile profile(Integer projectId) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Used in /project/profile
+ */
+ public List<QProfile> profiles(String language) {
+ throw new UnsupportedOperationException();
+ }
+
public void addProject(Integer profileId, Long projectId) {
operations.addProject(profileId, projectId, UserSession.get());
}
- public void removeProject(Integer profileId, String projectKey) {
- throw new UnsupportedOperationException();
+ public void removeProject(Integer profileId, Long projectId) {
+ operations.removeProject(profileId, projectId, UserSession.get());
+ }
+
+ public void removeProjectByLanguage(String language, Long projectId) {
+ operations.removeProject(language, projectId, UserSession.get());
}
public void removeAllProjects(Integer profileId) {
redirect_to :action => 'projects', :id => profile_id
end
- # POST /profiles/remove_project?id=<profile id>&project=<project id or key>
+ # POST /profiles/remove_project?id=<profile id>&project=<project id>
def remove_project
verify_post_request
- access_denied unless has_role?(:profileadmin)
- require_parameters 'id', 'project'
-
- profile=Profile.find(params[:id])
- bad_request('Unknown profile') unless profile
- project=Project.by_key(params[:project])
- bad_request('Unknown project') unless project
-
- Profile.reset_default_profile_for_project_id(profile.language, project.id)
- redirect_to :action => 'projects', :id => profile.id
+ profile_id = params[:id].to_i
+ call_backend do
+ Internal.qprofiles.removeProject(profile_id, params[:project].to_i)
+ end
+ redirect_to :action => 'projects', :id => profile_id
end
# POST /profiles/remove_projects?id=<profile id>
# GET /project/profile?id=<project id>
def profile
require_parameters :id
- @project=get_current_project_for_profile(params[:id])
- @snapshot=@project.last_snapshot
+ @project = get_current_project_for_profile(params[:id])
+ @snapshot = @project.last_snapshot
end
# POST /project/set_profile?id=<project id>&language=<language>[&profile_id=<profile id>]
def set_profile
- require_parameters :id, :language
verify_post_request
- language=params[:language]
- project = get_current_project_for_profile(params[:id])
+ language = params[:language]
+ project = params[:id].to_i
+ profile_id = params[:profile_id]
- if params[:profile_id].blank?
- Profile.reset_default_profile_for_project_id(language, project.id)
- else
- profile = Profile.find(params[:profile_id])
- bad_request('Bad language') if profile.language!=language
- profile.add_project_id(project.id)
+ call_backend do
+ if profile_id.blank?
+ Internal.qprofiles.removeProjectByLanguage(language, project)
+ else
+ Internal.qprofiles.addProject(profile_id.to_i, project)
+ end
end
- redirect_to :action => 'profile', :id => project.id
+ redirect_to :action => 'profile', :id => project
end
def get_current_project_for_profile(project_id)
}
verify(propertiesDao, never()).setProperty(any(PropertyDto.class));
}
+
+ @Test
+ public void remove_project_by_quality_profile() throws Exception {
+ when(dao.selectById(1)).thenReturn(new QualityProfileDto().setId(1).setName("My profile").setLanguage("java"));
+ when(resourceDao.findById(10L)).thenReturn(new ComponentDto().setId(10L).setKey("org.codehaus.sonar:sonar").setName("SonarQube"));
+
+ operations.removeProject(1, 10L, MockUserSession.create().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN));
+
+ verify(propertiesDao).deleteProjectProperty("sonar.profile.java", 10L);
+ }
+
+ @Test
+ public void remove_project_by_language() throws Exception {
+ when(resourceDao.findById(10L)).thenReturn(new ComponentDto().setId(10L).setKey("org.codehaus.sonar:sonar").setName("SonarQube"));
+
+ operations.removeProject("java", 10L, MockUserSession.create().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN));
+
+ verify(propertiesDao).deleteProjectProperty("sonar.profile.java", 10L);
+ }
}
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
public class QProfilesTest {
verify(operations).projects(1);
}
+ @Test(expected = UnsupportedOperationException.class)
+ public void get_profile_from_project_id() throws Exception {
+ qProfiles.profile(1);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void get_profiles_from_language() throws Exception {
+ qProfiles.profiles("java");
+ }
+
@Test
public void add_project() throws Exception {
qProfiles.addProject(1, 10L);
verify(operations).addProject(eq(1), eq(10L), any(UserSession.class));
}
- @Test(expected = UnsupportedOperationException.class)
- public void testRemoveProject() throws Exception {
- qProfiles.removeProject(null, null);
+ @Test
+ public void remove_project_by_quality_profile_id() throws Exception {
+ qProfiles.removeProject(1, 10L);
+ verify(operations).removeProject(eq(1), eq(10L), any(UserSession.class));
+ }
+
+ @Test
+ public void remove_project_by_language() throws Exception {
+ qProfiles.removeProjectByLanguage("java", 10L);
+ verify(operations).removeProject(eq("java"), eq(10L), any(UserSession.class));
}
@Test(expected = UnsupportedOperationException.class)