From: Teryk Bellahsene Date: Fri, 16 Dec 2016 10:52:38 +0000 (+0100) Subject: SONAR-7287 Use api/favorites/add in the UI X-Git-Tag: 6.3-RC1~718 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6a94b3b976758fb094488c36b9c178e6ef811f81;p=sonarqube.git SONAR-7287 Use api/favorites/add in the UI --- diff --git a/server/sonar-web/src/main/js/api/favorites.js b/server/sonar-web/src/main/js/api/favorites.js index 3bb5872aa1e..7b87df6ea42 100644 --- a/server/sonar-web/src/main/js/api/favorites.js +++ b/server/sonar-web/src/main/js/api/favorites.js @@ -24,10 +24,8 @@ export const getFavorites = (): Promise => ( getJSON('/api/favourites') ); -export function addFavorite (componentKey: string) { - const url = '/api/favorites'; - const data = { component: componentKey }; - return post(url, data); +export function addFavorite (component: string) { + return post('/api/favorites/add', { component}); } export function removeFavorite (componentKey: string) { diff --git a/server/sonar-web/src/main/js/components/source-viewer/header.js b/server/sonar-web/src/main/js/components/source-viewer/header.js index d0248f1a02c..be78f9e41bf 100644 --- a/server/sonar-web/src/main/js/components/source-viewer/header.js +++ b/server/sonar-web/src/main/js/components/source-viewer/header.js @@ -51,7 +51,7 @@ export default Marionette.ItemView.extend({ }); } else { $.ajax({ - url: API_FAVORITE, + url: API_FAVORITE + '/add', type: 'POST', data: { component: this.model.get('key') diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/favourites_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/favourites_controller.rb index 46951b8d28c..57051ad1b37 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/favourites_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/favourites_controller.rb @@ -36,23 +36,6 @@ class Api::FavouritesController < Api::ApiController end end - # - # POST /api/favourites?key= - # curl -X POST http://localhost:9000/api/favourites?key=org.apache.struts:struts -v -u admin:admin - # - def create - favourite=current_user.add_favourite(params[:key]) - if favourite - respond_to do |format| - format.json { render :json => jsonp(favourites_to_json([favourite])) } - format.xml { render :xml => favourites_to_xml([favourite]) } - format.text { render :text => text_not_supported } - end - else - render_error('Favourite not found', 404) - end - end - # # DELETE /api/favourites/ # curl -X DELETE http://localhost:9000/api/favourites/org.apache.struts:struts -v -u admin:admin diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/user.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/user.rb index 0c17202cef9..755b30da084 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/user.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/user.rb @@ -116,14 +116,6 @@ class User < ActiveRecord::Base favourite_ids.size==0 ? [] : Project.find(:all, :conditions => ['id in (?) and enabled=?', favourite_ids, true]) end - def add_favourite(resource_key) - favourite=Project.by_key(resource_key) - if favourite - Api::Utils.java_facade.saveProperty(FAVOURITE_PROPERTY_KEY, favourite.id, id, '') - end - favourite - end - def delete_favourite(resource_key) rid=resource_key if resource_key.is_a?(String)