hicube 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +24 -0
- data/app/assets/images/hicube/avatar.png +0 -0
- data/app/assets/images/hicube/dnd.png +0 -0
- data/app/assets/images/hicube/noimagefound.png +0 -0
- data/app/assets/javascripts/hicube/accounts.js +0 -0
- data/app/assets/javascripts/hicube/application.js +52 -0
- data/app/assets/javascripts/hicube/contents.js +2 -0
- data/app/assets/javascripts/hicube/documents.js +10 -0
- data/app/assets/javascripts/hicube/pages.coffee +7 -0
- data/app/assets/javascripts/hicube/public/pages.coffee +0 -0
- data/app/assets/javascripts/hicube/snippets.coffee +0 -0
- data/app/assets/javascripts/hicube.js +128 -0
- data/app/assets/stylesheets/hicube/accounts.css +0 -0
- data/app/assets/stylesheets/hicube/application.css +22 -0
- data/app/assets/stylesheets/hicube/contents.css +4 -0
- data/app/assets/stylesheets/hicube/documents.css +24 -0
- data/app/assets/stylesheets/hicube/pages.css +10 -0
- data/app/assets/stylesheets/hicube/public/pages.css +4 -0
- data/app/assets/stylesheets/hicube/snippets.css +4 -0
- data/app/assets/stylesheets/hicube.css +18 -0
- data/app/controllers/hicube/accounts_controller.rb +66 -0
- data/app/controllers/hicube/application_controller.rb +181 -0
- data/app/controllers/hicube/base_controller.rb +148 -0
- data/app/controllers/hicube/contents_controller.rb +53 -0
- data/app/controllers/hicube/documents_controller.rb +85 -0
- data/app/controllers/hicube/pages_controller.rb +106 -0
- data/app/controllers/hicube/public/base_controller.rb +92 -0
- data/app/controllers/hicube/public/pages_controller.rb +62 -0
- data/app/controllers/hicube/snippets_controller.rb +100 -0
- data/app/helpers/hicube/application_helper.rb +74 -0
- data/app/helpers/hicube/contents_helper.rb +4 -0
- data/app/helpers/hicube/documents_helper.rb +4 -0
- data/app/helpers/hicube/pages_helper.rb +4 -0
- data/app/helpers/hicube/public/pages_helper.rb +19 -0
- data/app/helpers/hicube/snippets_helper.rb +4 -0
- data/app/mailers/hicube/application_mailer.rb +8 -0
- data/app/mailers/hicube/page_mailer.rb +13 -0
- data/app/models/hicube/account.rb +26 -0
- data/app/models/hicube/content.rb +30 -0
- data/app/models/hicube/document.rb +46 -0
- data/app/models/hicube/page.rb +98 -0
- data/app/models/hicube/snippet.rb +20 -0
- data/app/models/hicube/tag.rb +19 -0
- data/app/models/hicube/user.rb +67 -0
- data/app/uploaders/hicube/file_uploader.rb +53 -0
- data/app/uploaders/hicube/image_uploader.rb +53 -0
- data/app/views/devise/mailer/confirmation_instructions.html.slim +8 -0
- data/app/views/devise/mailer/reset_password_instructions.html.slim +12 -0
- data/app/views/devise/mailer/unlock_instructions.html.slim +10 -0
- data/app/views/devise/passwords/edit.html.slim +22 -0
- data/app/views/devise/passwords/new.html.slim +15 -0
- data/app/views/devise/sessions/new.html.slim +24 -0
- data/app/views/hicube/accounts/_form.html.slim +31 -0
- data/app/views/hicube/accounts/_navigation.html.slim +25 -0
- data/app/views/hicube/accounts/edit.html.slim +4 -0
- data/app/views/hicube/accounts/index.html.slim +12 -0
- data/app/views/hicube/accounts/new.html.slim +4 -0
- data/app/views/hicube/accounts/show.html.slim +21 -0
- data/app/views/hicube/base/_flash.html.slim +36 -0
- data/app/views/hicube/base/_footer.html.slim +10 -0
- data/app/views/hicube/base/_header.html.slim +31 -0
- data/app/views/hicube/base/_navigation.html.slim +16 -0
- data/app/views/hicube/base/_sidebar.html.slim +122 -0
- data/app/views/hicube/contents/_form.html.slim +11 -0
- data/app/views/hicube/contents/edit.html.slim +9 -0
- data/app/views/hicube/contents/new.html.slim +9 -0
- data/app/views/hicube/documents/_form.html.slim +18 -0
- data/app/views/hicube/documents/_navigation.html.slim +25 -0
- data/app/views/hicube/documents/edit.html.slim +9 -0
- data/app/views/hicube/documents/index.html.slim +57 -0
- data/app/views/hicube/documents/new.html.slim +9 -0
- data/app/views/hicube/page_mailer/notify.html.slim +1 -0
- data/app/views/hicube/page_mailer/notify.text.slim +8 -0
- data/app/views/hicube/pages/_form.html.slim +153 -0
- data/app/views/hicube/pages/_navigation.html.slim +27 -0
- data/app/views/hicube/pages/edit.html.slim +9 -0
- data/app/views/hicube/pages/index.html.slim +32 -0
- data/app/views/hicube/pages/index.json.jbuilder +4 -0
- data/app/views/hicube/pages/new.html.slim +9 -0
- data/app/views/hicube/pages/show.html.slim +2 -0
- data/app/views/hicube/pages/show.json.jbuilder +1 -0
- data/app/views/hicube/public/pages/edit.html.slim +11 -0
- data/app/views/hicube/public/pages/show.html.slim +17 -0
- data/app/views/hicube/snippets/_form.html.slim +21 -0
- data/app/views/hicube/snippets/_navigation.html.slim +25 -0
- data/app/views/hicube/snippets/edit.html.slim +9 -0
- data/app/views/hicube/snippets/index.html.slim +25 -0
- data/app/views/hicube/snippets/new.html.slim +9 -0
- data/app/views/layouts/hicube/application.html.slim +26 -0
- data/app/views/layouts/hicube.html.slim +10 -0
- data/app/views/layouts/mailer.html.slim +3 -0
- data/app/views/layouts/mailer.text.slim +1 -0
- data/config/initializers/carrierwave.rb +12 -0
- data/config/initializers/devise.rb +282 -0
- data/config/initializers/liquid.rb +4 -0
- data/config/initializers/markdown.rb +7 -0
- data/config/locales/en.yml +18 -0
- data/config/routes.rb +40 -0
- data/lib/generators/hicube/install/install_generator.rb +49 -0
- data/lib/generators/hicube/install/templates/generate_hicube_accounts.rb +12 -0
- data/lib/generators/hicube/install/templates/generate_hicube_pages.rb +14 -0
- data/lib/generators/hicube/install/templates/generate_hicube_users.rb +14 -0
- data/lib/generators/hicube/install/templates/sitemap.rb +17 -0
- data/lib/hicube/engine.rb +6 -0
- data/lib/hicube/liquid/tags/content.rb +31 -0
- data/lib/hicube/liquid/tags/img.rb +21 -0
- data/lib/hicube/liquid/tags/snippet.rb +40 -0
- data/lib/hicube/liquid/tags/url.rb +21 -0
- data/lib/hicube/version.rb +3 -0
- data/lib/hicube.rb +30 -0
- data/lib/tasks/hicube_tasks.rake +4 -0
- metadata +576 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: b5affadc131a11624d44c31ab826dc26c861360d
|
|
4
|
+
data.tar.gz: 33a947974e3066e55c6dc463b252464d890d7b0d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 700403cf2fabc750774ed3f044fcc314d87cbc6fa068c84bc218a5aa5a0b7b0df826c16d02dc19628d7c750f237366ccd7f54505031add00afd12cc974ab8b71
|
|
7
|
+
data.tar.gz: 1e89e426345392181c17f5621cd3d0e0e2ebe4294cfcb42b656eb86dc0c23b5b9fbcf2c4a2d1c662fbcd01cbabff6f8583a7cf223efd17c4866ea815c8c79d63
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2015 Gaurav Cheema
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'rdoc/task'
|
|
8
|
+
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'Hicube'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
load 'rails/tasks/statistics.rake'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
Bundler::GemHelper.install_tasks
|
|
24
|
+
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//= require jquery
|
|
2
|
+
//= require jquery.turbolinks
|
|
3
|
+
//= require jquery_ujs
|
|
4
|
+
//= require jquery-ui
|
|
5
|
+
//= require turbolinks
|
|
6
|
+
//= require twitter/bootstrap
|
|
7
|
+
//= require jquery-fileupload
|
|
8
|
+
|
|
9
|
+
//= require dataTables/jquery.dataTables
|
|
10
|
+
//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
|
|
11
|
+
//= require dataTables/extras/dataTables.responsive
|
|
12
|
+
//= require icheck
|
|
13
|
+
//= require codemirror
|
|
14
|
+
//= require codemirror/modes/xml
|
|
15
|
+
//= require codemirror/modes/htmlembedded
|
|
16
|
+
//= require codemirror/modes/htmlmixed
|
|
17
|
+
//= require codemirror/modes/coffeescript
|
|
18
|
+
//= require codemirror/modes/javascript
|
|
19
|
+
//= require codemirror/modes/ruby
|
|
20
|
+
//= require codemirror/modes/markdown
|
|
21
|
+
//= require codemirror/modes/slim
|
|
22
|
+
//= require codemirror/addons/selection/active-line
|
|
23
|
+
|
|
24
|
+
// Adminlte and corresponding Plugins
|
|
25
|
+
//= require admin-lte
|
|
26
|
+
//= require_tree .
|
|
27
|
+
|
|
28
|
+
$(function () {
|
|
29
|
+
$('input').iCheck({
|
|
30
|
+
checkboxClass: 'icheckbox_square-blue',
|
|
31
|
+
radioClass: 'iradio_flat-blue',
|
|
32
|
+
increaseArea: '20%' // optional
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
$('#datatable').dataTable({
|
|
36
|
+
"bSort": false
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
var editor = CodeMirror.fromTextArea(document.getElementById("textarea"), {
|
|
40
|
+
lineNumbers: true,
|
|
41
|
+
mode: "application/x-slim",
|
|
42
|
+
matchBrackets: true,
|
|
43
|
+
tabSize: 2,
|
|
44
|
+
indentWithTabs: true,
|
|
45
|
+
lineWrapping: true,
|
|
46
|
+
styleActiveLine: true
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
});
|
|
51
|
+
window.setTimeout(function() { $(".alert-info").alert('close'); }, 4000);
|
|
52
|
+
window.setTimeout(function() { $(".alert-success").alert('close'); }, 4000);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Place all the behaviors and hooks related to the matching controller here.
|
|
2
|
+
// All this logic will automatically be available in application.js.
|
|
3
|
+
$("document").ready(function(){
|
|
4
|
+
|
|
5
|
+
$("#file-upload").change(function() {
|
|
6
|
+
var filename = $(this).val().split('\\').pop();
|
|
7
|
+
$("#file-name").val(filename);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
});
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// Bootstrap Editable
|
|
2
|
+
//= require bootstrap-wysihtml5
|
|
3
|
+
//= require bootstrap-editable
|
|
4
|
+
//= require bootstrap-editable-rails
|
|
5
|
+
//= require_tree ./hicube/public
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
// Copied this from https://github.com/vitalets/x-editable/blob/master/src/inputs-ext/wysihtml5/wysihtml5.js
|
|
9
|
+
|
|
10
|
+
(function ($) {
|
|
11
|
+
"use strict";
|
|
12
|
+
|
|
13
|
+
var Wysihtml5 = function (options) {
|
|
14
|
+
this.init('wysihtml5', options, Wysihtml5.defaults);
|
|
15
|
+
|
|
16
|
+
//extend wysihtml5 manually as $.extend not recursive
|
|
17
|
+
this.options.wysihtml5 = $.extend({}, Wysihtml5.defaults.wysihtml5, options.wysihtml5);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
$.fn.editableutils.inherit(Wysihtml5, $.fn.editabletypes.abstractinput);
|
|
21
|
+
|
|
22
|
+
$.extend(Wysihtml5.prototype, {
|
|
23
|
+
render: function () {
|
|
24
|
+
var deferred = $.Deferred(),
|
|
25
|
+
msieOld;
|
|
26
|
+
|
|
27
|
+
//generate unique id as it required for wysihtml5
|
|
28
|
+
this.$input.attr('id', 'textarea_'+(new Date()).getTime());
|
|
29
|
+
|
|
30
|
+
this.setClass();
|
|
31
|
+
this.setAttr('placeholder');
|
|
32
|
+
|
|
33
|
+
//resolve deffered when widget loaded
|
|
34
|
+
$.extend(this.options.wysihtml5, {
|
|
35
|
+
events: {
|
|
36
|
+
load: function() {
|
|
37
|
+
deferred.resolve();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
this.$input.wysihtml5(this.options.wysihtml5);
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
In IE8 wysihtml5 iframe stays on the same line with buttons toolbar (inside popover).
|
|
46
|
+
The only solution I found is to add <br>. If you fine better way, please send PR.
|
|
47
|
+
*/
|
|
48
|
+
msieOld = /msie\s*(8|7|6)/.test(navigator.userAgent.toLowerCase());
|
|
49
|
+
if(msieOld) {
|
|
50
|
+
this.$input.before('<br><br>');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return deferred.promise();
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
value2html: function(value, element) {
|
|
57
|
+
$(element).html(value);
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
html2value: function(html) {
|
|
61
|
+
return html;
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
value2input: function(value) {
|
|
65
|
+
this.$input.data("wysihtml5").editor.setValue(value, true);
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
activate: function() {
|
|
69
|
+
this.$input.data("wysihtml5").editor.focus();
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
isEmpty: function($element) {
|
|
73
|
+
if($.trim($element.html()) === '') {
|
|
74
|
+
return true;
|
|
75
|
+
} else if($.trim($element.text()) !== '') {
|
|
76
|
+
return false;
|
|
77
|
+
} else {
|
|
78
|
+
//e.g. '<img>', '<br>', '<p></p>'
|
|
79
|
+
return !$element.height() || !$element.width();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
Wysihtml5.defaults = $.extend({}, $.fn.editabletypes.abstractinput.defaults, {
|
|
85
|
+
/**
|
|
86
|
+
@property tpl
|
|
87
|
+
@default <textarea></textarea>
|
|
88
|
+
**/
|
|
89
|
+
tpl:'<textarea></textarea>',
|
|
90
|
+
/**
|
|
91
|
+
@property inputclass
|
|
92
|
+
@default editable-wysihtml5
|
|
93
|
+
**/
|
|
94
|
+
inputclass: 'editable-wysihtml5',
|
|
95
|
+
/**
|
|
96
|
+
Placeholder attribute of input. Shown when input is empty.
|
|
97
|
+
@property placeholder
|
|
98
|
+
@type string
|
|
99
|
+
@default null
|
|
100
|
+
**/
|
|
101
|
+
placeholder: null,
|
|
102
|
+
/**
|
|
103
|
+
Wysihtml5 default options.
|
|
104
|
+
See https://github.com/jhollingworth/bootstrap-wysihtml5#options
|
|
105
|
+
@property wysihtml5
|
|
106
|
+
@type object
|
|
107
|
+
@default {stylesheets: false}
|
|
108
|
+
**/
|
|
109
|
+
wysihtml5: {
|
|
110
|
+
stylesheets: false, //see https://github.com/jhollingworth/bootstrap-wysihtml5/issues/183
|
|
111
|
+
toolbar: {
|
|
112
|
+
"font-styles": true, //Font styling, e.g. h1, h2, etc. Default true
|
|
113
|
+
"emphasis": true, //Italics, bold, etc. Default true
|
|
114
|
+
"lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true
|
|
115
|
+
"html": true, //Button which allows you to edit the generated HTML. Default false
|
|
116
|
+
"link": false, //Button to insert a link. Default true
|
|
117
|
+
"image": false, //Button to insert an image. Default true,
|
|
118
|
+
"color": true, //Button to change color of font
|
|
119
|
+
"blockquote": false, //Blockquote
|
|
120
|
+
"size": "sm" //default: none, other options are xs, sm, lg
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
$.fn.editabletypes.wysihtml5 = Wysihtml5;
|
|
126
|
+
|
|
127
|
+
}(window.jQuery));
|
|
128
|
+
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*
|
|
3
|
+
*= require jquery-ui
|
|
4
|
+
*= require font-awesome
|
|
5
|
+
*= require twitter/bootstrap
|
|
6
|
+
*= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
|
|
7
|
+
*= require dataTables/extras/dataTables.responsive
|
|
8
|
+
*= require icheck/square/blue
|
|
9
|
+
*= require icheck/minimal/blue
|
|
10
|
+
*= require icheck/flat/blue
|
|
11
|
+
*= require ionicons
|
|
12
|
+
*= require jquery.fileupload
|
|
13
|
+
*= require jquery.fileupload-ui
|
|
14
|
+
*= require codemirror
|
|
15
|
+
|
|
16
|
+
* Adminlte and corresponding css
|
|
17
|
+
*= require admin-lte
|
|
18
|
+
*= require skin-purple
|
|
19
|
+
*= require skin-blue
|
|
20
|
+
*= require_tree .
|
|
21
|
+
*= require_self
|
|
22
|
+
*/
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
.fileInput {
|
|
2
|
+
cursor: pointer;
|
|
3
|
+
height: 100%;
|
|
4
|
+
position:absolute;
|
|
5
|
+
top: 0;
|
|
6
|
+
right: 0;
|
|
7
|
+
z-index: 99;
|
|
8
|
+
/*This makes the button huge. If you want a bigger button, increase the font size*/
|
|
9
|
+
font-size:40px;
|
|
10
|
+
/*Opacity settings for all browsers*/
|
|
11
|
+
opacity: 0;
|
|
12
|
+
-moz-opacity: 0;
|
|
13
|
+
filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/*.inputWrapper {
|
|
17
|
+
height: 20px;
|
|
18
|
+
width: 64px;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
position: relative;
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
Using a background color, but you can use a background image to represent a button
|
|
23
|
+
background-color: grey;
|
|
24
|
+
}*/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*
|
|
3
|
+
* Bootstrap Editable
|
|
4
|
+
*= require bootstrap-wysihtml5
|
|
5
|
+
*= require bootstrap-editable
|
|
6
|
+
*= require_tree ./hicube/public
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/*.editable-container.editable-inline,
|
|
10
|
+
.editable-container.editable-inline .control-group.form-group,
|
|
11
|
+
.editable-container.editable-inline .control-group.form-group .editable-input,
|
|
12
|
+
.editable-container.editable-inline .control-group.form-group .editable-input textarea,
|
|
13
|
+
.editable-container.editable-inline .control-group.form-group .editable-input select,
|
|
14
|
+
.editable-container.editable-inline .control-group.form-group .editable-input input:not([type=radio]):not([type=checkbox]):not([type=submit])
|
|
15
|
+
{
|
|
16
|
+
width: 100%!important;
|
|
17
|
+
}
|
|
18
|
+
*/
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require_dependency "hicube/application_controller"
|
|
2
|
+
|
|
3
|
+
module Hicube
|
|
4
|
+
class AccountsController < BaseController
|
|
5
|
+
|
|
6
|
+
before_action :load_resource, except: [
|
|
7
|
+
:create,
|
|
8
|
+
:index,
|
|
9
|
+
:new
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
before_filter :load_resources, :only => [
|
|
13
|
+
:index,
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
# Must be called after load_recource filter.
|
|
17
|
+
before_filter :check_resource_params, :only => [
|
|
18
|
+
:create,
|
|
19
|
+
:update,
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
def create
|
|
23
|
+
@account = Hicube::Account.new(accounts_params)
|
|
24
|
+
@account.save!
|
|
25
|
+
|
|
26
|
+
respond_to do |format|
|
|
27
|
+
notify :notice, ::I18n.t('messages.resource.created',
|
|
28
|
+
:type => Hicube::Account.model_name.human,
|
|
29
|
+
:resource => @account
|
|
30
|
+
)
|
|
31
|
+
format.html { redirect_to action: :show, id: @account }
|
|
32
|
+
end
|
|
33
|
+
rescue Mongoid::Errors::Validations => e
|
|
34
|
+
respond_to do |format|
|
|
35
|
+
notify_now :error, ::I18n.t('messages.resource.not_valid',
|
|
36
|
+
:type => Hicube::Account.model_name.human,
|
|
37
|
+
:errors => @account.errors.full_messages.to_sentence
|
|
38
|
+
)
|
|
39
|
+
format.html { render :action => :new, :status => 422 }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def update
|
|
44
|
+
@account.update_attributes(accounts_params)
|
|
45
|
+
@account.save!
|
|
46
|
+
|
|
47
|
+
notify :notice, ::I18n.t('messages.resource.updated',
|
|
48
|
+
:type => Hicube::Account.model_name.human,
|
|
49
|
+
:resource => @account
|
|
50
|
+
)
|
|
51
|
+
render action: :show, id: @account
|
|
52
|
+
rescue Mongoid::Errors::Validations => e
|
|
53
|
+
notify_now :error, ::I18n.t('messages.resource.not_valid',
|
|
54
|
+
:type => Hicube::Account.model_name.human,
|
|
55
|
+
:errors => @account.errors.full_messages.to_sentence
|
|
56
|
+
)
|
|
57
|
+
render :action => :edit
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
def accounts_params
|
|
63
|
+
params.require(:account).permit(:ga, :domain, :notify_email_html, :notify_email_text)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
module Hicube
|
|
2
|
+
class ApplicationController < ActionController::Base
|
|
3
|
+
# Prevent CSRF attacks by raising an exception.
|
|
4
|
+
# For APIs, you may want to use :null_session instead.
|
|
5
|
+
protect_from_forgery with: :exception
|
|
6
|
+
|
|
7
|
+
before_action :configure_devise_permitted_params
|
|
8
|
+
|
|
9
|
+
#around_filter :audit_trail
|
|
10
|
+
before_filter :initialise_locale
|
|
11
|
+
|
|
12
|
+
before_filter :initialise_account_settings
|
|
13
|
+
|
|
14
|
+
helper :all
|
|
15
|
+
|
|
16
|
+
helper_method :app_name
|
|
17
|
+
|
|
18
|
+
#
|
|
19
|
+
# Constants
|
|
20
|
+
#
|
|
21
|
+
|
|
22
|
+
FLASH_TYPES = [
|
|
23
|
+
:debug,
|
|
24
|
+
:error,
|
|
25
|
+
:notice,
|
|
26
|
+
:alert,
|
|
27
|
+
:success,
|
|
28
|
+
:warning,
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
#
|
|
32
|
+
# Public Class Methods
|
|
33
|
+
#
|
|
34
|
+
public
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
# Public Instance Methods
|
|
38
|
+
#
|
|
39
|
+
public
|
|
40
|
+
|
|
41
|
+
def after_sign_in_path_for(resource)
|
|
42
|
+
return request.env['omniauth.origin'] || stored_location_for(resource) || '/hicube/pages'
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Generate a notification message.
|
|
46
|
+
def notify(type, message, options = {})
|
|
47
|
+
options[:now] ||= false
|
|
48
|
+
|
|
49
|
+
# Convert and cleanup.
|
|
50
|
+
type = type.to_s.downcase.to_sym
|
|
51
|
+
|
|
52
|
+
# Sanity check for type.
|
|
53
|
+
unless FLASH_TYPES.include?(type)
|
|
54
|
+
raise ArgumentError, "Invalid value for argument type: #{type}, expected one of: #{FLASH_TYPES.to_sentence}."
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
logger.info("FLASH (#{options.inspect}) #{type.to_s.upcase}: #{message}")
|
|
58
|
+
|
|
59
|
+
if options[:now] == true
|
|
60
|
+
flash.now[type] ||= []
|
|
61
|
+
flash.now[type] << message
|
|
62
|
+
else
|
|
63
|
+
flash[type] ||= []
|
|
64
|
+
flash[type] << message
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
logger.debug("DEBUG: FLASH #{flash.inspect}")
|
|
68
|
+
|
|
69
|
+
return true
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def notify_now(type, message, options = {})
|
|
73
|
+
options[:now] = true
|
|
74
|
+
notify(type, message, options)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
#
|
|
78
|
+
# Protected Instance Methods
|
|
79
|
+
#
|
|
80
|
+
protected
|
|
81
|
+
|
|
82
|
+
#
|
|
83
|
+
# Private Instance Methods
|
|
84
|
+
#
|
|
85
|
+
private
|
|
86
|
+
|
|
87
|
+
def app_name
|
|
88
|
+
t('app.name') || Rails.application.class.to_s.split("::").first
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def action_controller_helpers
|
|
92
|
+
return ActionController::Base.helpers
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def audit_trail
|
|
96
|
+
# Create a shallow copy only so be careful.
|
|
97
|
+
local_params = params.clone
|
|
98
|
+
|
|
99
|
+
# Strip out redundant, useless or other unwanted parameters.
|
|
100
|
+
local_params.reject!{ |k,v| %w(action authenticity_token eid controller).include?(k) }
|
|
101
|
+
|
|
102
|
+
# Filter sensitive and/or useless parameters.
|
|
103
|
+
%w(password password_confirmation).each do |k|
|
|
104
|
+
local_params[k] = '***' if local_params.has_key?(k)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Filter sensitive and/or useless parameters.
|
|
108
|
+
%w(user).each do |j|
|
|
109
|
+
if local_params.has_key?(j)
|
|
110
|
+
local_params[j] = local_params[j].clone
|
|
111
|
+
%w(password password_confirmation).each do |k|
|
|
112
|
+
local_params[j][k] = '***' if local_params[j].has_key?(k)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Create an audit trail for the request.
|
|
118
|
+
# AUDIT_LOG.info("ACCESS") { "REQUEST::#{request.method}::#{params[:controller]}##{params[:action]}::#{request.remote_ip}::#{request.fullpath.split('?')[0]}::#{local_params.inspect}" }
|
|
119
|
+
|
|
120
|
+
# Proceed as normal.
|
|
121
|
+
yield
|
|
122
|
+
|
|
123
|
+
# Create an audit trail for the response.
|
|
124
|
+
# AUDIT_LOG.info("ACCESS") { "RESPONSE::#{request.method}::#{params[:controller]}##{params[:action]}::#{response.status}::#{response.content_type}::#{response.location || '-'}" }
|
|
125
|
+
|
|
126
|
+
rescue => e
|
|
127
|
+
# Log the exception and then re-raise so it can be handled as normal.
|
|
128
|
+
# AUDIT_LOG.error("EXCEPTION") { "#{request.remote_ip}::#{request.method}::#{params[:controller]}##{params[:action]}::#{e.class.to_s}::#{e.message}::#{e.backtrace[0...5]}" }
|
|
129
|
+
raise
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def initialise_account_settings
|
|
133
|
+
Rails.application.configure do
|
|
134
|
+
GA.tracker = Hicube::Account.first.ga unless Hicube::Account.first.nil? or Hicube::Account.first.ga.nil?
|
|
135
|
+
end if Rails.env.production? or Rails.env.staging?
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def initialise_locale
|
|
139
|
+
# if params[:locale] is nil then I18n.default_locale will be used.
|
|
140
|
+
I18n.locale = params[:locale]
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def respond(http_status, response, options = {})
|
|
144
|
+
respond_to do |format|
|
|
145
|
+
format.json { render json: response, status: http_status }
|
|
146
|
+
format.xml { render xml: response, root: :response, status: http_status }
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def respond_with_success(options = {})
|
|
151
|
+
http_status = options[:http_status] || :ok
|
|
152
|
+
|
|
153
|
+
response = {}
|
|
154
|
+
response[:status] = options[:status] || 'OK'
|
|
155
|
+
response.merge!(options[:response]) if options.has_key?(:response)
|
|
156
|
+
|
|
157
|
+
respond(http_status, response)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def respond_with_error(http_status, options = {})
|
|
161
|
+
response = {}
|
|
162
|
+
response[:status] = options[:status] || 'ERROR'
|
|
163
|
+
response[:error] = {}
|
|
164
|
+
response[:error][:code] = options[:code] || http_status.to_s.dasherize
|
|
165
|
+
response[:error][:message] = options[:message]
|
|
166
|
+
response.merge!(options[:response]) if options.has_key?(:response)
|
|
167
|
+
|
|
168
|
+
respond(http_status, response)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
protected
|
|
172
|
+
|
|
173
|
+
def configure_devise_permitted_params
|
|
174
|
+
unless params
|
|
175
|
+
devise_parameter_sanitizer.for(:sign_up) << :name if params[:controller].include? 'devise'
|
|
176
|
+
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:name, :email) } if params[:controller].include? 'devise'
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
end
|
|
181
|
+
end
|