Salmon Pueblo Archaeological Research Collection
This is an application to work with the SPARC data derived from the spreadsheets.
https://github.com/activescaffold/active_scaffold
The app no longer uses ActiveScaffold since the data editing was completed.
git clone [email protected]:CDRH/sparc.git
cd sparcMake sure that you have the latest Ruby version installed and operating in this directory. You may want to also make sure that you are installing gems into a distinct place from other Ruby projects using the same version. RVM is recommended for this.
The pg gem requires postgresql-devel be installed on the system before the gem will bundle.
Once you have the correct ruby version, run the following. This may take a few minutes.
bundle installSet up your config file and fill out the location of your iiif_server:
cp config/config.example.yml config/config.ymlNow let's take a minute to set up your secrets file.
cp config/secrets.example.yml config/secrets.ymlNow you can run rails secret as many times as you like to generate new secrets for your config/secrets.yml file.
The following Apache configuration is required in the production site's
<VirtualHost> block:
# Necessary for unit names with slashes
AllowEncodedSlashes NoDecode
# CORS Header
SetEnvIf Request_URI "^/documents/.+/\w+\.json$" IIIF=1
Header set Access-Control-Allow-Origin * env=IIIF
UnsetEnv IIIFUniversal Viewer references other files relative to each other, so it must be served as static assets outside of the Rails asset pipeline.
This is best managed with Apache like this:
# Universal Viewer Static Assets
Alias /assets/uv-2.0.2 /var/local/www/rails/salmonpueblo.org/public/uv-2.0.2
<Location /assets/uv-2.0.2/>
PassengerEnabled off
Require all granted
</Location>
Alias /uv-2.0.2 /var/local/www/rails/salmonpueblo.org/public/uv-2.0.2
<Location /uv-2.0.2/>
PassengerEnabled off
Require all granted
</Location>It's unclear how to remove the prefix of /assets/ to some of the UV URLs, but
updating UV to a newer version might simplify the URLs it uses here.
Configure Postgres to securely encrypt passwords.
vim /var/lib/pgsql/data/postgresql.conf
Append password encryption config to the bottom:
...
# LOCAL
password_encryption = scram-sha-256
# EOF
Add user and databases they can access at the bottom of this config file.
vim /var/lib/pgsql/data/pg_hba.conf
# LOCAL
# Type: TCP/IP socket connections, no encryption
# Database
# User
# Address - Local only
# Method - Securely hashed password auth
hostnossl sparc sparc ::1/128 scram-sha-256
hostnossl sparc_test sparc ::1/128 scram-sha-256
# EOF
Restart Postgres to use the new configuration.
systemctl restart postgresqlCreate a user & password to manage the database.
sudo -u postgres psql
create role sparc with createdb login password 'password';
# Exit psql shell
exit # or Ctrl+DChange / reset a user's password.
If a password is created while the server's password_encryption is
a different value than specified in pg_hba.conf, it will need to be reset
with alter role like this to re-encrypt with the new algorithm to match the
chosen algorithm in pg_hba.conf.
sudo -u postgres psql
alter role sparc password 'new_password';# Create sparc database with sparc user as owner
sudo -u postgres createdb -O sparc sparc
# Test connecting as sparc user
psql -h localhost -U sparc -WNow you'll need to set up Rails database configuration.
cp config/database.example.yml config/database.ymlOpen config/database.yml and add the user (sparc) and password that you set above.
sparc database has to already be created above with sparc user as owner.
Import sparc database dump.
sudo -u postgres pg_restore -d sparc sparc.pgcNote: This process has not been tested with Postgres 13 on Enterprise Linux 9. The existing database dump from CentOS 7 was imported as noted above instead.
Before you get too much farther, you will need to locate and add Burials.xlsx, which is not stored in this repository. Otherwise, comment out Burials at the bottom of seeds.rb.
Now set your dev and test databases up! This step may take a few minutes while it loads all the spreadsheet data.
rails db:setupYou can also do it by hand, if you prefer:
rails db:create
rails db:migrate
rails db:seedThere are several other steps that need to be taken to prepare the database.
Add descriptions to units and zones:
rails units:descriptionMark images which do exist on the file system. You will need to generate that list ahead of time by going to the IIIF directory and running:
find field polaroids -type f > all_mediaserver_images.txtCopy the text file results to reports/all_mediaserver_images.txt and then run:
rails images:file_existsIf you don't care if some images are broken and just want to see some images (for example, if working in development), run the following in your rails console (rails c):
Image.update_all(file_exists: true)rails sYou can view the site at localhost:3000
Images should be stored in app/assets/images/field in the large and thumb directories. To check if all the images and there and if each image in the directories has metadata, run the following, respectively:
rails images:find_missing
rails images:find_extraIn the event that new documents have been added, filenames altered, etc, you may need to regenerate the file used to seed the database. First, open up lib/tasks/document.rake and verify that the path to the jpegs is correct, for your system. The path was hardcoded because it is (hopefully) unlikely that the documents.csv file will need to be regenerated.
DOCUMENT_PATH = "/your/path/here"Verify that exiftool is installed on your system, then run:
rails documents:create_csvNOTE: This may take up to an hour to run, depending on your machine! The script pulls out metadata from the images with exiftool, which is where the bottleneck occurs.
To generate assets (production only):
rails assets:precompile RAILS_ENV=productionrails testBecause of the way that foreign keys are set up currently, in order to run the tests you will have to grant the postgres role you're using superuser privileges on the rails test database. If you just want to grant sweeping privileges, you can do this:
sudo -u postgres psql:
# Add privileges
ALTER ROLE sparc WITH SUPERUSER;
# Revoke
ALTER ROLE sparc WITH NOSUPERUSER;
# Exit psql shell
exit # or Ctrl+DI do not recommend doing the above in a production environment. In the near future we should figure out how we would like cascading deletes, etc, to work for these PKs.
When asked to redact images, take the following steps.
Verify which image you need to redact. The files themselves are arranged in two directories, polaroid and field, but while the filenames have nothing prepended to the number, the database lists polaroids as PA0#####. If you are redacting a polaroid, make sure that you use PA0 in the following commands.
Navigate to the production rails application.
** USE EXTREME CAUTION WHEN RUNNING CONSOLE DB OPERATIONS ON THE PRODUCTION SERVER **
rails c production
> # field image
> i = Image.find_by(image_no: "12038")
> i.update_attributes(image_human_remain_id: 2)
>
> # polaroid image
> i = Image.find_by(image_no: "PA012038")
> i.update_attributes(image_human_remain_id: 2)
> exitRefresh the website to make sure that the image is no longer available in the gallery views.
Now manually move the redacted image. Navigate to the mediaserver directory housing the images and move the image in question into the sensitive directory. This means it will not be available to view through the media server / IIIF URLs.