<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi,<br>
    <br>
    After previous discussions I've changed our /products API. Please
    update your scripts, if needed, to reflect this change.<br>
    <br>
    It was tagged in katello-0.1.225-1 and katello-cli-0.1.53-1.<br>
    <br>
    -- Ivan<br>
    <br>
    -------- Original Message --------
    <table class="moz-email-headers-table" border="0" cellpadding="0"
      cellspacing="0">
      <tbody>
        <tr>
          <th align="RIGHT" nowrap="nowrap" valign="BASELINE">Subject: </th>
          <td>[katello-commits] [katello] 768254 - scope products API by
            organization</td>
        </tr>
        <tr>
          <th align="RIGHT" nowrap="nowrap" valign="BASELINE">Date: </th>
          <td>Tue, 7 Feb 2012 10:57:51 +0000 (UTC)</td>
        </tr>
        <tr>
          <th align="RIGHT" nowrap="nowrap" valign="BASELINE">From: </th>
          <td>Ivan Nečas <a class="moz-txt-link-rfc2396E" href="mailto:inecas@fedoraproject.org"><inecas@fedoraproject.org></a></td>
        </tr>
        <tr>
          <th align="RIGHT" nowrap="nowrap" valign="BASELINE">Reply-To:
          </th>
          <td><a class="moz-txt-link-abbreviated" href="mailto:katello-commits@lists.fedorahosted.org">katello-commits@lists.fedorahosted.org</a></td>
        </tr>
        <tr>
          <th align="RIGHT" nowrap="nowrap" valign="BASELINE">To: </th>
          <td><a class="moz-txt-link-abbreviated" href="mailto:katello-commits@lists.fedorahosted.org">katello-commits@lists.fedorahosted.org</a></td>
        </tr>
      </tbody>
    </table>
    <br>
    <br>
    <pre>commit f3b57d1da6b93af2bda0fbb5246824fb68efdb20
Author: Ivan Necas <a class="moz-txt-link-rfc2396E" href="mailto:inecas@redhat.com"><inecas@redhat.com></a>
Date:   Tue Feb 7 11:43:26 2012 +0100

    768254 - scope products API by organization
    
    We referrence products by candlepin id. However there are more products in
    Katello assigned to a CP product (e.g. after importing manifest to more
    organizations).
    
    We might choose to refference products using Katello id, but
    this would cause troubles with rhsm, because we are mirroring CP API and in
    case subscription manager was using CP /products API, it would behave
    differently for plain Candlepin and Katello proxy.
    
    Therefore all the requests beginning with:
    
      /api/products/:product_id/...
    
    were transformed to:
    
      /api/organizations/:organization_name/products/:product_id/...

 cli/src/katello/client/api/product.py              |   40 +++++++++---------
 cli/src/katello/client/api/repo.py                 |   10 +++--
 cli/src/katello/client/core/organization.py        |    2 +-
 cli/src/katello/client/core/product.py             |   26 ++++++------
 cli/src/katello/client/core/repo.py                |   10 ++--
 src/app/controllers/api/filters_controller.rb      |    4 +-
 src/app/controllers/api/products_controller.rb     |    6 +-
 src/app/controllers/api/repositories_controller.rb |    4 +-
 src/app/controllers/api/sync_controller.rb         |    3 +-
 src/app/models/glue/pulp/errata.rb                 |    2 +-
 src/app/models/organization.rb                     |    1 +
 src/config/routes.rb                               |   26 +++++------
 .../controllers/api/filters_controller_spec.rb     |    6 +-
 .../controllers/api/products_controller_spec.rb    |    6 +-
 .../api/repositories_controller_spec.rb            |   16 ++++----
 src/spec/controllers/api/sync_controller_spec.rb   |   45 ++++++++++---------
 16 files changed, 106 insertions(+), 101 deletions(-)
---
diff --git a/cli/src/katello/client/api/product.py b/cli/src/katello/client/api/product.py
index f7dc821..543567a 100644
--- a/cli/src/katello/client/api/product.py
+++ b/cli/src/katello/client/api/product.py
@@ -53,7 +53,7 @@ class ProductAPI(KatelloAPI):
         result = self.server.POST(path, {"product": product})[1]
         return result
 
