Skip to content
Snippets Groups Projects
Commit c28d7b18 authored by Iain Bryson's avatar Iain Bryson
Browse files

Initial version.

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 393 additions and 0 deletions
.DS_Store 0 → 100644
File added
Gemfile 0 → 100644
source 'https://rubygems.org'
# Declare your gem's dependencies in dtu_core.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
# To use a debugger
# gem 'byebug', group: [:development, :test]
gem 'rubycas-client', '~> 2.3.8', :git => 'https://github.com/rubycas/rubycas-client'
gem 'dtu-auth', :path => './dtu-auth'
gem 'dtu-file-management', :path => './dtu-file-management'
GIT
remote: https://github.com/rubycas/rubycas-client
revision: 195a4b70333029be474b0ac70efdc85bd4288861
specs:
rubycas-client (2.3.10.rc1)
activesupport
PATH
remote: .
specs:
dtu-core (0.0.1)
dtu-auth
dtu-file-management
rails (~> 4.2.5)
PATH
remote: ./dtu-auth
specs:
dtu-auth (0.0.0)
PATH
remote: ./dtu-file-management
specs:
dtu-file-management (0.0.0)
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.2.7)
actionpack (= 4.2.7)
actionview (= 4.2.7)
activejob (= 4.2.7)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.7)
actionview (= 4.2.7)
activesupport (= 4.2.7)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.7)
activesupport (= 4.2.7)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
activejob (4.2.7)
activesupport (= 4.2.7)
globalid (>= 0.3.0)
activemodel (4.2.7)
activesupport (= 4.2.7)
builder (~> 3.1)
activerecord (4.2.7)
activemodel (= 4.2.7)
activesupport (= 4.2.7)
arel (~> 6.0)
activesupport (4.2.7)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
builder (3.2.2)
concurrent-ruby (1.0.2)
erubis (2.7.0)
globalid (0.3.7)
activesupport (>= 4.1.0)
i18n (0.7.0)
json (1.8.3)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.4)
mime-types (>= 1.16, < 4)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.9.0)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
pkg-config (1.1.7)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.7)
actionmailer (= 4.2.7)
actionpack (= 4.2.7)
actionview (= 4.2.7)
activejob (= 4.2.7)
activemodel (= 4.2.7)
activerecord (= 4.2.7)
activesupport (= 4.2.7)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.7)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.7)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (4.2.7)
actionpack (= 4.2.7)
activesupport (= 4.2.7)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (11.2.2)
sprockets (3.7.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.1.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.19.1)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
PLATFORMS
ruby
DEPENDENCIES
dtu-auth!
dtu-core!
dtu-file-management!
rubycas-client (~> 2.3.8)!
BUNDLED WITH
1.10.6
Copyright 2016 Iain Bryson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
= DtuCore
This project rocks and uses MIT-LICENSE.
\ No newline at end of file
Rakefile 0 → 100644
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
require 'rdoc/task'
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'DtuCore'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'
load 'rails/tasks/statistics.rake'
Bundler::GemHelper.install_tasks
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end
task default: :test
File added
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require_tree .
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/
File added
module DtuCore
class ApplicationController < ActionController::Base
include DtuCore::SessionsHelper
end
end
class DtuCore::SessionsController < DtuCore::ApplicationController
skip_before_filter :require_login
def new
end
def create
#user = User.find_by(email: params[:session][:email].downcase)
user = params[:session][:username].downcase
user_info = DTUAuth::AuthorizationManager.find_user(user)
if user_info # && user.authenticate(params[:session][:password])
logger.info "User #{user_info.ai} logged in successfully."
log_in user_info
redirect_to '/home'
else
logger.info "User #{user} failed to log in."
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
end
def destroy
log_out
CASClient::Frameworks::Rails::Filter.logout(self) if Rails.env.production?
redirect_to '/' if !Rails.env.production?
end
end
File added
module DtuCore
module ApplicationHelper
end
end
module DtuCore::SessionsHelper
# Logs in the given user.
def log_in(user_info)
@current_user = user_info
session[:user_id] = user_info._id
end
# Returns the current logged-in user (if any).
def current_user
@current_user ||= DTUAuth::AuthorizationManager.find_user(current_user_id)
end
def current_user_id
return session[:cas_user] if Rails.env.production?
return session[:user_id] if !Rails.env.production?
end
# Returns true if the user is logged in, false otherwise.
def logged_in?
!current_user.nil?
end
def log_out
session.delete(:user_id)
@current_user = nil
end
def is_admin(course_id)
#Rails.logger.info(roles_for_course(course_id))
#Rails.logger.info "RESULT #{roles_for_course(course_id).include?('administrator')}"
roles_for_course(course_id).include?('administrator')
end
def roles_for_course(course_id)
Rails.logger.debug "checking admin status for #{current_user_id} in #{course_id}"
groups_for_user = DTUAuth::AuthorizationManager.instance.user_roles[current_user_id]
return [] unless groups_for_user
groups = groups_for_user[course_id]
groups ? groups.map{ |g,k| k[0].acl } : []
end
def current_user_roles_for_group(course_id, group_name)
Group.where({ :course_id => course_id, :user_id => current_user_id, :name => group_name}).map{ |g| g.acl }
end
def current_user_courses_for_acl(acl)
groups_for_user = DTUAuth::AuthorizationManager.instance.user_roles[current_user_id]
return [] unless groups_for_user
groups = groups_for_user.select{ |course, group_info| group_info.values.map{ |roles| roles.map(&:acl).include? acl } }
groups.map{ |course, group_info| course }
end
end
<% provide(:title, "Log in") %>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1>Log in</h1>
<%= form_for(:session, url: login_path) do |f| %>
<div class="form-group">
<%= f.label :username %>
<%= f.text_field :username, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.submit "Log in", class: "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
<!DOCTYPE html>
<html>
<head>
<title>DtuCore</title>
<%= stylesheet_link_tag "dtu_core/application", media: "all" %>
<%= javascript_include_tag "dtu_core/application" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/dtu_core/engine', __FILE__)
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
require 'rails/all'
require 'rails/engine/commands'
require File.expand_path('../boot', __FILE__)
require "rails"
module DtuCore
class Application < Rails::Application
config.dtu_data = {:course => ENV['COURSE_NAME'],
:root_path => ENV['DTU_DATA_ROOT'] || "/dtu-data",
:filemanager_path => ENV['DTU_FILEMANAGER'] || "/filemanager",
:source => "core" }
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment