docbrown/app/controllers/organizations_controller.rb
Edem Attikese 0ad8cd9eab Edem/improvements/pundit coverage (#498)
* added organization policy + spec

* user specs for is_org_admin?

* added authroize to organization controller

* admin policy + specs

* deleted enforce admin due to pundit policy redundancy

* applied admin policy to entire admin namespace

* refactoring analytics controller WIP - wanna test codeship

* Add protection against reactions to unpublished articles (#473)

* Add chat channel policy and spec (#474)

* Add comment policy and specs (#475)

* Fix edge case with apostrophes

* Add comment policy and specs

* Add login for deleting comment spec

* Change test to raise pundit error instead of 404

* Clean up comment destroy request specs

* Remove redundant raise

* Whitelist columns on to_json call (#477)

* Add pundit policy for several controllers (#476)

* Add pundit policy for several controllers

* Adjust video spec

* Fix tag request specs

* Add proper twilio tokens request specs

* Remove puts statements

* Add a couple basic request specs (#478)

* Add a few tests and fix user tag color bug (#482)

* Refactor handle_tag_index in stories_controller (#481)

* Modify valid_request_origin? (#483)

* Add misc specs and remove banned attribute from user model (#484)

*  Fix missing Cloudinary tags and misc specs (#486)

* removing current_user_is_admin? to use .is_admin? method

* added missing org policy routes

* Add comment for all public controllers

* Fix edge case for test

* Authorize mod controller and add specs

* Refactor methods via inheritance and use only super_admin role

* Create policy method for analytics via article_policy and refactor

* Capitalize all buttons in dashboard page

* Fix org tests and remove old admin test

* Use only happy path for analytics

* Fix tests to use Pundit error

* Update org_policy spec
2018-06-28 09:38:20 -04:00

80 lines
2.1 KiB
Ruby

class OrganizationsController < ApplicationController
before_action :authenticate_user!, except: [:show]
after_action :verify_authorized
def create
@tab = "organization"
@user = current_user
@tab_list = @user.settings_tab_list
@organization = Organization.new(organization_params)
authorize @organization
if @organization.save
current_user.update(organization_id: @organization.id, org_admin: true)
redirect_to "/settings/organization", notice:
"Your organization was successfully created and you are an admin."
else
@tab = "switch-organizations" if @user.has_role?(:switch_between_orgs)
render template: "users/edit"
end
end
# GET /users/:id/edit
def update
@user = current_user
@tab = "organization"
@tab_list = @user.settings_tab_list
@organization = @user.organization
authorize @organization
if @organization.update(organization_params)
redirect_to "/settings/organization", notice: "Your organization was successfully updated."
else
render template: "users/edit"
end
end
def generate_new_secret
raise unless current_user.org_admin
@organization = current_user.organization
authorize @organization
@organization.secret = @organization.generated_random_secret
@organization.save
redirect_to "/settings/organization", notice: "Your org secret was updated"
end
private
def permitted_params
accessible = %i[
name
summary
tag_line
slug
url
proof
profile_image
location
company_size
tech_stack
email
story
bg_color_hex
text_color_hex
twitter_username
github_username
]
approved_params = %i(cta_button_text cta_button_url cta_body_markdown)
@organization&.approved ? accessible + approved_params : accessible
end
def organization_params
params.require(:organization).permit(permitted_params).
transform_values do |value|
if value.class.name == "String"
ActionController::Base.helpers.strip_tags(value)
else
value
end
end
end
end