-    def update(self, prodId, description, gpgkey, nogpgkey, gpgkey_recursive):
+    def update(self, orgName, prodId, description, gpgkey, nogpgkey, gpgkey_recursive):
         product = {}
         self.update_dict(product, "description", description)
         self.update_dict(product, "gpg_key_name", gpgkey)
@@ -61,46 +61,46 @@ class ProductAPI(KatelloAPI):
         if nogpgkey:
             product["gpg_key_name"] = ""
 
-        path = "/api/products/%s/" % prodId
+        path = "/api/organizations/%s/products/%s/" % (orgName, prodId)
         result = self.server.PUT(path, {"product": product})[1]
         return result
 
 
-    def show(self, prodId):
-        path = "/api/products/%s/" % prodId
+    def show(self, orgName, prodId):
+        path = "/api/organizations/%s/products/%s/" % (orgName, prodId)
         return self.server.GET(path)[1]
 
-    def delete(self, prodId):
-        path = "/api/products/%s/" % prodId
+    def delete(self, orgName, prodId):
+        path = "/api/organizations/%s/products/%s/" % (orgName, prodId)
         return self.server.DELETE(path)[1]
 
-    def sync(self, prodId):
-        path = "/api/products/%s/sync" % prodId
+    def sync(self, orgName, prodId):
+        path = "/api/organizations/%s/products/%s/sync" % (orgName, prodId)
         return self.server.POST(path)[1]
 
-    def set_sync_plan(self, prodId, planId):
-        path = "/api/products/%s/sync_plan" % str(prodId)
+    def set_sync_plan(self, orgName, prodId, planId):
+        path = "/api/organizations/%s/products/%s/sync_plan" % (orgName, prodId)
         return self.server.POST(path, {"plan_id": planId})[1]
 
-    def remove_sync_plan(self, prodId):
-        path = "/api/products/%s/sync_plan" % str(prodId)
+    def remove_sync_plan(self, orgName, prodId):
+        path = "/api/organizations/%s/products/%s/sync_plan" % (orgName, prodId)
         return self.server.DELETE(path)[1]
 
-    def cancel_sync(self, prodId):
-        path = "/api/products/%s/sync" % prodId
+    def cancel_sync(self, orgName, prodId):
+        path = "/api/organizations/%s/products/%s/sync" % (orgName, prodId)
         return self.server.DELETE(path)[1]
 
-    def last_sync_status(self, prodId):
-        path = "/api/products/%s/sync" % prodId
+    def last_sync_status(self, orgName, prodId):
+        path = "/api/organizations/%s/products/%s/sync" % (orgName, prodId)
         data = self.server.GET(path)[1]
         return data
 
-    def update_filters(self, prodId, filters):
-        path = "/api/products/%s/filters" % prodId
+    def update_filters(self, orgName, prodId, filters):
+        path = "/api/organizations/%s/products/%s/filters" % (orgName, prodId)
         data = self.server.PUT(path, {"filters": filters})[1]
         return data
 
-    def filters(self, prodId):
-        path = "/api/products/%s/filters" % prodId
+    def filters(self, orgName, prodId):
+        path = "/api/organizations/%s/products/%s/filters" % (orgName, prodId)
         data = self.server.GET(path)[1]
         return data
diff --git a/cli/src/katello/client/api/repo.py b/cli/src/katello/client/api/repo.py
index b5bd746..8eee71c 100644
--- a/cli/src/katello/client/api/repo.py
+++ b/cli/src/katello/client/api/repo.py
@@ -19,8 +19,10 @@ class RepoAPI(KatelloAPI):
     """
     Connection class to access repositories
     """
-    def create(self, prod_id, name, url, gpgkey, nogpgkey):
-        repodata = {"product_id": prod_id,
+    def create(self, orgName, prod_id, name, url, gpgkey, nogpgkey):
+        repodata = {
+                    "organization_id": orgName,
+                    "product_id": prod_id,
                     "name": name,
                     "url": url}
         self.update_dict(repodata, "gpg_key_name", gpgkey)
@@ -58,8 +60,8 @@ class RepoAPI(KatelloAPI):
         result_list = self.server.GET(path, search_params)[1]
         return result_list
 
-    def repos_by_product(self, productId, includeDisabled=False):
-        path = "/api/products/%s/repositories" % productId
+    def repos_by_product(self, orgName, productId, includeDisabled=False):
+        path = "/api/organizations/%s/products/%s/repositories" % (orgName, productId)
         data = {
             "include_disabled": includeDisabled
         }
diff --git a/cli/src/katello/client/core/organization.py b/cli/src/katello/client/core/organization.py
index 8b4f6e2..bae764b 100644
--- a/cli/src/katello/client/core/organization.py
+++ b/cli/src/katello/client/core/organization.py
@@ -226,7 +226,7 @@ class ShowSubscriptions(OrganizationAction):
         return os.EX_OK
 
     def sla(self, pool):
-        return {'sla': self.extract_sla_from_product(self.productApi.show(pool['productId']))}
+        return {'sla': self.extract_sla_from_product(self.productApi.show(self.get_option('name'), pool['productId']))}
 
     def convert_timestamp(self, timestamp_field):
         offset = int(timestamp_field[-5:])
diff --git a/cli/src/katello/client/core/product.py b/cli/src/katello/client/core/product.py
index 94825f7..ca0c733 100644
--- a/cli/src/katello/client/core/product.py
+++ b/cli/src/katello/client/core/product.py
@@ -95,7 +95,7 @@ class SetSyncPlan(SingleProductAction):
         if (plan == None):
             return os.EX_DATAERR
 
-        msg = self.api.set_sync_plan(prod['id'], plan['id'])
+        msg = self.api.set_sync_plan(orgName, prod['id'], plan['id'])
         print msg
         return os.EX_OK
 
@@ -114,7 +114,7 @@ class RemoveSyncPlan(SingleProductAction):
         if (prod == None):
             return os.EX_DATAERR
 
-        msg = self.api.remove_sync_plan(prod['id'])
+        msg = self.api.remove_sync_plan(orgName, prod['id'])
         print msg
         return os.EX_OK
 
@@ -181,7 +181,7 @@ class Sync(SingleProductAction):
         if (prod == None):
             return os.EX_DATAERR
 
-        task = AsyncTask(self.api.sync(prod["id"]))
+        task = AsyncTask(self.api.sync(orgName, prod["id"]))
         run_async_task_with_status(task, ProgressBar())
 
         if task.failed():
@@ -209,7 +209,7 @@ class CancelSync(SingleProductAction):
         if (prod == None):
             return os.EX_DATAERR
 
-        msg = self.api.cancel_sync(prod["id"])
+        msg = self.api.cancel_sync(orgName, prod["id"])
         print msg
         return os.EX_OK
 
@@ -228,7 +228,7 @@ class Status(SingleProductAction):
         if (prod == None):
             return os.EX_DATAERR
 
-        task = AsyncTask(self.api.last_sync_status(prod['id']))
+        task = AsyncTask(self.api.last_sync_status(orgName, prod['id']))
 
         prod['last_sync'] = format_sync_time(prod['last_sync'])
         prod['sync_state'] = format_sync_state(prod['sync_state'])
@@ -367,7 +367,7 @@ class Create(ProductAction):
             repourls = self.discoverRepos.discover_repositories(orgName, url)
             self.printer.setHeader(_("Repository Urls discovered @ [%s]" % url))
             selectedurls = self.discoverRepos.select_repositories(repourls, assumeyes)
-            self.discoverRepos.create_repositories(prod["id"], prod["name"], selectedurls)
+            self.discoverRepos.create_repositories(orgName, prod["id"], prod["name"], selectedurls)
 
         return os.EX_OK
 
@@ -403,7 +403,7 @@ class Update(SingleProductAction):
         if (prod == None):
             return os.EX_DATAERR
 
-        prod = self.api.update(prod["id"], description, gpgkey, nogpgkey, gpgkey_recursive)
+        prod = self.api.update(orgName, prod["id"], description, gpgkey, nogpgkey, gpgkey_recursive)
         print _("Successfully updated product [ %s ]") % prodName
         return os.EX_OK
 
@@ -420,7 +420,7 @@ class Delete(SingleProductAction):
         if product == None:
             return os.EX_DATAERR
 
-        msg = self.api.delete(product["id"])
+        msg = self.api.delete(orgName, product["id"])
         print msg
         return os.EX_OK
 
@@ -437,7 +437,7 @@ class ListFilters(SingleProductAction):
         if (prod == None):
             return os.EX_DATAERR
 
-        filters = self.api.filters(prod['id'])
+        filters = self.api.filters(orgName, prod['id'])
         self.printer.addColumn('name')
         self.printer.addColumn('description')
         self.printer.setHeader(_("Product Filters<a class="moz-txt-link-rfc2396E" href="mailto:))@@-484,12+484,12@@classAddRemoveFilter(SingleProductAction):ifget_filter(org_name,filter_name)==None:returnos.EX_DATAERR-filters=self.api.filters(prod['id'])+filters=self.api.filters(org_name,prod['id'])filters=[f['name']forfinfilters]-self.update_filters(prod,filters,filter_name)+self.update_filters(org_name,prod,filters,filter_name)returnos.EX_OK-defupdate_filters(self,product,filters,filter_name):+defupdate_filters(self,org_name,product,filters,filter_name):ifself.addition:filters.append(filter_name)message=_(">"))
