PUT /admin/variants/:id
764799
def admin_update
      return if !user_is_allowed('variants', 'edit')
      
      resp = Caboose::StdClass.new({'attributes' => {}})
      v = Variant.find(params[:id])    
      
      save = true    
      params.each do |name,value|
        case name        
          when 'alternate_id'
            v.alternate_id = value
          when 'sku'
            v.sku = value
          when 'barcode'
            v.barcode = value
          when 'price'
            v.price = value
          when 'quantity_in_stock'
            v.quantity_in_stock = value
          when 'ignore_quantity'
            v.ignore_quantity = value
          when 'allow_backorder'
            v.allow_backorder = value
          when 'status'
            v.status = value
          when 'weight'
            v.weight = value
          when 'length'
            v.length = value
          when 'width'
            v.width = value
          when 'height'
            v.height = value
          when 'option1'
            v.option1 = value
          when 'option2'
            v.option2 = value
          when 'option3'
            v.option3 = value
          when 'requires_shipping'
            v.requires_shipping = value
          when 'taxable'
            v.taxable = value
        end
      end
      resp.success = save && v.save
      render :json => resp
    end
475404
def admin_update
      return if !user_is_allowed('products', 'edit')
      
      resp = Caboose::StdClass.new({'attributes' => {}})
      product = Product.find(params[:id])    
      
      save = true    
      params.each do |name,value|
        case name
          when 'alternate_id'
            product.alternate_id = value
          when 'date_available'
            if value.strip.length == 0
              product.date_available = nil
            else
              begin
                product.date_available = DateTime.parse(value)
              rescue
                resp.error = "Invalid date"
                save = false
              end
            end
          when 'title'
            product.title = value
          when 'caption'
            product.caption = value
          when 'featured'
            product.featured = value
          when 'description'
            product.description = value
          when 'category_id'
            product.category_id = value
          when 'vendor_id'  
            product.vendor_id = value
          when 'handle'
            product.handle = value
          when 'seo_title'
            product.seo_title = value
          when 'seo_description'
            product.seo_description = value
          when 'option1'
            product.option1 = value
          when 'option2'
            product.option2 = value
          when 'option3'
            product.option3 = value
          when 'default1'
            product.default1 = value
            Variant.where(:product_id => product.id, :option1 => nil).each do |p|
              p.option1 = value
              p.save
            end
          when 'default2'
            product.default2 = value
            Variant.where(:product_id => product.id, :option2 => nil).each do |p|
              p.option2 = value
              p.save
            end
          when 'default3'
            product.default3 = value
            Variant.where(:product_id => product.id, :option3 => nil).each do |p|
              p.option3 = value
              p.save
            end
          when 'status'
            product.status = value
        end
      end
      resp.success = save && product.save
      render :json => resp
    end
837164
def update

      @admin = Admin.find(params[:id])

      @admin.deal_with_cover params


      respond_to do |format|

        admin_passed = 
          if params[:admin][:password].blank?
            @admin.update_without_password(administrator_params)
          else
            @admin.update_attributes(administrator_params)
          end

        if admin_passed
          clear_cache
          profile_images(params, @admin)
          format.html { redirect_to edit_admin_administrator_path(@admin), notice: I18n.t("controllers.admin.administrators.update.flash.success") }
        else
          @action = 'update'
          format.html {
            # add breadcrumb and set title
            add_breadcrumb I18n.t("controllers.admin.administrators.edit.breadcrumb")
            flash[:error] = I18n.t('generic.validation.no_passed')
            render action: "edit"
          }
        end

      end

    end
803677
function (config, ID) {

        if (!ID) ID = '/';

        if (typeof config[environment] === 'string') hosts[ID] = config[environment];

        for (let element in config) {

            let elementID = (ID === '/') ? '/' + element : ID + '/' + element;
            if (typeof config[element] === 'object') iterate(config[element], elementID);

        }

    }
978311
def admin_edit_variants   
      return if !user_is_allowed('products', 'edit')    
      @product = Product.find(params[:id])
      
      if @product.variants.nil? || @product.variants.count == 0
        v = Variant.new
        v.option1 = @product.default1 if @product.option1
        v.option2 = @product.default2 if @product.option2
        v.option3 = @product.default3 if @product.option3
        v.status  = 'Active'
        @product.variants = [v]
        @product.save
      end
      @variant = params[:variant_id] ? Variant.find(params[:variant_id]) : @product.variants[0]
      session['variant_cols'] = self.default_variant_cols if session['variant_cols'].nil?
      @cols = session['variant_cols']
      
      @highlight_variant_id = params[:highlight] ? params[:highlight].to_i : nil        
      
      if @product.options.nil? || @product.options.count == 0
        render 'caboose_store/products/admin_edit_variants_single', :layout => 'caboose/admin'  
      else
        render 'caboose_store/products/admin_edit_variants', :layout => 'caboose/admin'
      end          
    end
1222072
def POST(self, id):
        
        id = int(id)
        model.del_todo(id)
        raise web.seeother('/')
718623
def put(self, user_id):
        """"""
        self.reqparse.add_argument('roles', type=str, action='append')
        args = self.reqparse.parse_args()
        auditlog(event='user.create', actor=session['user'].username, data=args)

        user = db.User.find_one(User.user_id == user_id)
        roles = db.Role.find(Role.name.in_(args['roles']))
        if not user:
            return self.make_response('No such user found: {}'.format(user_id), HTTP.NOT_FOUND)

        if user.username == 'admin' and user.auth_system == 'builtin':
            return self.make_response('You cannot modify the built-in admin user', HTTP.FORBIDDEN)

        user.roles = []
        for role in roles:
            if role in args['roles']:
                user.roles.append(role)

        db.session.add(user)
        db.session.commit()

        return self.make_response({'message': 'User roles updated'}, HTTP.OK)
861521
def add_variants(self, variants):
        
        
        operations = []
        nr_inserted = 0
        for i,variant in enumerate(variants, 1):
            # We need to check if there was any information returned
            # The variant could be excluded based on low gq or if no individiual was called
            # in the particular case
            if not variant:
                continue
            nr_inserted += 1
            update = self._get_update(variant)
            operations.append(
                UpdateOne(
                    {'_id': variant['_id']},
                    update,
                    upsert=True
                )
            )
            if i % 10000 == 0:
                self.db.variant.bulk_write(operations, ordered=False)
                operations = []
        
        if len(operations) > 0:
            self.db.variant.bulk_write(operations, ordered=False)
        
        return nr_inserted
275232
def merge_with_id(path, new_path, id)
      Dir.chdir(@directory) do
        run("git show #{id}:#{path} > #{path}.old_version")

        conflict_count = 0
        begin
          run("git merge-file #{path} #{path}.old_version #{new_path} \
                -L \"newly generated\" \
                -L \"previously generated\" \
                -L \"user edited\"")
        rescue ExecutionFailed => e
          if e.status > 0
            conflict_count = e.status
          else
            raise e
          end
        end
        File.delete("#{path}.old_version")
        conflict_count
      end
    end
529407
def save_variation_for_experiment(self, experiment_id, variation_id):
    

    self.experiment_bucket_map.update({
      experiment_id: {
        self.VARIATION_ID_KEY: variation_id
      }
    })
634436
def update_role(id, name)
      current_path = "/api/v1/roles/#{id}/update"
      payload = { 'new_name' => name }.to_json
      @conn.put(current_path, payload)
    end
626359
def admin_update_variant_columns    
      return if !user_is_allowed('products', 'edit')
      session['variant_cols'] = self.default_variant_cols if session['variant_cols'].nil?
      
      resp = Caboose::StdClass.new({'attributes' => {}})
      product = Product.find(params[:id])    
      
      save = true    
      params.each do |name,value|
        value = ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
        case name
          when 'option1'        ,
            'option2'           ,
            'option3'           ,
            'status'            ,
            'alternate_id'      ,
            'sku'               ,                        
            'barcode'           , 
            'price'             ,
            'quantity_in_stock' ,
            'weight'            , 
            'length'            , 
            'width'             , 
            'height'            , 
            'cylinder'          , 
            'requires_shipping' ,
            'allow_backorder'   ,
            'taxable'      
            session['variant_cols'][name] = value
        end
      end
      resp.success = save && product.save
      render :json => resp
    end
374098
private void putId() {
        // note: name and info may be null
        super.put("Provider.id name", String.valueOf(name));
        super.put("Provider.id version", String.valueOf(version));
        super.put("Provider.id info", String.valueOf(info));
        super.put("Provider.id className", this.getClass().getName());
    }
584152
def put(path, options = {}, &block)
      perform_request Net::HTTP::Put, path, options, &block
    end
1216560
def admin_add_upcs
      params[:vendor_id] if params[:vendor_id] and params[:vendor_id].empty?
      
      conditions = if params[:vendor_id]
        "store_variants.alternate_id IS NULL and store_vendors.id = #{params[:vendor_id]}"
      else
        "store_variants.alternate_id IS NULL"
      end
      
      @products = Product.all(
        :include => [:variants, :vendor],
        :conditions => conditions
      )
      
      render :layout => 'caboose/admin'
    end
504294
def create 
  	  # To do update this table we loop through the fields and update the key with the value.
      # In order to do this we need to remove any unnecessary keys from the params hash
      remove_unwanted_keys

      # loop through the param fields and update the key with the value
      validation = Setting.manual_validation(params)

      respond_to do |format|
        if validation.blank?
          Setting.save_data(params)
          clear_cache

          format.html { redirect_to administrator_setup_index_path, notice: I18n.t("controllers.admin.setup.general.success") }
        else
          format.html {
            # add breadcrumb and set title
            @settings = params
            @settings['errors'] = validation
            render action: "index"
          }
        end
      end

  	end
817189
def set(id, value, options = {})
      id = Array(id)
      id.push(nil) if id.empty?
      id[id.size - 1] ||= next_id(id[0..-2])
      with_redis do |redis|
        redis.set(redis_key_for(id), dump(value), redis_set_options.merge(options))
      end
      id.last
    end