Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a user preference system, and allowed interval size to be set. #3

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
28b4c8a
Added a user preference system, and allowed interval size to be set.
Mutant Nov 14, 2013
565e2df
Added some styling to change password / preferences screens
Mutant Nov 19, 2013
c189737
Added option of logins via LDAP.
Mutant Nov 25, 2013
3529e55
Don't require LDAP users to have a password.
Mutant Nov 25, 2013
7b1f9bb
Remove LDAP config from the default
Mutant Nov 26, 2013
3a8a340
Fix to migration
Mutant Nov 26, 2013
f5550be
Added postgres schema, and added missing table to sqlite schema.
Mutant Nov 26, 2013
4e466ed
Generate an API key for new users, if not supplied.
Mutant Nov 26, 2013
b217ee0
Fix order by clause for first_wr_system
Mutant Nov 26, 2013
897f2eb
Prevent LDAP users from updating their passwords
Mutant Nov 26, 2013
436c0d7
Display API key on preferences screen.
Mutant Nov 26, 2013
1a18d0a
Allow user to select which WRMS systems to use
Mutant Nov 26, 2013
4c5357f
Added a config option to only allow ldap logins
Mutant Dec 4, 2013
2d2870a
Allow it to work on older Dancer versions
Mutant Dec 4, 2013
8cbb6c2
Minor bug fix
Mutant Jun 13, 2014
9db605d
Added vagrant setup
Mutant Jun 13, 2014
784c399
Only load Net::LDAP if it's needed
Mutant Jun 13, 2014
a506995
Merge remote-tracking branch 'origin/master' into vagrant
Mutant Jun 13, 2014
40a5e03
Fixed vagrant bootstrap
Mutant Jun 19, 2014
c046c5a
Added some extra things to vagrant bookstrap
Jun 29, 2014
a3a1866
Added instructions for using vagrant.
Jun 29, 2014
36db8fe
Display total hours used for each day
Jun 29, 2014
05c7bd8
Make daily totals a preference
Jun 30, 2014
bcbec59
Make sure ldap_only conf parameter is passed to login template
Jul 4, 2014
dde62ff
Merge remote-tracking branch 'origin/master' into daily_totals
Jul 4, 2014
3be9c68
Log the client's IP address on LDAP error.
Mutant Nov 23, 2015
0977e7f
Log the actual IP if request comes through a proxy
Mutant Nov 23, 2015
8fa8ba4
Changed log format to allow easier parsing
Mutant Nov 23, 2015
191c838
Change dev session location
Mutant Nov 23, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/tks-data
/var
/logs/*.log
/.vagrant
.project
122 changes: 122 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.

# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise64"

# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://files.vagrantup.com/precise64.box"

config.vm.synced_folder ".", "/vagrant", :nfs => true

config.vm.provision :shell, :path=>"./bin/bootstrap-vagrant.sh"

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network :forwarded_port, guest: 80, host: 8080

# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network :private_network, ip: "192.168.33.12"

# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network :public_network

# If true, then any SSH connections made will enable agent forwarding.
# Default value: false
# config.ssh.forward_agent = true

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"

# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider :virtualbox do |vb|
# # Don't boot with headless mode
# vb.gui = true
#
# # Use VBoxManage to customize the VM. For example to change memory:
# vb.customize ["modifyvm", :id, "--memory", "1024"]
# end
#
# View the documentation for the provider you're using for more
# information on available options.

# Enable provisioning with Puppet stand alone. Puppet manifests
# are contained in a directory path relative to this Vagrantfile.
# You will need to create the manifests directory and a manifest in
# the file base.pp in the manifests_path directory.
#
# An example Puppet manifest to provision the message of the day:
#
# # group { "puppet":
# # ensure => "present",
# # }
# #
# # File { owner => 0, group => 0, mode => 0644 }
# #
# # file { '/etc/motd':
# # content => "Welcome to your Vagrant-built virtual machine!
# # Managed by Puppet.\n"
# # }
#
# config.vm.provision :puppet do |puppet|
# puppet.manifests_path = "manifests"
# puppet.manifest_file = "site.pp"
# end

# Enable provisioning with chef solo, specifying a cookbooks path, roles
# path, and data_bags path (all relative to this Vagrantfile), and adding
# some recipes and/or roles.
#
# config.vm.provision :chef_solo do |chef|
# chef.cookbooks_path = "../my-recipes/cookbooks"
# chef.roles_path = "../my-recipes/roles"
# chef.data_bags_path = "../my-recipes/data_bags"
# chef.add_recipe "mysql"
# chef.add_role "web"
#
# # You may also specify custom JSON attributes:
# chef.json = { :mysql_password => "foo" }
# end

# Enable provisioning with chef server, specifying the chef server URL,
# and the path to the validation key (relative to this Vagrantfile).
#
# The Opscode Platform uses HTTPS. Substitute your organization for
# ORGNAME in the URL and validation key.
#
# If you have your own Chef Server, use the appropriate URL, which may be
# HTTP instead of HTTPS depending on your configuration. Also change the
# validation key to validation.pem.
#
# config.vm.provision :chef_client do |chef|
# chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
# chef.validation_key_path = "ORGNAME-validator.pem"
# end
#
# If you're using the Opscode platform, your validator client is
# ORGNAME-validator, replacing ORGNAME with your organization name.
#
# If you have your own Chef Server, the default validation client name is
# chef-validator, unless you changed the configuration.
#
# chef.validation_client_name = "ORGNAME-validator"
end
18 changes: 18 additions & 0 deletions bin/bootstrap-vagrant.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

apt-get update
DEBIAN_FRONTEND=noninteractive apt-get -y install liblocal-lib-perl sqlite3 curl postgresql-9.1 libdbix-class-perl libdancer-perl libdbd-pg-perl libdbix-class-schema-loader-perl libhtml-fillinform-perl libdatetime-perl libtemplate-perl libjson-perl libdancer-plugin-dbic-perl libcss-minifier-xs-perl libwww-mechanize-perl libmime-lite-perl libdatetime-format-pg-perl curl make

curl -L http://cpanmin.us | perl - App::cpanminus

cpanm --installdeps /vagrant

sudo -u postgres createuser -d --no-password --no-superuser --no-createrole vagrant
sudo -u vagrant createdb tksweb-vagrant
sudo -u vagrant psql -f /vagrant/data/schema-postgres.sql tksweb-vagrant
sudo -u vagrant psql -f /vagrant/data/vagrant_user.sql tksweb-vagrant

mkdir -p /vagrant/var/dev-sessions



2 changes: 2 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ charset: "UTF-8"
#
#template: "template_toolkit"

logger_format: "[%T] [%P] %L %D %m"

template: "template_toolkit"
engines:
template_toolkit:
Expand Down
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ requires 'CSS::Minifier::XS';
requires 'JavaScript::Minifier::XS';
requires 'MIME::Lite';
requires 'YAML';
requires 'HTML::FillInForm';

recommends 'Starman';

Expand Down
10 changes: 10 additions & 0 deletions data/migrations/003-user-preferences.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BEGIN;

CREATE TABLE user_preference (
preference_id INTEGER CONSTRAINT PK_PREFERENCE PRIMARY KEY AUTOINCREMENT,
app_user_id INTEGER NOT NULL,
preference TEXT NOT NULL,
value TEXT NOT NULL
);

COMMIT;
63 changes: 63 additions & 0 deletions data/migrations/004-wr-system-many-to-many.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
BEGIN;

CREATE TABLE "main"."user_wr_system" (
"wr_system_id" INTEGER NOT NULL,
"app_user_id" INTEGER NOT NULL,
PRIMARY KEY (wr_system_id, app_user_id),

CONSTRAINT FK_USER_M2M
FOREIGN KEY (app_user_id) REFERENCES app_user (app_user_id),

CONSTRAINT FK_WR_SYSTEM_M2M
FOREIGN KEY (wr_system_id) REFERENCES wr_system (wr_system_id)
);

ALTER TABLE wr_system RENAME TO old_wr_system;

CREATE TABLE wr_system (
wr_system_id INTEGER CONSTRAINT PK_WR_SYSTEM PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
description TEXT NOT NULL,
request_url TEXT NOT NULL DEFAULT '',
colour_code INTEGER NOT NULL DEFAULT '0',
is_default BOOLEAN NOT NULL DEFAULT false
);

INSERT INTO wr_system
SELECT
wr_system_id
,name
,description
,request_url
,colour_code,
'true'
FROM old_wr_system
ORDER BY wr_system_id;

UPDATE wr_system SET is_default = 'true' WHERE wr_system_id = (select MIN(wr_system_id) from wr_system);

DROP TABLE old_wr_system;

ALTER TABLE app_user RENAME TO old_app_user;

CREATE TABLE app_user (
app_user_id INTEGER CONSTRAINT PK_APP_USER PRIMARY KEY AUTOINCREMENT,
email TEXT NOT NULL UNIQUE,
full_name TEXT NOT NULL,
password TEXT,
reset_key TEXT NULL UNIQUE,
api_key TEXT NULL UNIQUE,
status TEXT NOT NULL DEFAULT 'active',
admin BOOLEAN NOT NULL DEFAULT '0'
);

INSERT INTO app_user
SELECT
*
FROM old_app_user
ORDER BY app_user_id;

DROP TABLE old_app_user;

COMMIT;

26 changes: 21 additions & 5 deletions data/schema-lite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CREATE TABLE app_user (
app_user_id INTEGER CONSTRAINT PK_APP_USER PRIMARY KEY AUTOINCREMENT,
email TEXT NOT NULL UNIQUE,
full_name TEXT NOT NULL,
password TEXT NOT NULL,
password TEXT,
reset_key TEXT NULL UNIQUE,
api_key TEXT NULL UNIQUE,
status TEXT NOT NULL DEFAULT 'active',
Expand All @@ -13,14 +13,11 @@ CREATE TABLE app_user (

CREATE TABLE wr_system (
wr_system_id INTEGER CONSTRAINT PK_WR_SYSTEM PRIMARY KEY AUTOINCREMENT,
app_user_id INTEGER NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
request_url TEXT NOT NULL DEFAULT '',
colour_code INTEGER NOT NULL DEFAULT '0',

CONSTRAINT FK_WR_SYSTEM_USER
FOREIGN KEY (app_user_id) REFERENCES app_user (app_user_id)
is_default BOOLEAN NOT NULL DEFAULT false
);

CREATE TABLE activity (
Expand All @@ -39,5 +36,24 @@ CREATE TABLE activity (
FOREIGN KEY (wr_system_id) REFERENCES wr_system (wr_system_id)
);

CREATE TABLE user_preference (
preference_id INTEGER CONSTRAINT PK_PREFERENCE PRIMARY KEY AUTOINCREMENT,
app_user_id INTEGER NOT NULL,
preference TEXT NOT NULL,
value TEXT NOT NULL
);

CREATE TABLE user_wr_system (
wr_system_id INTEGER NOT NULL,
app_user_id INTEGER NOT NULL,
PRIMARY KEY (wr_system_id, app_user_id),

CONSTRAINT FK_USER_M2M
FOREIGN KEY (app_user_id) REFERENCES app_user (app_user_id),

CONSTRAINT FK_WR_SYSTEM_M2M
FOREIGN KEY (wr_system_id) REFERENCES wr_system (wr_system_id)
);

COMMIT;

64 changes: 64 additions & 0 deletions data/schema-postgres.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
BEGIN;

CREATE TABLE app_user (
app_user_id SERIAL NOT NULL,
email TEXT NOT NULL UNIQUE,
full_name TEXT NOT NULL,
password TEXT,
reset_key TEXT NULL UNIQUE,
api_key TEXT NULL UNIQUE,
status TEXT NOT NULL DEFAULT 'active',
admin BOOLEAN NOT NULL DEFAULT '0',
PRIMARY KEY (app_user_id)
);

CREATE TABLE wr_system (
wr_system_id SERIAL NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
request_url TEXT NOT NULL DEFAULT '',
colour_code INTEGER NOT NULL DEFAULT '0',
is_default BOOLEAN NOT NULL DEFAULT false,
PRIMARY KEY (wr_system_id)
);

CREATE TABLE activity (
activity_id SERIAL NOT NULL,
app_user_id INTEGER NOT NULL,
date_time TIMESTAMP NOT NULL,
duration INTEGER NOT NULL,
wr_system_id INTEGER NOT NULL,
wr_number TEXT,
description TEXT,

PRIMARY KEY (activity_id),

CONSTRAINT FK_ACTIVITY_USER
FOREIGN KEY (app_user_id) REFERENCES app_user (app_user_id),

CONSTRAINT FK_ACTIVITY_WR_SYSTEM
FOREIGN KEY (wr_system_id) REFERENCES wr_system (wr_system_id)
);

CREATE TABLE user_preference (
preference_id SERIAL NOT NULL,
app_user_id INTEGER NOT NULL,
preference TEXT NOT NULL,
value TEXT NOT NULL,
PRIMARY KEY(preference_id)
);

CREATE TABLE user_wr_system (
"wr_system_id" INTEGER NOT NULL,
"app_user_id" INTEGER NOT NULL,
PRIMARY KEY (wr_system_id, app_user_id),

CONSTRAINT FK_USER_M2M
FOREIGN KEY (app_user_id) REFERENCES app_user (app_user_id),

CONSTRAINT FK_WR_SYSTEM_M2M
FOREIGN KEY (wr_system_id) REFERENCES wr_system (wr_system_id)
);

COMMIT;

24 changes: 24 additions & 0 deletions data/vagrant_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

INSERT INTO app_user (
email, full_name, password, reset_key, api_key, status, admin
) VALUES (
'vagrant', 'vagrant', '{CRYPT}$2a$04$1.HMmfFTiYWfHesuX1WJY.JQALFjk0M0cbFh/CqH0T0RpviF5IGSK', NULL,
'API_KEY',
'active', 't'
);

INSERT INTO wr_system (
name, description, request_url
) VALUES (
'catalyst', 'Catalyst WRMS',
'https://wrms.catalyst.net.nz/wr.php?request_id='
);

INSERT INTO user_wr_system(
wr_system_id, app_user_id
) VALUES (
(select wr_system_id from wr_system where name = 'catalyst'),
(select app_user_id from app_user where full_name = 'vagrant')
);


Loading