@@ -484,12 +484,12 @@ class AddRemoveFilter(SingleProductAction):
         if get_filter(org_name, filter_name) == None:
             return os.EX_DATAERR
 
-        filters = self.api.filters(prod['id'])
+        filters = self.api.filters(org_name, prod['id'])
         filters = [f['name'] for f in filters] 
-        self.update_filters(prod, filters, filter_name)
+        self.update_filters(org_name, prod, filters, filter_name)
         return os.EX_OK
 
-    def update_filters(self, product, filters, filter_name):
+    def update_filters(self, org_name, product, filters, filter_name):
         if self.addition:
             filters.append(filter_name)
             message = _("</a>Added filter [ %s ] to product [ %s ]" % (filter_name, product["name<a class="moz-txt-link-rfc2396E" href="mailto:]))@@-497,7+497,7@@classAddRemoveFilter(SingleProductAction):filters.remove(filter_name)message=_(">"]))
@@ -497,7 +497,7 @@ class AddRemoveFilter(SingleProductAction):
             filters.remove(filter_name)
             message = _("</a>Removed filter [ %s ] to product [ %s ]" % (filter_name, product["name"]))
 
-        self.api.update_filters(product['id'], filters)
+        self.api.update_filters(org_name, product['id'], filters)
         print message
 
 
diff --git a/cli/src/katello/client/core/repo.py b/cli/src/katello/client/core/repo.py
index 9e7a7e7..e5a7a59 100644
--- a/cli/src/katello/client/core/repo.py
+++ b/cli/src/katello/client/core/repo.py
@@ -149,7 +149,7 @@ class Create(RepoAction):
 
         prod = get_product(orgName, prodName)
         if prod != None:
-            repo = self.api.create(prod["id"], name, url, gpgkey, nogpgkey)
+            repo = self.api.create(orgName, prod["id"], name, url, gpgkey, nogpgkey)
             print _("Successfully created repository [ %s ]") % name
         else:
             print _("No product [ %s ] found") % prodName
@@ -192,7 +192,7 @@ class Discovery(RepoAction):
 
         prod = get_product(orgName, prodName)
         if prod != None:
-            self.create_repositories(prod["id"], name, selectedurls)
+            self.create_repositories(orgName, prod["id"], name, selectedurls)
 
         return os.EX_OK
 
@@ -252,11 +252,11 @@ class Discovery(RepoAction):
 
         return selection
 
-    def create_repositories(self, productid, name, selectedurls):
+    def create_repositories(self, orgName, productid, name, selectedurls):
         for repourl in selectedurls:
             parsedUrl = urlparse.urlparse(repourl)
             repoName = self.repository_name(name, parsedUrl.path) # pylint: disable=E1101
-            repo = self.api.create(productid, repoName, repourl, None, None)
+            repo = self.api.create(orgName, productid, repoName, repourl, None, None)
 
             print _("Successfully created repository [ %s ]") % repoName
 
@@ -454,7 +454,7 @@ class List(RepoAction):
             prod = get_product(orgName, prodName)
             if prod != None:
                 self.printer.setHeader(_("Repo List for Product %s in Org %s ") % (prodName, orgName))
-                repos = self.api.repos_by_product(prod["id"], listDisabled)
+                repos = self.api.repos_by_product(orgName, prod["id"], listDisabled)
                 self.printer.printItems(repos)
             else:
                 return os.EX_DATAERR
diff --git a/src/app/controllers/api/filters_controller.rb b/src/app/controllers/api/filters_controller.rb
index b955823..0308fd7 100644
--- a/src/app/controllers/api/filters_controller.rb
+++ b/src/app/controllers/api/filters_controller.rb
@@ -12,7 +12,7 @@
 
 class Api::FiltersController < Api::ApiController
 
-  before_filter :find_organization, :only => [:index, :create]
+  before_filter :find_organization, :only => [:index, :create, :list_product_filters, :update_product_filters]
   before_filter :find_filter, :only => [:show, :destroy, :update]
   before_filter :find_product, :only => [:list_product_filters, :update_product_filters]
   before_filter :find_repository, :only => [:list_repository_filters, :update_repository_filters]
@@ -101,7 +101,7 @@ class Api::FiltersController < Api::ApiController
   end
 
   def find_product
-    @product = Product.find_by_cp_id(params[:product_id])
+    @product = @organization.products.find_by_cp_id(params[:product_id])
     raise HttpErrors::NotFound, _("Couldn't find product with id '#{params[:product_id]}'") if @product.nil?
   end
 
diff --git a/src/app/controllers/api/products_controller.rb b/src/app/controllers/api/products_controller.rb
index 118606e..e6ec49c 100644
--- a/src/app/controllers/api/products_controller.rb
+++ b/src/app/controllers/api/products_controller.rb
@@ -12,9 +12,9 @@
 
 class Api::ProductsController < Api::ApiController
   respond_to :json
-  before_filter :find_organization, :only => [:index]
-  before_filter :find_product, :only => [:repositories, :show, :update, :destroy, :set_sync_plan, :remove_sync_plan]
+  before_filter :find_organization, :only => [:index, :repositories, :show, :update, :destroy, :set_sync_plan, :remove_sync_plan]
   before_filter :find_environment, :only => [:index, :repositories]
+  before_filter :find_product, :only => [:repositories, :show, :update, :destroy, :set_sync_plan, :remove_sync_plan]
   before_filter :verify_presence_of_organization_or_environment, :only => [:index]
   before_filter :authorize
 
@@ -85,7 +85,7 @@ class Api::ProductsController < Api::ApiController
   private
 
   def find_product
-    @product = Product.find_by_cp_id(params[:id].to_s)
+    @product = @organization.products.find_by_cp_id(params[:id].to_s)
     raise HttpErrors::NotFound, _("Couldn't find product with id '#{params[:id]}'") if @product.nil?
   end
 
diff --git a/src/app/controllers/api/repositories_controller.rb b/src/app/controllers/api/repositories_controller.rb
index e7a7acd..147762d 100644
--- a/src/app/controllers/api/repositories_controller.rb
+++ b/src/app/controllers/api/repositories_controller.rb
@@ -15,8 +15,8 @@ require 'resources/pulp'
 class Api::RepositoriesController < Api::ApiController
   respond_to :json
   before_filter :find_repository, :only => [:show, :update, :destroy, :package_groups, :package_group_categories, :enable, :gpg_key_content]
+  before_filter :find_organization, :only => [:create, :discovery]
   before_filter :find_product, :only => [:create]
-  before_filter :find_organization, :only => [:discovery]
 
   before_filter :authorize
   skip_filter   :set_locale, :require_user, :thread_locals, :authorize, :only => [:gpg_key_content]
@@ -120,7 +120,7 @@ class Api::RepositoriesController < Api::ApiController
   end
 
   def find_product
-    @product = Product.find_by_cp_id params[:product_id]
+    @product = @organization.products.find_by_cp_id params[:product_id]
     raise HttpErrors::NotFound, _("Couldn't find product with id '#{params[:product_id]}'") if @product.nil?
   end
 end
diff --git a/src/app/controllers/api/sync_controller.rb b/src/app/controllers/api/sync_controller.rb
index e2c3131..650523d 100644
--- a/src/app/controllers/api/sync_controller.rb
+++ b/src/app/controllers/api/sync_controller.rb
@@ -80,7 +80,8 @@ class Api::SyncController < Api::ApiController
   end
 
   def find_product
-    @product = Product.find_by_cp_id(params[:product_id])
+    find_organization
+    @product = @organization.products.find_by_cp_id(params[:product_id])
     raise HttpErrors::NotFound, _("Couldn't find product with id '#{params[:product_id]}'") if @product.nil?
     @product
   end
