diff --git a/app/controllers/admin/admin_panel_controller.rb b/app/controllers/admin/admin_panel_controller.rb new file mode 100644 index 0000000..e86ed9b --- /dev/null +++ b/app/controllers/admin/admin_panel_controller.rb @@ -0,0 +1,18 @@ +class AdminPanelController < EnvironmentAdminController + + before_filter :login_required + + protect 'view_environment_admin_panel', :environment + + #FIXME This is not necessary because the application controller define the envrioment + # as the default holder + before_filter :load_default_enviroment + + design :holder => 'environment' + + protected + + def load_default_enviroment + @environment = Environment.default + end +end diff --git a/app/controllers/admin/categories_controller.rb b/app/controllers/admin/categories_controller.rb new file mode 100644 index 0000000..544acaa --- /dev/null +++ b/app/controllers/admin/categories_controller.rb @@ -0,0 +1,52 @@ +class CategoriesController < EnvironmentAdminController + + protect 'manage_environment_categories', :environment + + helper :categories + + def index + @categories = environment.top_level_categories + end + + ALLOWED_TYPES = CategoriesHelper::TYPES.map {|item| item[1] } + + # posts back + def new + type = (params[:type] || 'Category') + raise 'Type not allowed' unless ALLOWED_TYPES.include?(type) + + @category = type.constantize.new(params[:category]) + @category.environment = environment + if params[:parent_id] + @category.parent = environment.categories.find(params[:parent_id]) + end + if request.post? + begin + @category.save! + redirect_to :action => 'index' + rescue Exception => e + render :action => 'new' + end + end + end + + # posts back + def edit + begin + @category = environment.categories.find(params[:id]) + if request.post? + @category.update_attributes!(params[:category]) + redirect_to :action => 'index' + end + rescue Exception => e + render :action => 'edit' + end + end + + post_only :remove + def remove + environment.categories.find(params[:id]).destroy + redirect_to :action => 'index' + end + +end diff --git a/app/controllers/admin/edit_template_controller.rb b/app/controllers/admin/edit_template_controller.rb new file mode 100644 index 0000000..88e4611 --- /dev/null +++ b/app/controllers/admin/edit_template_controller.rb @@ -0,0 +1,17 @@ +class EditTemplateController < EnvironmentAdminController + + design_editor :holder => 'environment', :autosave => true, :block_types => :block_types + + #FIXME This is wrong + #See the FavoriteLinksController considerations and choose the better way + def block_types + %w[ + FavoriteLinks + ] + end + + def index + redirect_to :action => 'design_editor' + end + +end diff --git a/app/controllers/admin/environment_role_manager_controller.rb b/app/controllers/admin/environment_role_manager_controller.rb new file mode 100644 index 0000000..c5cda6d --- /dev/null +++ b/app/controllers/admin/environment_role_manager_controller.rb @@ -0,0 +1,66 @@ +class EnvironmentRoleManagerController < ApplicationController + protect 'manage_environment_roles', :environment + + def index + @admins = Person.find(:all, :conditions => ['role_assignments.resource_type = ?', 'Environment'], :include => :role_assignments ) + end + + def change_roles + @admin = Person.find(params[:id]) + @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) } + end + + def update_roles + @roles = params[:roles] ? Role.find(params[:roles]) : [] + @person = Person.find(params[:person]) + if @person.define_roles(@roles, environment) + flash[:notice] = _('Roles successfuly updated') + else + flash[:notice] = _('Couldn\'t change the roles') + end + redirect_to :action => :index + end + + def change_role + @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) } + @admin = Person.find(params[:id]) + @associations = @admin.find_roles(environment) + end + + def add_role + @person = Person.find(params[:person]) + @role = Role.find(params[:role]) + if environment.affiliate(@person, @role) + redirect_to :action => 'index' + else + @admin = Person.find(params[:person]) + @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) } + render :action => 'affiliate' + end + end + + def remove_role + @association = RoleAssignment.find(params[:id]) + if @association.destroy + flash[:notice] = _('Member succefully unassociated') + else + flash[:notice] = _('Failed to unassociate member') + end + redirect_to :aciton => 'index' + end + + def unassociate + @association = RoleAssignment.find(params[:id]) + if @association.destroy + flash[:notice] = _('Member succefully unassociated') + else + flash[:notice] = _('Failed to unassociate member') + end + redirect_to :aciton => 'index' + end + + def make_admin + @people = Person.find(:all) + @roles = Role.find(:all).select{|r|r.has_kind?(:environment)} + end +end diff --git a/app/controllers/admin/features_controller.rb b/app/controllers/admin/features_controller.rb new file mode 100644 index 0000000..174a916 --- /dev/null +++ b/app/controllers/admin/features_controller.rb @@ -0,0 +1,20 @@ +class FeaturesController < EnvironmentAdminController + protect 'edit_environment_features', :environment + + acts_as_environment_admin_controller + + def index + @features = Environment.available_features + end + + post_only :update + def update + if @environment.update_attributes(params[:environment]) + flash[:notice] = _('Features updated successfully.') + redirect_to :action => 'index' + else + render :action => 'index' + end + end + +end diff --git a/app/controllers/admin/manage_tags_controller.rb b/app/controllers/admin/manage_tags_controller.rb new file mode 100644 index 0000000..89a9cbd --- /dev/null +++ b/app/controllers/admin/manage_tags_controller.rb @@ -0,0 +1,74 @@ +# Manage tags stored by the acts-as_taggable_on_steroids plugin by providing an interface to create, destroy, update and list them +class ManageTagsController < EnvironmentAdminController + + # Index redirects to list action without modifing the url + def index + redirect_to :action => 'list' + end + + # Lists the tags starting with the top tags or with the chidren of @parent if its provided + def list + @parent = Tag.find(params[:parent]) if params[:parent] + @tags = @parent ? @parent.children : Tag.roots + @pending_tags = Tag.find_all_by_pending(true) + end + + # Prompt for data to a new tag + def new + @parent_tags = Tag.find_all_by_pending(false) + @tag = Tag.new + end + + # Collects the data and creates a new tag with it + def create + @tag = Tag.new(params[:tag]) + if @tag.save + flash[:notice] = _('Tag was successfully created.') + redirect_to :action => 'list' + else + @parent_tags = Tag.find_all_by_pending(false) + render :action => 'new' + end + end + + # Prompt for modifications on the attributes of a tag + def edit + @tag = Tag.find(params[:id]) + @parent_tags = @tag.parent_candidates + end + + # Do the modifications collected by edit + def update + @tag = Tag.find(params[:id]) + if @tag.update_attributes(params[:tag]) + flash[:notice] = _('Tag was successfully updated.') + redirect_to :action => 'list' + else + @parent_tags = @tag.parent_candidates + render :action => 'edit' + end + end + + # Destroy a tag and all its children + def destroy + @tag = Tag.find(params[:id]) + if @tag.destroy + flash[:notice] = _('Tag was successfuly destroyed') + end + redirect_to :action => 'list' + end + + # Approve a pending tag so now ita can be used to tag things + def approve + @tag = Tag.find(params[:id]) + if @tag.update_attribute(:pending, false) + flash[:notice] = _('Tag was successfuly approved') + redirect_to :action => 'list' + end + end + + # Full-text search for tags that have the query terms + def search + @tags_found = Tag.find_all_by_name_and_pending(params[:query], false) + end +end diff --git a/app/controllers/admin/region_validators_controller.rb b/app/controllers/admin/region_validators_controller.rb new file mode 100644 index 0000000..a95d441 --- /dev/null +++ b/app/controllers/admin/region_validators_controller.rb @@ -0,0 +1,40 @@ +class RegionValidatorsController < ApplicationController + + before_filter :load_region_and_search, :except => 'index' + +# protect 'manage_environment_validators', :environment + + def index + @regions = Region.top_level_for(environment) + end + + def region + # nothing to do, load_region_and_search already does everything needed here + end + + def search + render :partial => 'search' + end + + def add + validator = environment.organizations.find(params[:validator_id]) + @region.validators << validator + redirect_to :action => 'region', :id => @region.id + end + + def remove + validator = environment.organizations.find(params[:validator_id]) + @region.validators.delete(validator) + redirect_to :action => 'region', :id => @region.id + end + + protected + + def load_region_and_search + @region = environment.regions.find(params[:id]) + if params[:search] + @search = @region.search_possible_validators(params[:search]) + end + end + +end diff --git a/app/controllers/admin/role_controller.rb b/app/controllers/admin/role_controller.rb new file mode 100644 index 0000000..277e638 --- /dev/null +++ b/app/controllers/admin/role_controller.rb @@ -0,0 +1,49 @@ +class RoleController < EnvironmentAdminController + protect 'manage_environment_roles', :environment + + def index + @roles = Role.find(:all) + end + + def show + @role = Role.find(params[:id]) + end + + def new + @role = Role.new + end + + def create + @role = Role.new(params[:role]) + if @role.save + redirect_to :action => 'show', :id => @role + else + flash[:notice] = _('Failed to create role') + render :action => 'new' + end + end + + def edit + @role = Role.find(params[:id]) + end + + def update + @role = Role.find(params[:id]) + if @role.update_attributes(params[:role]) + redirect_to :action => 'show', :id => @role + else + flash[:notice] = _('Failed to edit role') + render :action => 'edit' + end + end + + def destroy + @role = Role.find(params[:id]) + if @role.destroy + redirect_to :action => 'index' + else + flash[:notice] = _('Failed to edit role') + redirect_to :action => 'index' + end + end +end diff --git a/app/controllers/environment_admin/admin_panel_controller.rb b/app/controllers/environment_admin/admin_panel_controller.rb deleted file mode 100644 index e86ed9b..0000000 --- a/app/controllers/environment_admin/admin_panel_controller.rb +++ /dev/null @@ -1,18 +0,0 @@ -class AdminPanelController < EnvironmentAdminController - - before_filter :login_required - - protect 'view_environment_admin_panel', :environment - - #FIXME This is not necessary because the application controller define the envrioment - # as the default holder - before_filter :load_default_enviroment - - design :holder => 'environment' - - protected - - def load_default_enviroment - @environment = Environment.default - end -end diff --git a/app/controllers/environment_admin/categories_controller.rb b/app/controllers/environment_admin/categories_controller.rb deleted file mode 100644 index 544acaa..0000000 --- a/app/controllers/environment_admin/categories_controller.rb +++ /dev/null @@ -1,52 +0,0 @@ -class CategoriesController < EnvironmentAdminController - - protect 'manage_environment_categories', :environment - - helper :categories - - def index - @categories = environment.top_level_categories - end - - ALLOWED_TYPES = CategoriesHelper::TYPES.map {|item| item[1] } - - # posts back - def new - type = (params[:type] || 'Category') - raise 'Type not allowed' unless ALLOWED_TYPES.include?(type) - - @category = type.constantize.new(params[:category]) - @category.environment = environment - if params[:parent_id] - @category.parent = environment.categories.find(params[:parent_id]) - end - if request.post? - begin - @category.save! - redirect_to :action => 'index' - rescue Exception => e - render :action => 'new' - end - end - end - - # posts back - def edit - begin - @category = environment.categories.find(params[:id]) - if request.post? - @category.update_attributes!(params[:category]) - redirect_to :action => 'index' - end - rescue Exception => e - render :action => 'edit' - end - end - - post_only :remove - def remove - environment.categories.find(params[:id]).destroy - redirect_to :action => 'index' - end - -end diff --git a/app/controllers/environment_admin/edit_template_controller.rb b/app/controllers/environment_admin/edit_template_controller.rb deleted file mode 100644 index 88e4611..0000000 --- a/app/controllers/environment_admin/edit_template_controller.rb +++ /dev/null @@ -1,17 +0,0 @@ -class EditTemplateController < EnvironmentAdminController - - design_editor :holder => 'environment', :autosave => true, :block_types => :block_types - - #FIXME This is wrong - #See the FavoriteLinksController considerations and choose the better way - def block_types - %w[ - FavoriteLinks - ] - end - - def index - redirect_to :action => 'design_editor' - end - -end diff --git a/app/controllers/environment_admin/environment_role_manager_controller.rb b/app/controllers/environment_admin/environment_role_manager_controller.rb deleted file mode 100644 index c5cda6d..0000000 --- a/app/controllers/environment_admin/environment_role_manager_controller.rb +++ /dev/null @@ -1,66 +0,0 @@ -class EnvironmentRoleManagerController < ApplicationController - protect 'manage_environment_roles', :environment - - def index - @admins = Person.find(:all, :conditions => ['role_assignments.resource_type = ?', 'Environment'], :include => :role_assignments ) - end - - def change_roles - @admin = Person.find(params[:id]) - @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) } - end - - def update_roles - @roles = params[:roles] ? Role.find(params[:roles]) : [] - @person = Person.find(params[:person]) - if @person.define_roles(@roles, environment) - flash[:notice] = _('Roles successfuly updated') - else - flash[:notice] = _('Couldn\'t change the roles') - end - redirect_to :action => :index - end - - def change_role - @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) } - @admin = Person.find(params[:id]) - @associations = @admin.find_roles(environment) - end - - def add_role - @person = Person.find(params[:person]) - @role = Role.find(params[:role]) - if environment.affiliate(@person, @role) - redirect_to :action => 'index' - else - @admin = Person.find(params[:person]) - @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) } - render :action => 'affiliate' - end - end - - def remove_role - @association = RoleAssignment.find(params[:id]) - if @association.destroy - flash[:notice] = _('Member succefully unassociated') - else - flash[:notice] = _('Failed to unassociate member') - end - redirect_to :aciton => 'index' - end - - def unassociate - @association = RoleAssignment.find(params[:id]) - if @association.destroy - flash[:notice] = _('Member succefully unassociated') - else - flash[:notice] = _('Failed to unassociate member') - end - redirect_to :aciton => 'index' - end - - def make_admin - @people = Person.find(:all) - @roles = Role.find(:all).select{|r|r.has_kind?(:environment)} - end -end diff --git a/app/controllers/environment_admin/features_controller.rb b/app/controllers/environment_admin/features_controller.rb deleted file mode 100644 index 174a916..0000000 --- a/app/controllers/environment_admin/features_controller.rb +++ /dev/null @@ -1,20 +0,0 @@ -class FeaturesController < EnvironmentAdminController - protect 'edit_environment_features', :environment - - acts_as_environment_admin_controller - - def index - @features = Environment.available_features - end - - post_only :update - def update - if @environment.update_attributes(params[:environment]) - flash[:notice] = _('Features updated successfully.') - redirect_to :action => 'index' - else - render :action => 'index' - end - end - -end diff --git a/app/controllers/environment_admin/manage_tags_controller.rb b/app/controllers/environment_admin/manage_tags_controller.rb deleted file mode 100644 index 89a9cbd..0000000 --- a/app/controllers/environment_admin/manage_tags_controller.rb +++ /dev/null @@ -1,74 +0,0 @@ -# Manage tags stored by the acts-as_taggable_on_steroids plugin by providing an interface to create, destroy, update and list them -class ManageTagsController < EnvironmentAdminController - - # Index redirects to list action without modifing the url - def index - redirect_to :action => 'list' - end - - # Lists the tags starting with the top tags or with the chidren of @parent if its provided - def list - @parent = Tag.find(params[:parent]) if params[:parent] - @tags = @parent ? @parent.children : Tag.roots - @pending_tags = Tag.find_all_by_pending(true) - end - - # Prompt for data to a new tag - def new - @parent_tags = Tag.find_all_by_pending(false) - @tag = Tag.new - end - - # Collects the data and creates a new tag with it - def create - @tag = Tag.new(params[:tag]) - if @tag.save - flash[:notice] = _('Tag was successfully created.') - redirect_to :action => 'list' - else - @parent_tags = Tag.find_all_by_pending(false) - render :action => 'new' - end - end - - # Prompt for modifications on the attributes of a tag - def edit - @tag = Tag.find(params[:id]) - @parent_tags = @tag.parent_candidates - end - - # Do the modifications collected by edit - def update - @tag = Tag.find(params[:id]) - if @tag.update_attributes(params[:tag]) - flash[:notice] = _('Tag was successfully updated.') - redirect_to :action => 'list' - else - @parent_tags = @tag.parent_candidates - render :action => 'edit' - end - end - - # Destroy a tag and all its children - def destroy - @tag = Tag.find(params[:id]) - if @tag.destroy - flash[:notice] = _('Tag was successfuly destroyed') - end - redirect_to :action => 'list' - end - - # Approve a pending tag so now ita can be used to tag things - def approve - @tag = Tag.find(params[:id]) - if @tag.update_attribute(:pending, false) - flash[:notice] = _('Tag was successfuly approved') - redirect_to :action => 'list' - end - end - - # Full-text search for tags that have the query terms - def search - @tags_found = Tag.find_all_by_name_and_pending(params[:query], false) - end -end diff --git a/app/controllers/environment_admin/region_validators_controller.rb b/app/controllers/environment_admin/region_validators_controller.rb deleted file mode 100644 index a95d441..0000000 --- a/app/controllers/environment_admin/region_validators_controller.rb +++ /dev/null @@ -1,40 +0,0 @@ -class RegionValidatorsController < ApplicationController - - before_filter :load_region_and_search, :except => 'index' - -# protect 'manage_environment_validators', :environment - - def index - @regions = Region.top_level_for(environment) - end - - def region - # nothing to do, load_region_and_search already does everything needed here - end - - def search - render :partial => 'search' - end - - def add - validator = environment.organizations.find(params[:validator_id]) - @region.validators << validator - redirect_to :action => 'region', :id => @region.id - end - - def remove - validator = environment.organizations.find(params[:validator_id]) - @region.validators.delete(validator) - redirect_to :action => 'region', :id => @region.id - end - - protected - - def load_region_and_search - @region = environment.regions.find(params[:id]) - if params[:search] - @search = @region.search_possible_validators(params[:search]) - end - end - -end diff --git a/app/controllers/environment_admin/role_controller.rb b/app/controllers/environment_admin/role_controller.rb deleted file mode 100644 index 277e638..0000000 --- a/app/controllers/environment_admin/role_controller.rb +++ /dev/null @@ -1,49 +0,0 @@ -class RoleController < EnvironmentAdminController - protect 'manage_environment_roles', :environment - - def index - @roles = Role.find(:all) - end - - def show - @role = Role.find(params[:id]) - end - - def new - @role = Role.new - end - - def create - @role = Role.new(params[:role]) - if @role.save - redirect_to :action => 'show', :id => @role - else - flash[:notice] = _('Failed to create role') - render :action => 'new' - end - end - - def edit - @role = Role.find(params[:id]) - end - - def update - @role = Role.find(params[:id]) - if @role.update_attributes(params[:role]) - redirect_to :action => 'show', :id => @role - else - flash[:notice] = _('Failed to edit role') - render :action => 'edit' - end - end - - def destroy - @role = Role.find(params[:id]) - if @role.destroy - redirect_to :action => 'index' - else - flash[:notice] = _('Failed to edit role') - redirect_to :action => 'index' - end - end -end diff --git a/app/controllers/environment_admin_controller.rb b/app/controllers/environment_admin_controller.rb index 95d7452..69655f9 100644 --- a/app/controllers/environment_admin_controller.rb +++ b/app/controllers/environment_admin_controller.rb @@ -1,2 +1,2 @@ -class EnvironmentAdminController < ApplicationController +class AdminController < ApplicationController end -- libgit2 0.21.2