diff --git a/app/assets/javascripts/admin/dashboards.js.coffee b/app/assets/javascripts/admin/dashboards.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/admin/dashboards.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/admin/items.js.coffee b/app/assets/javascripts/admin/items.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/admin/items.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/announcements.js.coffee b/app/assets/javascripts/announcements.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/announcements.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/designs.js.coffee b/app/assets/javascripts/designs.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/designs.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/member-selection.js b/app/assets/javascripts/member-selection.js
new file mode 100644
index 0000000..700f8d5
--- /dev/null
+++ b/app/assets/javascripts/member-selection.js
@@ -0,0 +1,53 @@
+$(document).ready(function() {
+ $(".select_user_modal").on('click', function(){
+ var ids = [];
+ var users = $(this).siblings('.selected_users').children('span.selected_user');
+ users.each(function(i) {
+ ids.push(users.eq(i).attr('id'));
+ });
+ $("#main-wrap").after("");
+ $.ajax({
+ type: 'GET',
+ url: $(this).attr("rel"),
+ dataType: 'script',
+ data: {field: $(this).attr("field"), ids: ids},
+ success: function (msg) {
+ $("#member-filter").modal('show'); },
+ error: function(){
+ alert("ERROR");
+ }
+ });
+ return false;
+ });
+
+ $(document).on('click', ".remove_user", function(){
+ $(this).parent().remove();
+ });
+
+ $("#remove_users").on('click', function(){
+ var ids = [];
+ var users = $('.selected_user input[type="checkbox"]:checked');
+ users.each(function(i) {
+ ids.push(users.eq(i).parent().attr('id'));
+ });
+ if (users.size() > 0) {
+ // TODO: i18n in javascript
+ if (confirm('Are you sure you want to delete this?')) {
+ $.ajax({
+ type: 'DELETE',
+ url: $(this).attr("rel"),
+ dataType: 'script',
+ data: {ids: ids},
+ error: function(){
+ // TODO: i18n in javascript
+ alert("ERROR");
+ }
+ });
+ }
+ }
+ else {
+ // TODO: i18n in javascript
+ alert('You did not select anything to delete')
+ }
+ });
+});
\ No newline at end of file
diff --git a/app/assets/javascripts/member.js b/app/assets/javascripts/member.js
new file mode 100644
index 0000000..491ffd6
--- /dev/null
+++ b/app/assets/javascripts/member.js
@@ -0,0 +1,7 @@
+//= require basic
+//= require lib/footable-0.1.js
+//= require lib/all-list
+//= require lib/jquery.fastLiveFilter.js
+//= require lib/checkbox.card.js
+//= require lib/jquery.form.js
+//= require lib/member/member-role.js
\ No newline at end of file
diff --git a/app/assets/javascripts/module_store.js.coffee b/app/assets/javascripts/module_store.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/module_store.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/sessions.js.coffee b/app/assets/javascripts/sessions.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/sessions.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/sites.js.coffee b/app/assets/javascripts/sites.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/sites.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/users.js.coffee b/app/assets/javascripts/users.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/users.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/stylesheets/admin/items.css.scss b/app/assets/stylesheets/admin/items.css.scss
deleted file mode 100644
index 6c4fb95..0000000
--- a/app/assets/stylesheets/admin/items.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the admin/items controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/announcements.css.scss b/app/assets/stylesheets/announcements.css.scss
deleted file mode 100644
index 72e63be..0000000
--- a/app/assets/stylesheets/announcements.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the announcements controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/designs.css.scss b/app/assets/stylesheets/designs.css.scss
deleted file mode 100644
index db79e0f..0000000
--- a/app/assets/stylesheets/designs.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the designs controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/member.css b/app/assets/stylesheets/member.css
new file mode 100644
index 0000000..9106a19
--- /dev/null
+++ b/app/assets/stylesheets/member.css
@@ -0,0 +1,7 @@
+/*
+ *= require basic
+ *= require lib/wrap-nav
+ *= require lib/main-list
+ *= require lib/filter
+ *= require lib/pageslide
+*/
\ No newline at end of file
diff --git a/app/assets/stylesheets/member_select.css b/app/assets/stylesheets/member_select.css
new file mode 100644
index 0000000..0d4e9df
--- /dev/null
+++ b/app/assets/stylesheets/member_select.css
@@ -0,0 +1,237 @@
+/* Member Filter */
+#select_user #select_user_modal.modal {
+ width: 80%;
+ margin-left: -40%;
+}
+#select_user #select_user_modal .modal-body {
+ max-height: 425px;
+}
+#select_user #select_user_modal .modal-body form {
+ margin-bottom: 0px;
+}
+#select_user #select_user_modal .modal-body form fieldset {
+ min-height: 360px;
+}
+#select_user #select_user_modal .modal-body .radio.inline,
+#select_user #select_user_modal .modal-body .checkbox.inline {
+ display: inline-block;
+ padding-top: 5px;
+ margin-bottom: 0;
+ vertical-align: middle;
+ min-width: 100px;
+ margin-left: 0;
+}
+#select_user #select_user_modal .modal-body .form-actions {
+ margin: 20px 0 0;
+ padding: 10px 0 0;
+ background-color: transparent;
+ text-align: right;
+}
+#select_user #select_user_modal .modal-body .tabs-left > .nano {
+ width: 160px;
+ min-height: 425px;
+ float: left;
+}
+#select_user #select_user_modal .modal-body .tabs-left > .nano .pane {
+ right: 6px;
+}
+#select_user #select_user_modal .modal-body .tabs-left > .nano > .content > .nav-tabs {
+ width: 140px;
+ float: left;
+ margin-bottom: 0;
+ margin-right: 0;
+ border-right: 1px solid #ddd;
+ border-bottom: none;
+}
+#select_user #select_user_modal .modal-body .tabs-left > .nano > .content > .nav-tabs > li {
+ float: none;
+}
+#select_user #select_user_modal .modal-body .tabs-left > .nano > .content > .nav-tabs > li > a {
+ min-width: 74px;
+ margin-right: 0;
+ margin-bottom: 3px;
+}
+#select_user #select_user_modal .modal-body .tabs-left > .nano > .content > .nav-tabs > li > a {
+ margin-right: -1px;
+ -webkit-border-radius: 4px 0 0 4px;
+ -moz-border-radius: 4px 0 0 4px;
+ border-radius: 4px 0 0 4px;
+}
+#select_user #select_user_modal .modal-body .tabs-left > .nano > .content > .nav-tabs > li > a:hover {
+ border-color: #eeeeee #dddddd #eeeeee #eeeeee;
+}
+#select_user #select_user_modal .modal-body .tabs-left > .nano > .content > .nav-tabs .active > a,
+#select_user #select_user_modal .modal-body .tabs-left > .nano > .content > .nav-tabs .active > a:hover {
+ border-color: #ddd transparent #ddd #ddd;
+ *border-right-color: #ffffff;
+}
+#select_user #select_user_modal .member-filter-options {
+ float: left;
+ display: inline-block;
+ width: 175px;
+ min-height: 425px;
+ margin-right: 10px;
+ padding: 0 10px 0 0;
+}
+#select_user #select_user_modal .member-filter-options select {
+ width: 165px;
+}
+#select_user #select_user_modal .member-filter-options .btn {
+ display: block;
+}
+#select_user #select_user_modal .member-filter-result {
+ padding-left: 15px;
+ min-height: 360px;
+ width: auto;
+}
+
+
+/* Check Box Card */
+.checkbox-card {
+ margin: 0;
+}
+.checkbox-card li {
+ position: relative;
+ list-style: none;
+ color: #FFFFFF;
+ width: 180px;
+ height: 40px;
+ margin: 0 10px 10px 0;
+ float: left;
+ display: inline-block;
+ background-color: #cccccc;
+ overflow: hidden;
+ -webkit-border-radius: 3px;
+ -moz-border-radius: 3px;
+ border-radius: 3px;
+ -webkit-transition: all .2s linear;
+ -moz-transition: all .2s linear;
+ -o-transition: all .2s linear;
+ transition: all .2s linear;
+}
+.checkbox-card li.mark {
+ width: 0;
+ height: 0;
+ padding: 0;
+ margin: 0;
+ -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
+ filter: alpha(opacity=0);
+ opacity: 0;
+ visibility: hidden;
+}
+.checkbox-card li:hover {
+ background-color: #0088cc;
+}
+.checkbox-card li:after {
+ content: "";
+ display: block;
+ clear: both;
+ height: 0;
+ visibility: hidden;
+}
+.checkbox-card li.active:before {
+ -webkit-text-size-adjust : none;
+ font-family: FontAwesome;
+ font-weight: normal;
+ font-style: normal;
+ color: #FFF;
+ text-decoration: inherit;
+ content: "\f00c";
+ position: absolute;
+ right: 0px;
+ top: 0px;
+ line-height: 14px;
+ text-indent: 10px;
+ font-size: 10px;
+ width: 0px;
+ height: 0px;
+ border-style: solid;
+ border-width: 0 22px 22px 0;
+ border-color: transparent #51a351 transparent transparent;
+}
+.checkbox-card li.active label {
+}
+.checkbox-card li label {
+ margin-bottom: 0px;
+ overflow: hidden;
+ -webkit-border-radius: 3px;
+ -moz-border-radius: 3px;
+ border-radius: 3px;
+}
+.checkbox-card li input {
+ opacity: 0;
+ width: 100%;
+ height: 100%;
+ position: absolute;
+ top: 0;
+ left: 0;
+ margin: 0;
+ z-index: 10;
+}
+.checkbox-card li label span {
+ -webkit-text-size-adjust : none;
+ font-size: 10px;
+ display: block;
+ width: 130px;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ color: #666666;
+ margin-top: -3px;
+}
+.checkbox-card li:hover label span,
+.checkbox-card li:hover label span.user-name {
+ color: #FFFFFF;
+}
+.checkbox-card li label span.user-name {
+ font-size: 12px;
+ color: #363636;
+ padding: 2px 0 0;
+ margin-top: 0;
+}
+.checkbox-card li .user-pic {
+ float: left;
+ margin-right: 5px;
+ width: 40px;
+ height: 40px;
+}
+#selected_users .selected_user {
+ display: inline-block;
+ margin-bottom: 5px;
+}
+#selected_users .selected_user .remove_user {
+ font-size: 15px;
+}
+#selected_email_users .selected_user {
+ display: inline-block;
+ margin-bottom: 5px;
+}
+#selected_email_users .selected_user .remove_user {
+ font-size: 15px;
+}
+/*
+.promoter {
+ border-color: #CCCCCC;
+ border-style: solid;
+ border-width: 0 1px;
+ padding: 0 10px 5px 10px;
+}
+.promoter > div {
+ border-bottom: 1px solid #CCCCCC;
+}
+.promoter > div:after {
+ content: "";
+ clear: both;
+ display: block;
+ visibility: hidden;
+}
+.promoter > div > span {
+ display: block;
+ margin-left: 70px;
+ padding-bottom: 5px;
+}
+.promoter p {
+ width: 70px;
+ float: left;
+ text-align:right;
+}*/
\ No newline at end of file
diff --git a/app/assets/stylesheets/module_store.css.scss b/app/assets/stylesheets/module_store.css.scss
deleted file mode 100644
index b7d604b..0000000
--- a/app/assets/stylesheets/module_store.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the module_store controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/sessions.css.scss b/app/assets/stylesheets/sessions.css.scss
deleted file mode 100644
index 7bef9cf..0000000
--- a/app/assets/stylesheets/sessions.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the sessions controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/sites.css.scss b/app/assets/stylesheets/sites.css.scss
deleted file mode 100644
index 682e55c..0000000
--- a/app/assets/stylesheets/sites.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the sites controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/users.css.scss b/app/assets/stylesheets/users.css.scss
deleted file mode 100644
index 1efc835..0000000
--- a/app/assets/stylesheets/users.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the users controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/admin/authorizations_controller.rb b/app/controllers/admin/authorizations_controller.rb
new file mode 100644
index 0000000..3da0d14
--- /dev/null
+++ b/app/controllers/admin/authorizations_controller.rb
@@ -0,0 +1,79 @@
+class Admin::AuthorizationsController < OrbitAdminController
+ layout "back_end"
+
+ def index
+ @module_apps ||= ModuleApp.any_of({authorizable: true}).order_by([:title, :asc])
+ if @module_apps && @module_apps.include?(@module_app)
+ if @type
+ case @type
+ when 'category_authorization'
+ if (@module_app.categorizable || @module_app.categories.present?)
+ @objects = @module_app.categories rescue nil
+ else
+ @error = t(:no_category)
+ end
+ else
+ @objects = @klass.all
+ end
+ unless @objects.blank?
+ @object ||= @objects.first
+ @authorizations = Authorization.category_authorized_users(@object.id)
+ else
+ @error = t(:no_data)
+ end
+ else
+ @authorizations = Authorization.module_authorized_users(@module_app.id)
+ end
+ elsif @module_apps
+ @module_app = @module_apps.first
+ else
+ redirect_to :root
+ end
+ end
+
+ def add_users
+ users = User.find(params[:user_ids]) rescue nil
+ unless users.nil?
+ authorization = get_or_create_authorization
+ add_users_to_auth(authorization, users)
+ end
+ @users = authorization.authorized_users
+ render 'admin/authorizations/reload_users'
+ end
+
+ def modal_select
+ existing_users = User.find(params[:ids]) rescue []
+ roles = Role.all
+ if @type
+ @object_id = @object.id if @object
+ @sorted_users = roles.inject({}) do |users, role|
+ users[role] = role.users.where(admin: false) - existing_users - @module_app.managers
+ users
+ end
+ else
+ @sorted_users = roles.inject({}) do |users, role|
+ users[role] = role.users.where(admin: false) - existing_users
+ users
+ end
+ end
+ end
+
+
+ private
+
+ def admin_or_manager
+ @override_can_use = true
+ setup_vars
+ authenticate_user!
+ current_user.is_manager?(@module_app) unless current_user.is_admin?
+ end
+
+ def setup_vars
+ @module_app = ModuleApp.find_by(key: params[:module]) if params[:module]
+ @type = params[:type].underscore if params[:type]
+ if @type
+ @klass = @type.gsub('_authorization', '').gsub('_approval', '').classify.constantize rescue nil
+ @object = @klass.find(params[:id]) rescue nil
+ end
+ end
+end
diff --git a/app/controllers/admin/members_controller.rb b/app/controllers/admin/members_controller.rb
new file mode 100644
index 0000000..26b341f
--- /dev/null
+++ b/app/controllers/admin/members_controller.rb
@@ -0,0 +1,81 @@
+class Admin::MembersController < OrbitMemberController
+ def index
+ @roles = Role.all
+
+ @filter = params[:filter]
+ @mq = params[:mq]
+ @new_filter = params[:new_filter]
+
+ if @filter && params[:clear]
+ @filter.delete(params[:type])
+ elsif @filter && @new_filter
+ if @filter.has_key?(@new_filter[:type]) && @filter[@new_filter[:type]].include?(@new_filter[:id].to_s)
+ @filter[@new_filter[:type]].delete(@new_filter[:id].to_s)
+ elsif @filter.has_key?(@new_filter[:type])
+ @filter[@new_filter[:type]] << @new_filter[:id].to_s
+ else
+ @filter.merge!({@new_filter[:type] => [@new_filter[:id].to_s]})
+ end
+ elsif @new_filter
+ @filter = {@new_filter[:type] => [@new_filter[:id].to_s]}
+ end
+
+ if @filter.blank? and @mq.blank?
+
+ render case params[:at]
+ when 'summary'
+ @users=User.all.desc("_id")
+ "index_summary"
+ when 'thumbnail'
+ @users=User.all.desc("_id")
+ "index_thumbnail"
+ else
+ @users=User.all.desc("_id")
+ "index"
+ end
+
+ elsif @filter.blank? and !@mq.blank?
+
+ render case params[:at]
+ when 'summary'
+ @users=User.all.any_of({:user_id => /#{@mq}/i}, {:first_name => /#{@mq}/i}, {:last_name => /#{@mq}/i}, {:email => /#{@mq}/i}, {:office_tel => /#{@mq}/i}).desc("_id")
+ "index_summary"
+ when 'thumbnail'
+ @users=User.all.any_of({:user_id => /#{@mq}/i}, {:first_name => /#{@mq}/i}, {:last_name => /#{@mq}/i}, {:email => /#{@mq}/i}, {:office_tel => /#{@mq}/i}).desc("_id")
+ "index_thumbnail"
+ else
+ @users=User.all.any_of({:user_id => /#{@mq}/i}, {:first_name => /#{@mq}/i}, {:last_name => /#{@mq}/i}, {:email => /#{@mq}/i}, {:office_tel => /#{@mq}/i}).desc("_id")
+ "index"
+ end
+
+ elsif !@filter.blank? and @mq.blank?
+
+ render case params[:at]
+ when 'summary'
+ @users=User.all.any_in(:role_ids=>@filter['role']).desc("_id")
+ "index_summary"
+ when 'thumbnail'
+ @users=User.all.any_in(:role_ids=>@filter['role']).desc("_id")
+ "index_thumbnail"
+ else
+ @users=User.all.any_in(:role_ids=>@filter['role']).desc("_id")
+ "index"
+ end
+
+ end
+
+ end
+
+ def new
+ @member = MemberProfile.new
+ end
+
+ def edit
+ end
+
+ def create
+ end
+
+ def update
+ end
+end
diff --git a/app/controllers/admin/module_apps_controller.rb b/app/controllers/admin/module_apps_controller.rb
new file mode 100644
index 0000000..08fc64b
--- /dev/null
+++ b/app/controllers/admin/module_apps_controller.rb
@@ -0,0 +1,26 @@
+class Admin::ModuleAppsController < OrbitAdminController
+ before_action :check_auth
+ include AdminHelper
+
+ def index
+ @module_app = ModuleApp.find params[:module_app_id]
+ @managers = Authorization.module_authorized_users(@module_app)
+ end
+
+ def check_auth
+ unless (is_admin? || is_manager?)
+ flash[:error] = "unauthorized access"
+ if request.env["HTTP_REFERER"]
+ redirect_to :back
+ else
+ render 'public/403.html', :status => 403, :layout => false)
+ end
+ false
+ end
+ end
+
+ def setting
+ @sys_users = User.not_admins
+ @module_app = ModuleApp.find(params[:module_app_id])
+ end
+end
diff --git a/app/controllers/concerns/authorize.rb b/app/controllers/concerns/authorize.rb
new file mode 100644
index 0000000..06e3c8a
--- /dev/null
+++ b/app/controllers/concerns/authorize.rb
@@ -0,0 +1,29 @@
+module Authorize
+ extend ActiveSupport::Concern
+
+ protected
+
+ def open_for_admin
+ if current_user.is_admin?
+ "Authorized"
+ else
+ render "public/404" , layout: "back_end"
+ end
+ end
+
+ def open_for_manager
+ if ((@module_authorized_users.include?(current_user.id) && current_user.is_manager?(@module_app)) || current_user.is_admin?)
+ "Authorized"
+ else
+ render "public/404" , layout: "back_end"
+ end
+ end
+
+ private
+
+ def set_variables(module_app)
+ @module_app = ModuleApp.find_by(key: module_app)
+ @categories = @module_app.categories
+ @module_authorized_users = Authorization.module_authorized_users(@module_app).pluck(:user_id) rescue nil
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/orbit_admin_controller.rb b/app/controllers/orbit_admin_controller.rb
index de52542..c5b11a2 100644
--- a/app/controllers/orbit_admin_controller.rb
+++ b/app/controllers/orbit_admin_controller.rb
@@ -1,4 +1,7 @@
class OrbitAdminController < ApplicationController
+ include OrbitCoreLib::Authorize
+ include OrbitCoreLib::PermissionUtility
+ include Authorize
before_action :authenticate_user
layout "back_end"
end
diff --git a/app/controllers/orbit_member_controller.rb b/app/controllers/orbit_member_controller.rb
new file mode 100644
index 0000000..380d8bc
--- /dev/null
+++ b/app/controllers/orbit_member_controller.rb
@@ -0,0 +1,7 @@
+class OrbitMemberController < ApplicationController
+ include Authorize
+ include AdminHelper
+ include ApplicationHelper
+
+ layout "member"
+end
diff --git a/app/helpers/admin/authorizations_helper.rb b/app/helpers/admin/authorizations_helper.rb
new file mode 100644
index 0000000..314abcf
--- /dev/null
+++ b/app/helpers/admin/authorizations_helper.rb
@@ -0,0 +1,2 @@
+module Admin::AuthorizationsHelper
+end
diff --git a/app/helpers/admin/members_helper.rb b/app/helpers/admin/members_helper.rb
new file mode 100644
index 0000000..81c843b
--- /dev/null
+++ b/app/helpers/admin/members_helper.rb
@@ -0,0 +1,2 @@
+module Admin::MembersHelper
+end
diff --git a/app/helpers/admin/module_apps_helper.rb b/app/helpers/admin/module_apps_helper.rb
new file mode 100644
index 0000000..9c73da9
--- /dev/null
+++ b/app/helpers/admin/module_apps_helper.rb
@@ -0,0 +1,2 @@
+module Admin::ModuleAppsHelper
+end
diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb
new file mode 100644
index 0000000..e57690e
--- /dev/null
+++ b/app/helpers/admin_helper.rb
@@ -0,0 +1,34 @@
+module AdminHelper
+
+ # Check if the current_user is manager in current module app
+ def is_manager?
+ (@current_user.is_manager?(@module_app) rescue nil) || is_admin?
+ end
+
+ # Check if the current_user is sub manager in current module app
+ def is_sub_manager?
+ (@current_user.is_sub_manager?(@module_app) rescue nil) || is_admin?
+ end
+
+ def is_admin?
+ @current_user.is_admin? rescue false
+ end
+
+ def is_member?
+ if (@current_user rescue false)
+ return true
+ end
+ return false
+ end
+
+ def get_user_module_role(user)
+ if user.is_admin?
+ t(:admin)
+ elsif user.is_manager?(@module_app)
+ t(:manager)
+ elsif user.is_sub_manager?
+ t(:sub_manager)
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/app/models/authorization.rb b/app/models/authorization.rb
new file mode 100644
index 0000000..22e0673
--- /dev/null
+++ b/app/models/authorization.rb
@@ -0,0 +1,29 @@
+class Authorization
+ include Mongoid::Document
+
+ belongs_to :module_app
+ belongs_to :user
+ belongs_to :category
+ belongs_to :workgroup
+ belongs_to :role
+
+ scope :module_authorized_users, ->(module_app){ where(module_app_id: module_app) }
+ scope :category_authorized_users, ->(category){ where(category_id: category) }
+
+ def self.create_authorization(module_app_id=nil,category_id=nil,user_id,type)
+ user = User.find(user_id)
+ if user.is_admin?
+ elsif user.workgroup.nil?
+ if type == "module_authorization"
+ workgroup = Workgroup.find_by(key: "managers")
+ user.update_attributes(workgroup_id: workgroup.id)
+ a = self.new(module_app_id: module_app_id, user_id: user_id, workgroup_id: workgroup.id)
+ a.save
+ elsif type == "category_authorization"
+ self.create(category_id: category_id, user_id: user_id )
+ workgroup = Workgroup.find_by(key: "sub_managers")
+ user.update_attributes(workgroup_id: workgroup.id)
+ end
+ end
+ end
+end
diff --git a/app/models/category.rb b/app/models/category.rb
index a4e94c5..86211bb 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -6,6 +6,11 @@ class Category
field :title, localize: true
belongs_to :module_app
+ has_many :authorizations
scope :enabled, ->{ where(:disable.in => [false, nil, ''])}
+
+ def category_sub_managers
+ Authorization.category_authorized_users(self).pluck(:user_id)
+ end
end
diff --git a/app/models/member_profile.rb b/app/models/member_profile.rb
new file mode 100644
index 0000000..0113887
--- /dev/null
+++ b/app/models/member_profile.rb
@@ -0,0 +1,15 @@
+class MemberProfile
+ include Mongoid::Document
+ field :first_name, type: String, localize: true
+ field :last_name, type: String, localize: true
+ field :gender
+
+ has_one :user
+ has_and_belongs_to_many :roles
+
+ mount_uploader :avatar, AvatarUploader
+
+ def name
+ "#{self.first_name} #{self.last_name}"
+ end
+end
diff --git a/app/models/module_app.rb b/app/models/module_app.rb
index 45c85e4..6c65010 100644
--- a/app/models/module_app.rb
+++ b/app/models/module_app.rb
@@ -6,14 +6,19 @@ class ModuleApp
field :key, type: String
field :taggable, type: Boolean, default: false
field :categorizable, type: Boolean, default: false
+ field :authorizable, type: Boolean, default: false
field :sidebar_order,type: Integer,default: 0
+ field :authorizable_models, type: Array
has_many :categories, dependent: :destroy, :autosave => true
has_and_belongs_to_many :tags, dependent: :destroy, :autosave => true
+ has_many :authorizations
def refetch_setting!(reg)
self[:taggable] = reg.is_taggable
self[:categorizable] = reg.is_categorizable
+ self[:authorizable] = reg.is_authorizable
+ self[:authorizable_models] = reg.get_authorizable_models
end
def get_registration
@@ -48,4 +53,22 @@ class ModuleApp
def categorizable
get_registration.is_categorizable
end
+
+ def user_can_manage?
+ self.workgroup.key.eql?("manager")
+ end
+
+ def authorizable
+ get_registration.is_authorizable
+ end
+
+ def user_module_managers
+ Authorization.module_authorized_users(self).pluck(:user_id)
+ end
+
+ def role_module_managers
+ users = Authorization.module_authorized_users(self).pluck(:user_id)
+ roles = Authorization.module_authorized_users(self).pluck(:role_id)
+ users + roles
+ end
end
diff --git a/app/models/role.rb b/app/models/role.rb
new file mode 100644
index 0000000..99bd231
--- /dev/null
+++ b/app/models/role.rb
@@ -0,0 +1,8 @@
+class Role
+ include Mongoid::Document
+ field :key, type: String
+ field :title, type: String, localize: true
+
+ has_and_belongs_to_many :member_profiles
+ has_many :authorizations
+end
diff --git a/app/models/site.rb b/app/models/site.rb
index a081b48..63135ab 100644
--- a/app/models/site.rb
+++ b/app/models/site.rb
@@ -37,4 +37,6 @@ class Site
I18n.locale = :en
title.parameterize
end
+
+ mount_uploader :default_image, ImageUploader
end
diff --git a/app/models/user.rb b/app/models/user.rb
index fa69d5a..2d49f44 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -10,9 +10,50 @@ class User
has_secure_password
+ belongs_to :workgroup
+ has_many :authorizations
+ belongs_to :member_profile
+
VALID_EMAIL_FORMAT = /\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z/
validates :user_name, presence: true, uniqueness: true
validates :password, presence: true, :on => :create, length: {:in => 8..20}
validates :email, presence: true, uniqueness: true, format: { with: VALID_EMAIL_FORMAT }
+
+ def is_admin?
+ if (self.workgroup.present? && self.workgroup.key.eql?("admin"))
+ true
+ else
+ false
+ end
+ end
+
+ def is_manager?(module_app)
+ if ((module_app.user_module_managers.include?(self.id) rescue nil) && (!self.is_admin?))
+ true
+ else
+ false
+ end
+ end
+
+ def is_sub_manager?(module_app)
+ module_app_categories = module_app.categories.map {|c| c.id} rescue nil
+ authorized_categories = self.authorizations.map {|a| a.category.id if (a.category.present? && a.workgroup.key.eql?("sub_managers"))}
+ intersection = (module_app_categories & authorized_categories)
+
+ if ((intersection.count > 0 if intersection.present?) && !self.is_admin? && !self.is_manager?(module_app))
+ true
+ else
+ false
+ end
+ end
+
+ def is_authorized_with_role?(module_app)
+ end
+
+ def self.not_admins
+ workgroup = Workgroup.find_by(key: "admin")
+ self.where(:workgroup_id.ne => workgroup.id)
+ end
+
end
diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb
new file mode 100644
index 0000000..3351dbd
--- /dev/null
+++ b/app/models/workgroup.rb
@@ -0,0 +1,10 @@
+class Workgroup
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :key, type: String
+ field :title, type: String
+
+ has_many :authorizations
+ has_many :users
+end
diff --git a/app/uploaders/avatar_uploader.rb b/app/uploaders/avatar_uploader.rb
new file mode 100644
index 0000000..e291b43
--- /dev/null
+++ b/app/uploaders/avatar_uploader.rb
@@ -0,0 +1,65 @@
+# encoding: utf-8
+require 'carrierwave/processing/mime_types'
+
+class AvatarUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or MiniMagick support:
+ # include CarrierWave::RMagick
+ # include CarrierWave::MiniMagick
+ include CarrierWave::MiniMagick
+ include CarrierWave::MimeTypes
+
+ process :set_content_type
+ # Choose what kind of storage to use for this uploader:
+ storage :file
+ # storage :fog
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ # def default_url
+ # # For Rails 3.1+ asset pipeline compatibility:
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
+ #
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
+ # end
+
+ def default_url
+ [version_name, (Site.first.default_image.file.url rescue "person.png")].compact.join('_')
+ end
+
+ # Process files as they are uploaded:
+ # process :scale => [200, 300]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ # Create different versions of your uploaded files:
+ # version :thumb do
+ # process :resize_to_fit => [50, 50]
+ # end
+ version :thumb do
+ process :resize_to_fit => [200, 200]
+ end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ def extension_white_list
+ %w(jpg jpeg gif png)
+ end
+
+ # Override the filename of the uploaded files:
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+ def cache_dir
+ "#{Rails.root}/tmp/uploads"
+ end
+
+end
diff --git a/app/views/admin/authorizations/_user.html.erb b/app/views/admin/authorizations/_user.html.erb
new file mode 100644
index 0000000..0f081fa
--- /dev/null
+++ b/app/views/admin/authorizations/_user.html.erb
@@ -0,0 +1,16 @@
+<% if user.user.present?%>
+
+
+ <% unless user == current_user || user.user.is_admin? %>
+
+ <% end %>
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/admin/authorizations/index.html.erb b/app/views/admin/authorizations/index.html.erb
new file mode 100644
index 0000000..cabf858
--- /dev/null
+++ b/app/views/admin/authorizations/index.html.erb
@@ -0,0 +1,38 @@
+
diff --git a/app/views/admin/authorizations/modal_select.js.erb b/app/views/admin/authorizations/modal_select.js.erb
new file mode 100644
index 0000000..fe82819
--- /dev/null
+++ b/app/views/admin/authorizations/modal_select.js.erb
@@ -0,0 +1,2 @@
+$("#select_user").html("<%= j render partial: 'admin/member_selects/modal_select', locals: {role_form_url: admin_add_roles_authorizations_path(@module_app.key, @type, @object_id), user_form_url: admin_add_users_authorizations_path(@module_app.key, @type, @object_id)} %>");
+$("#member-filter").modal();
\ No newline at end of file
diff --git a/app/views/admin/authorizations/unauthorized.html.erb b/app/views/admin/authorizations/unauthorized.html.erb
new file mode 100644
index 0000000..bb7da83
--- /dev/null
+++ b/app/views/admin/authorizations/unauthorized.html.erb
@@ -0,0 +1 @@
+
Aww Snap! You are not allowed to access this page!
\ No newline at end of file
diff --git a/app/views/admin/member_selects/_modal_select.html.erb b/app/views/admin/member_selects/_modal_select.html.erb
new file mode 100644
index 0000000..e8d14e7
--- /dev/null
+++ b/app/views/admin/member_selects/_modal_select.html.erb
@@ -0,0 +1,80 @@
+
+ <%= form_tag user_form_url, remote: true do %>
+
+ <% end %>
+
+ <% end %>
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/views/admin/members/_clear_filters.html.erb b/app/views/admin/members/_clear_filters.html.erb
new file mode 100644
index 0000000..d8ff178
--- /dev/null
+++ b/app/views/admin/members/_clear_filters.html.erb
@@ -0,0 +1,3 @@
+
\ No newline at end of file
diff --git a/app/views/admin/members/_filter.html.erb b/app/views/admin/members/_filter.html.erb
new file mode 100644
index 0000000..93f395f
--- /dev/null
+++ b/app/views/admin/members/_filter.html.erb
@@ -0,0 +1,7 @@
+