diff --git a/src/app/models/glue/pulp/errata.rb b/src/app/models/glue/pulp/errata.rb
index 1aae95f..48bdd57 100644
--- a/src/app/models/glue/pulp/errata.rb
+++ b/src/app/models/glue/pulp/errata.rb
@@ -49,7 +49,7 @@ class Glue::Pulp::Errata
     elsif environment_id = filter[:environment_id]
       env = KTEnvironment.find(environment_id)
       if product_id = filter[:product_id]
-        products = [::Product.find_by_cp_id!(product_id)]
+        products = [env.products.find_by_cp_id!(product_id)]
       else
         products = env.products
       end
diff --git a/src/app/models/organization.rb b/src/app/models/organization.rb
index 29f7cbd..9f2eaa0 100644
--- a/src/app/models/organization.rb
+++ b/src/app/models/organization.rb
@@ -27,6 +27,7 @@ class Organization < ActiveRecord::Base
 
   has_many :activation_keys, :dependent => :destroy
   has_many :providers, :dependent => :destroy
+  has_many :products, :through => :providers
   has_many :environments, :class_name => "KTEnvironment", :conditions => {:library => false}, :dependent => :destroy, :inverse_of => :organization
   has_one :library, :class_name =>"KTEnvironment", :conditions => {:library => true}, :dependent => :destroy
   has_many :filters, :dependent => :destroy, :inverse_of => :organization
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 484feec..a1d9ec6 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -392,9 +392,20 @@ Src::Application.routes.draw do
     end
 
     resources :organizations do
-      resources :products, :only => [:index] do
+      resources :products, :only => [:index, :show, :update, :destroy] do
+        get :repositories, :on => :member
+        post :sync_plan, :on => :member, :action => :set_sync_plan
+        delete :sync_plan, :on => :member, :action => :remove_sync_plan
         get :repositories, :on => :member
+        resources :sync, :only => [:index, :create] do
+          delete :index, :on => :collection, :action => :cancel
+        end
+        resources :filters, :only => [] do
+          get :index, :on => :collection, :action => :list_product_filters
+          put :index, :on => :collection, :action => :update_product_filters
+        end
       end
+
       resources :environments do
         get :repositories, :on => :member
         resources :changesets, :only => [:index, :create]
@@ -450,19 +461,6 @@ Src::Application.routes.draw do
 
     end
 
-    resources :products, :only => [:show, :update, :destroy] do
-      post :sync_plan, :on => :member, :action => :set_sync_plan
-      delete :sync_plan, :on => :member, :action => :remove_sync_plan
-      get :repositories, :on => :member
-      resources :sync, :only => [:index, :create] do
-        delete :index, :on => :collection, :action => :cancel
-      end
-      resources :filters, :only => [] do
-        get :index, :on => :collection, :action => :list_product_filters
-        put :index, :on => :collection, :action => :update_product_filters
-      end
-    end
-
     #resources :puppetclasses, :only => [:index]
     resources :ping, :only => [:index]
 
diff --git a/src/spec/controllers/api/filters_controller_spec.rb b/src/spec/controllers/api/filters_controller_spec.rb
index 8bb5b60..7ec40e6 100644
--- a/src/spec/controllers/api/filters_controller_spec.rb
+++ b/src/spec/controllers/api/filters_controller_spec.rb
@@ -90,16 +90,16 @@ describe Api::FiltersController do
 
     it "should find product" do
       Product.should_receive(:find_by_cp_id).once.with(product_id).and_return(@product)
-      put :update_product_filters, :product_id => product_id, :filters => []
+      put :update_product_filters, :organization_id => @organization.cp_key, :product_id => product_id, :filters => []
     end
 
     it "should find filters" do
       Filter.should_receive(:where).once.with(hash_including(:pulp_id => [@filter.name]))
-      put :update_product_filters, :product_id => product_id, :filters => [@filter.name]
+      put :update_product_filters, :organization_id => @organization.cp_key, :product_id => product_id, :filters => [@filter.name]
     end
 
     it "should add new filter" do
-      put :update_product_filters, :product_id => product_id, :filters => [@filter.name]
+      put :update_product_filters, :organization_id => @organization.cp_key, :product_id => product_id, :filters => [@filter.name]
       assigns(:product).filters.size.should == 1
       assigns(:product).filters.should include(@filter)
     end
