app/models/user_analysis.rb
# add user_analysis to methods repository and set ACL to public read
add user_analysis to methods repository and set ACL to public read
add user_analysis to methods repository and set ACL to public read
def add_method_to_repository
    begin
      Rails.logger.info "Adding #{self.namespace}/#{self.name} to methods repo as new snapshot"
      user_client = FireCloudClient.new(self.user)
      synopsis = "User analysis for #{self.user_workspace.name}"
      if self.snapshot.present? && self.snapshot > 0
        remote_method = user_client.update_method(self.namespace, self.name, self.snapshot, synopsis, self.wdl_contents)
      else
        remote_method = user_client.create_method(self.namespace, self.name, synopsis, self.wdl_contents)
      end
      if remote_method.present?
        self.snapshot = remote_method['snapshotId']
      else
        errors.add(:wdl_contents, '- did not successfully add to methods repo (no snapshot assigned).  Please try again.')
      end
      Rails.logger.info "#{self.full_name} successfully added to methods repo"
      Rails.logger.info "Setting permissions to allow imports for #{self.full_name}"
      public_acl = user_client.create_method_acl('public', 'READER')
      updated_acl = user_client.update_method_permissions(self.namespace, self.name, self.snapshot, public_acl)
      public_added = updated_acl.detect {|acl| acl['user'] == 'public' && acl['role'] == 'READER'}
      unless public_added.present?
        user_client.delete_method(self.namespace, self.name, self.snapshot)
        errors.add(:wdl_contents, '- did not successfully set permissions on method (not publicly readable).  Please try again.')
      end
      Rails.logger.info "Public access set on #{self.full_name}"
    rescue => e
      Rails.logger.error "Unable to add #{self.full_name} to methods repo: #{e.message}"
      errors.add(:wdl_contents, "- unable to add this analysis to the methods repo due to an error: #{e.message}")
    end
  end
def add_method_to_repository begin Rails . logger . info "Adding #{self.namespace}/#{self.name} to methods repo as new snapshot" user_client = FireCloudClient . new ( self . user ) synopsis = "User analysis for #{self.user_workspace.name}" if self . snapshot . present? && self . snapshot > 0 remote_method = user_client . update_method ( self . namespace , self . name , self . snapshot , synopsis , self . wdl_contents ) else remote_method = user_client . create_method ( self . namespace , self . name , synopsis , self . wdl_contents ) end if remote_method . present? self . snapshot = remote_method [ 'snapshotId' ] else errors . add ( :wdl_contents , '- did not successfully add to methods repo (no snapshot assigned).  Please try again.' ) end Rails . logger . info "#{self.full_name} successfully added to methods repo" Rails . logger . info "Setting permissions to allow imports for #{self.full_name}" public_acl = user_client . create_method_acl ( 'public' , 'READER' ) updated_acl = user_client . update_method_permissions ( self . namespace , self . name , self . snapshot , public_acl ) public_added = updated_acl . detect { | acl | acl [ 'user' ] == 'public' && acl [ 'role' ] == 'READER' } unless public_added . present? user_client . delete_method ( self . namespace , self . name , self . snapshot ) errors . add ( :wdl_contents , '- did not successfully set permissions on method (not publicly readable).  Please try again.' ) end Rails . logger . info "Public access set on #{self.full_name}" rescue => e Rails . logger . error "Unable to add #{self.full_name} to methods repo: #{e.message}" errors . add ( :wdl_contents , "- unable to add this analysis to the methods repo due to an error: #{e.message}" ) end end
add user_analysis to methods repository and set ACL to public read
add user_analysis to methods repository and set ACL to public read
# update existing method if already present