Skip to content
Gareth Rees edited this page Feb 1, 2024 · 11 revisions

Enable Projects

Set ENABLE_PROJECTS: true in config/general.yml.

Migrate the database bundle exec rake db:migrate if you don't have the projects table.

Run bundle exec rake db:seed to ensure you have the roles necessary for projects.

Create a Project

user = User.find_by(email: 'annie@localhost')
project = Project.create(
  owner: user,
  title: 'My first project',
  briefing: '<p>Collaborate!</p>'
)

# Examples of how to add requests or batches
# Note that your user needs to have these already created
project.batches << user.info_request_batches.last
project.requests << user.info_requests.where(info_request_batch_id: nil).last

# Add some contributors
project.contributors << User.find_by(email: 'bob@localhost')

Create a Project from an InfoRequestBatch

Project.instance_eval do
  def self.from_batch(batch, briefing: '<p>…</p>')
    project = new(
      owner: batch.user,
      title: batch.title,
      briefing: briefing
    )

    project.batches << batch

    project
  end
end

batch = InfoRequestBatch.find(BATCH_ID)
project = Project.from_batch(batch)
project.save

View a project

Visit /projects/1.

Create a dataset

Create keys ("questions") one by one:

p = Project.find(1)

ks = Dataset::KeySet.create(resource: p)

k1 = Dataset::Key.create(key_set: ks, title: 'Is there anything of interest in this request?', format: 'text', order: 1)

k2 = Dataset::Key.create(key_set: ks, title: 'Did they attach a spreadsheet?', format: 'boolean', order: 2)

k3 = Dataset::Key.create(key_set: ks, title: 'How many things are there?', format: 'numeric', order: 3)

Note that order must be unique per KeySet.

Or create from JSON generated by the form builder:

questions = <<~JSON
[
  {
    "label": "Do they use foo?",
    "type": "boolean"
  }
]
JSON

Dataset::KeySet.class_eval do
  def create_keys_from_json(json)
    JSON.parse(json).each_with_index do |hash, index|
      Dataset::Key.create!(
        key_set: self,
        title: hash['label'],
        format: hash['type'],
        order: index + 1
      )
    end
  end
end

project = Project.find(1)
ks = Dataset::KeySet.create!(resource: project)
ks.create_keys_from_json(questions)

Generate an invite token

project.update(invite_token: SecureRandom.hex(6))

Print project URLs

# TODO: Use route helpers
puts "Project URL: " << "https://www.whatdotheyknow.com#{app.project_path(project)}"
puts "Invite URL:  " << "https://www.whatdotheyknow.com/p/#{project.invite_token}"

Here's some boilerplate to explain the two URLS:

As you're a project owner, you can go direct to the project URL (/projects/ID_NUMBER).

Contributors will first have to go via the Invite URL. They'll get asked to sign in / sign up to WDTK, and then automatically get permissions added to view the project. After that, they can/should use the project URL to access the project.

Export a leaderboard

See #7542.

Clone this wiki locally