diff --git a/src/spec/controllers/api/products_controller_spec.rb b/src/spec/controllers/api/products_controller_spec.rb
index c08af30..2deffbc 100644
--- a/src/spec/controllers/api/products_controller_spec.rb
+++ b/src/spec/controllers/api/products_controller_spec.rb
@@ -71,7 +71,7 @@ describe Api::ProductsController do
     end
 
     let(:action) { :show }
-    let(:req) { get 'show', :id => @product.id }
+    let(:req) { get 'show', :organization_id => @organization.name, :id => @product.id }
     let(:authorized_user) { user_with_read_permissions }
     let(:unauthorized_user) { user_without_read_permissions }
     it_should_behave_like "protected action"
@@ -91,7 +91,7 @@ describe Api::ProductsController do
     end
 
     let(:action) { :update }
-    let(:req) { put 'update', :id => @product.id, :product => {:gpg_key_name => gpg_key.name, :description => "another description" } }
+    let(:req) { put 'update', :id => @product.cp_id, :organization_id => @organization.cp_key, :product => {:gpg_key_name => gpg_key.name, :description => "another description" } }
     let(:authorized_user) { user_with_update_permissions }
     let(:unauthorized_user) { user_without_update_permissions }
     it_should_behave_like "protected action"
@@ -108,7 +108,7 @@ describe Api::ProductsController do
 
       it "should reset repos' GPGs, if updating recursive" do
         @product.should_receive(:reset_repo_gpgs!)
-        put 'update', :id => @product.id, :product => {:gpg_key_name => gpg_key.name, :description => "another description", :recursive => true }
+        put 'update', :id => @product.cp_id, :organization_id => @organization.cp_key, :product => {:gpg_key_name => gpg_key.name, :description => "another description", :recursive => true }
       end
     end
 
diff --git a/src/spec/controllers/api/repositories_controller_spec.rb b/src/spec/controllers/api/repositories_controller_spec.rb
index 87912a0..e5bab58 100644
--- a/src/spec/controllers/api/repositories_controller_spec.rb
+++ b/src/spec/controllers/api/repositories_controller_spec.rb
@@ -46,7 +46,7 @@ describe Api::RepositoriesController do
     describe "for create" do
       let(:action) {:create}
       let(:req) do
-        post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1'
+        post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1', :organization_id => @organization.cp_key
       end
       let(:authorized_user) do
         user_with_permissions { |u| u.can(:update, :providers, @provider.id, @organization) }
@@ -173,13 +173,13 @@ describe Api::RepositoriesController do
       Product.should_receive(:find_by_cp_id).with('product_1').and_return(@product)
       @product.should_receive(:add_repo).and_return({})
 
-      post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1'
+      post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1', :organization_id => @organization.cp_key
     end
 
     context 'there is already a repo for the product with the same name' do
       it "should notify about conflict" do
         @product.stub(:add_repo).and_return { raise Errors::ConflictException }
-        post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1'
+        post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1', :organization_id => @organization.cp_key
         response.code.should == '409'
       end
     end
@@ -197,7 +197,7 @@ describe Api::RepositoriesController do
           @product.should_receive(:add_repo).with do |name, url, type, gpg|
             gpg == product_gpg
           end.and_return({})
-          post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1'
+          post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1', :organization_id => @organization.cp_key
         end
       end
 
@@ -206,7 +206,7 @@ describe Api::RepositoriesController do
           @product.should_receive(:add_repo).with do |name, url, type, gpg|
             gpg == repo_gpg
           end.and_return({})
-          post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1', :gpg_key_name => repo_gpg.name
+          post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1', :organization_id => @organization.cp_key, :gpg_key_name => repo_gpg.name
         end
       end
 
@@ -215,7 +215,7 @@ describe Api::RepositoriesController do
           @product.should_receive(:add_repo).with do |name, url, type, gpg|
             gpg == nil
           end.and_return({})
-          post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1', :gpg_key_name => ""
+          post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1', :organization_id => @organization.cp_key, :gpg_key_name => ""
         end
       end
     end
@@ -254,7 +254,7 @@ describe Api::RepositoriesController do
       url  = <a class="moz-txt-link-rfc2396E" href="http://url.org">"http://url.org"</a>
       type = "yum"
 
