added admin and deadmin rake tasks
This commit is contained in:
parent
a04e519b4e
commit
0337a3cb4e
110
README.md
110
README.md
|
@ -13,93 +13,93 @@
|
||||||
|
|
||||||
#### PostgreSQL
|
#### PostgreSQL
|
||||||
|
|
||||||
```
|
$ sudo -u postgres psql -d template1
|
||||||
$ sudo -u postgres psql -d template1
|
template1=# CREATE USER justask CREATEDB;
|
||||||
template1=# CREATE USER justask CREATEDB;
|
template1=# CREATE DATABASE justask_production OWNER justask;
|
||||||
template1=# CREATE DATABASE justask_production OWNER justask;
|
template1=# \q
|
||||||
template1=# \q
|
|
||||||
```
|
|
||||||
|
|
||||||
Try connecting to the database:
|
Try connecting to the database:
|
||||||
|
|
||||||
```
|
$ psql -U justask -d justask_production
|
||||||
$ psql -U justask -d justask_production
|
|
||||||
```
|
|
||||||
|
|
||||||
#### MySQL
|
#### MySQL
|
||||||
|
|
||||||
```
|
$ mysql -u root -p
|
||||||
$ mysql -u root -p
|
# change 'hack me' in the command below to a real password
|
||||||
# change 'hack me' in the command below to a real password
|
mysql> CREATE USER 'justask'@'localhost' IDENTIFIED BY 'hack me';
|
||||||
mysql> CREATE USER 'justask'@'localhost' IDENTIFIED BY 'hack me';
|
mysql> SET storage_engine=INNODB;
|
||||||
mysql> SET storage_engine=INNODB;
|
mysql> CREATE DATABASE IF NOT EXISTS `justask_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
|
||||||
mysql> CREATE DATABASE IF NOT EXISTS `justask_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
|
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES ON `justask_production`.* TO 'justask'@'localhost';
|
||||||
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES ON `justask_production`.* TO 'justask'@'localhost';
|
mysql> \q
|
||||||
mysql> \q
|
|
||||||
```
|
|
||||||
|
|
||||||
Try connecting to the database:
|
Try connecting to the database:
|
||||||
|
|
||||||
```
|
$ mysql -u justask -p -D justask_production
|
||||||
$ mysql -u justask -p -D justask_production
|
|
||||||
```
|
|
||||||
|
|
||||||
### justask
|
### justask
|
||||||
|
|
||||||
#### Clone the Source
|
#### Clone the Source
|
||||||
|
|
||||||
```
|
$ git clone https://git.rrerr.net/nilsding/justask.git justask
|
||||||
$ git clone https://git.rrerr.net/nilsding/justask.git justask
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Configure It
|
#### Configure It
|
||||||
|
|
||||||
```
|
# Change into the justask directory
|
||||||
# Change into the justask directory
|
$ cd justask
|
||||||
$ cd justask
|
|
||||||
|
|
||||||
# Copy the example config
|
# Copy the example config
|
||||||
$ cp config/justask.yml.example config/justask.yml
|
$ cp config/justask.yml.example config/justask.yml
|
||||||
|
|
||||||
# Edit the configuration file
|
# Edit the configuration file
|
||||||
$ vi config/justask.yml
|
$ vi config/justask.yml
|
||||||
```
|
|
||||||
|
|
||||||
#### Database Configuration
|
#### Database Configuration
|
||||||
|
|
||||||
```
|
# PostgreSQL only:
|
||||||
# PostgreSQL only:
|
$ cp config/database.yml.postgres config/database.yml
|
||||||
$ cp config/database.yml.postgres config/database.yml
|
|
||||||
|
|
||||||
# MySQL only:
|
# MySQL only:
|
||||||
$ cp config/database.yml.mysql config/database.yml
|
$ cp config/database.yml.mysql config/database.yml
|
||||||
|
|
||||||
# MySQL and remote PostgreSQL only:
|
# MySQL and remote PostgreSQL only:
|
||||||
$ vi config/database.yml
|
$ vi config/database.yml
|
||||||
|
|
||||||
# Both:
|
# Both:
|
||||||
# Make database.yml readable only for you
|
# Make database.yml readable only for you
|
||||||
chmod o-rwx config/database.yml
|
chmod o-rwx config/database.yml
|
||||||
```
|
|
||||||
|
|
||||||
#### Install Gems
|
#### Install Gems
|
||||||
|
|
||||||
```
|
# For PostgreSQL (note: the option says "without ... mysql")
|
||||||
# For PostgreSQL (note: the option says "without ... mysql")
|
$ bundle install --deployment --without development test mysql
|
||||||
$ bundle install --deployment --without development test mysql
|
|
||||||
|
|
||||||
# Or, if you use MySQL
|
# Or, if you use MySQL
|
||||||
$ bundle install --deployment --without development test postgres
|
$ bundle install --deployment --without development test postgres
|
||||||
```
|
|
||||||
|
|
||||||
#### Initialize Database
|
#### Initialize Database
|
||||||
|
|
||||||
```
|
$ bundle exec rake db:migrate RAILS_ENV=production
|
||||||
$ bundle exec rake db:migrate RAILS_ENV=production
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Compile Assets
|
#### Compile Assets
|
||||||
|
|
||||||
```
|
$ bundle exec rake assets:precompile RAILS_ENV=production
|
||||||
$ bundle exec rake assets:precompile RAILS_ENV=production
|
|
||||||
```
|
#### Run the server
|
||||||
|
|
||||||
|
# Production mode:
|
||||||
|
$ mkdir -p ./tmp/sockets/
|
||||||
|
$ bundle exec unicorn -E production -l unix:./tmp/sockets/justask.sock
|
||||||
|
|
||||||
|
# Development mode:
|
||||||
|
$ bundle exec rails server
|
||||||
|
|
||||||
|
Create an account on your justask installation.
|
||||||
|
|
||||||
|
To make yourself an admin, just execute:
|
||||||
|
|
||||||
|
$ bundle exec rake 'justask:admin[your_username]' RAILS_ENV=production
|
||||||
|
|
||||||
|
If you want to remove admin status from a certain user, you can do this:
|
||||||
|
|
||||||
|
$ bundle exec rake 'justask:deadmin[get_rekt]' RAILS_ENV=production
|
||||||
|
|
||||||
|
|
20
Rakefile
20
Rakefile
|
@ -23,4 +23,24 @@ namespace :justask do
|
||||||
progress.increment
|
progress.increment
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "Gives admin status to an user."
|
||||||
|
task :admin, [:screen_name] => :environment do |t, args|
|
||||||
|
fail "screen name required" if args[:screen_name].nil?
|
||||||
|
user = User.find_by_screen_name(args[:screen_name])
|
||||||
|
fail "user #{args[:screen_name]} not found" if user.nil?
|
||||||
|
user.admin = true
|
||||||
|
user.save!
|
||||||
|
puts "#{user.screen_name} is now an admin"
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Removes admin status from an user."
|
||||||
|
task :deadmin, [:screen_name] => :environment do |t, args|
|
||||||
|
fail "screen name required" if args[:screen_name].nil?
|
||||||
|
user = User.find_by_screen_name(args[:screen_name])
|
||||||
|
fail "user #{args[:screen_name]} not found" if user.nil?
|
||||||
|
user.admin = false
|
||||||
|
user.save!
|
||||||
|
puts "#{user.screen_name} no longer an admin"
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue