<commit_before>module Concerns
  module CartodbCentralSynchronizable

    def create_in_central
      return true unless sync_data_with_cartodb_central?
      if self.is_a?(User) && organization.present?
        cartodb_central_client.create_organization_user(organization.name, allowed_attributes_to_central(:create))
      elsif self.is_a?(Organization)
        raise "Can't create organizations in editor"
      end
      return true
    end

    def update_in_central
      return true unless sync_data_with_cartodb_central?
      if self.is_a?(User) && organization.present?
        cartodb_central_client.update_organization_user(organization.name, username, allowed_attributes_to_central(:update))
      elsif self.is_a?(Organization)
        cartodb_central_client.update_organization(name, allowed_attributes_to_central(:update))
      end
      return true
    end

    def delete_in_central
      return true unless sync_data_with_cartodb_central?
      if self.is_a?(User) && organization.present?
        if self.organization.owner && self.organization.owner != self
          cartodb_central_client.delete_organization_user(organization.name, username)
        else
          raise "Can't destroy the organization owner"
        end
      end
      return true
    end

    def allowed_attributes_from_central(action)
      if self.is_a?(Organization)
        case action
        when :create
          [:name, :seats, :quota_in_bytes, :display_name, :description, :website,
          :discus_shortname, :twitter_username, :geocoding_quota, :map_view_quota,
          :geocoding_block_price, :map_view_block_price,
          :twitter_datasource_enabled, :twitter_datasource_block_size,
          :twitter_datasource_block_price, :twitter_datasource_quota,
          :new_dashboard_enabled]
        when :update
          [:seats, :quota_in_bytes, :display_name, :description, :website,
          :discus_shortname, :twitter_username, :geocoding_quota, :map_view_quota,
          :geocoding_block_price, :map_view_block_price,
          :twitter_datasource_enabled, :twitter_datasource_block_size,
          :twitter_datasource_block_price, :twitter_datasource_quota,
          :new_dashboard_enabled]
        end
      elsif self.is_a?(User)
        [:account_type, :admin, :crypted_password, :database_host,
        :database_timeout, :description, :disqus_shortname, :available_for_hire, :email,
        :geocoding_block_price, :geocoding_quota, :map_view_block_price,
        :map_view_quota, :max_layers, :name, :notification, :organization_id,
        :period_end_date, :private_tables_enabled, :quota_in_bytes, :salt,
        :sync_tables_enabled, :table_quota, :twitter_username, :upgraded_at,
        :user_timeout, :username, :website, :soft_geocoding_limit,
        :twitter_datasource_enabled, :twitter_datasource_block_size,
        :twitter_datasource_block_price, :twitter_datasource_quota,
        :soft_twitter_datasource_limit,<commit_msg>Allow remotely edit limits closes #2389<commit_after>module Concerns
  module CartodbCentralSynchronizable

    def create_in_central
      return true unless sync_data_with_cartodb_central?
      if self.is_a?(User) && organization.present?
        cartodb_central_client.create_organization_user(organization.name, allowed_attributes_to_central(:create))
      elsif self.is_a?(Organization)
        raise "Can't create organizations in editor"
      end
      return true
    end

    def update_in_central
      return true unless sync_data_with_cartodb_central?
      if self.is_a?(User) && organization.present?
        cartodb_central_client.update_organization_user(organization.name, username, allowed_attributes_to_central(:update))
      elsif self.is_a?(Organization)
        cartodb_central_client.update_organization(name, allowed_attributes_to_central(:update))
      end
      return true
    end

    def delete_in_central
      return true unless sync_data_with_cartodb_central?
      if self.is_a?(User) && organization.present?
        if self.organization.owner && self.organization.owner != self
          cartodb_central_client.delete_organization_user(organization.name, username)
        else
          raise "Can't destroy the organization owner"
        end
      end
      return true
    end

    def allowed_attributes_from_central(action)
      if self.is_a?(Organization)
        case action
        when :create
          [:name, :seats, :quota_in_bytes, :display_name, :description, :website,
          :discus_shortname, :twitter_username, :geocoding_quota, :map_view_quota,
          :geocoding_block_price, :map_view_block_price,
          :twitter_datasource_enabled, :twitter_datasource_block_size,
          :twitter_datasource_block_price, :twitter_datasource_quota,
          :new_dashboard_enabled]
        when :update
          [:seats, :quota_in_bytes, :display_name, :description, :website,
          :discus_shortname, :twitter_username, :geocoding_quota, :map_view_quota,
          :geocoding_block_price, :map_view_block_price,
          :twitter_datasource_enabled, :twitter_datasource_block_size,
          :twitter_datasource_block_price, :twitter_datasource_quota,
          :new_dashboard_enabled]
        end
      elsif self.is_a?(User)
        [:account_type, :admin, :crypted_password, :database_host,
        :database_timeout, :description, :disqus_shortname, :available_for_hire, :email,
        :geocoding_block_price, :geocoding_quota, :map_view_block_price,
        :map_view_quota, :max_layers, :max_import_file_size, :max_import_table_row_count, :max_concurrent_import_count,
        :name, :notification, :organization_id,
        :period_end_date, :private_tables_enabled, :quota_in_bytes, :salt,
        :sync_tables_enabled, :table_quota, :twitter_username, :upgraded_at,
        :user_timeout, :username, :website, :soft_geocoding_limit,
        :twitter_datasource_enabled, :twitter_datasource_block_size,
        :twitter_datasource_block_price, :twitter_datasource_quota,
        :soft_twitter_datasource_limit,
{'fraction_non_alphanumeric': 0.07711360634081903, 'fraction_numerical': 0.0006605019815059445, 'mean_word_length': 3.841726618705036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2555153', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1826, 'n_words': 315}