-        post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1'
+        post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1', :organization_id => @organization.cp_key
       end
 
       context 'there is already a repo for the product with the same name' do
@@ -264,7 +264,7 @@ describe Api::RepositoriesController do
         end
 
         it "should notify about conflict" do
-          post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1'
+          post 'create', :name => 'repo_1', :url => '<a class="moz-txt-link-freetext" href="http://www.repo.org">http://www.repo.org</a>', :product_id => 'product_1', :organization_id => @organization.cp_key
           response.code.should == '409'
         end
       end
diff --git a/src/spec/controllers/api/sync_controller_spec.rb b/src/spec/controllers/api/sync_controller_spec.rb
index 1b9ee3e..775c0c0 100644
--- a/src/spec/controllers/api/sync_controller_spec.rb
+++ b/src/spec/controllers/api/sync_controller_spec.rb
@@ -46,22 +46,7 @@ describe Api::SyncController do
 
   describe "rules" do
     before(:each) do
-      disable_product_orchestration
-
-      @organization = new_test_org
-      Organization.stub!(:first).and_return(@organization)
-      @provider = Provider.create!(:provider_type=>Provider::CUSTOM, :name=>"foo1", :organization=>@organization)
-      Provider.stub!(:find).and_return(@provider)
-      @product = Product.new({:name => "prod"})
-      @product.provider = @provider
-      @product.environments << @organization.library
-      @product.stub(:arch).and_return('noarch')
-      @product.save!
-      Product.stub!(:find).and_return(@product)
-      Product.stub!(:find_by_cp_id).and_return(@product)
-      ep = EnvironmentProduct.find_or_create(@organization.library, @product)
-      @repository = Repository.create!(:environment_product => ep, :name=> "repo_1", :pulp_id=>"1")
-      Repository.stub(:find).and_return(@repository)
+      stub_product_with_repo
     end
     describe "for provider index" do
       let(:action) {:index}
@@ -79,7 +64,7 @@ describe Api::SyncController do
     describe "for product index" do
       let(:action) {:index}
       let(:req) do
-        get :index, :product_id => product_id
+        get :index, :product_id => product_id, :organization_id => @organization.cp_key
       end
       let(:authorized_user) do
         user_with_permissions { |u| u.can(:read, :providers, nil, @organization) }
@@ -146,11 +131,10 @@ describe Api::SyncController do
       end
 
       it "should find product if :product_id is specified" do
-        found_product = {}
-        Product.should_receive(:find_by_cp_id).once.with(product_id).and_return(found_product)
-        controller.stub!(:params).and_return({:product_id => product_id })
+        stub_product_with_repo
+        controller.stub!(:params).and_return({:organization_id => @organization.cp_key, :product_id => @product.id })
 
-        controller.find_object.should == found_product
+        controller.find_object.should == @product
       end
 
       it "should find repository if :repository_id is specified" do
@@ -263,5 +247,24 @@ describe Api::SyncController do
     end
   end
 
+  def stub_product_with_repo
+      disable_product_orchestration
+
+      @organization = new_test_org
+      Organization.stub!(:first).and_return(@organization)
+      @provider = Provider.create!(:provider_type=>Provider::CUSTOM, :name=>"foo1", :organization=>@organization)
+      Provider.stub!(:find).and_return(@provider)
+      @product = Product.new({:name => "prod"})
+      @product.provider = @provider
+      @product.environments << @organization.library
+      @product.stub(:arch).and_return('noarch')
+      @product.save!
+      Product.stub!(:find).and_return(@product)
+      Product.stub!(:find_by_cp_id).and_return(@product)
+      ep = EnvironmentProduct.find_or_create(@organization.library, @product)
+      @repository = Repository.create!(:environment_product => ep, :name=> "repo_1", :pulp_id=>"1")
+      Repository.stub(:find).and_return(@repository)
+  end
+
 end
 
_______________________________________________
katello-commits mailing list
<a class="moz-txt-link-abbreviated" href="mailto:katello-commits@lists.fedorahosted.org">katello-commits@lists.fedorahosted.org</a>
<a class="moz-txt-link-freetext" href="https://fedorahosted.org/mailman/listinfo/katello-commits">https://fedorahosted.org/mailman/listinfo/katello-commits</a>
</pre>
  </body>
</html>