Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNO-287] Developer Section in My Account #153

Merged
merged 3 commits into from
Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ angular.module('mnoEnterprise.configuration', [])
})
.constant('PRICING_CONFIG', <%= Settings.pricing.to_json %>)
.constant('DOCK_CONFIG', <%= Settings.dock.to_json %>)
.constant('DEVELOPER_SECTION_CONFIG', <%= Settings.developer.to_json %>)
.constant('GOOGLE_TAG_CONTAINER_ID', <%= MnoEnterprise.google_tag_container.to_json %>)
.constant('INTERCOM_ID', <%= MnoEnterprise.intercom_app_id.to_json %>)
.constant('APP_NAME', <%= MnoEnterprise.app_name.to_json %>)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ json.cache! ['v1', @user.cache_key] do
json.created_at @user.created_at ? @user.created_at.iso8601 : nil
json.company @user.company
json.phone @user.phone
json.api_secret @user.api_secret
json.api_key @user.api_key
json.phone_country_code @user.phone_country_code
json.country_code @user.geo_country_code || 'US'
json.website @user.website
Expand Down
1 change: 1 addition & 0 deletions api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
resources :marketplace, only: [:index, :show]
resource :current_user, only: [:show, :update] do
put :update_password
put :register_developer
#post :deletion_request, action: :create_deletion_request
#delete :deletion_request, action: :cancel_deletion_request
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def show
# PUT /mnoe/jpi/v1/current_user
def update
@user = current_user

@user.assign_attributes(user_params)
changes = @user.changes
if @user.update(user_params)
Expand All @@ -34,6 +33,17 @@ def update
end
end

# PUT /mnoe/jpi/v1/current_user/register_developer
def register_developer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write a spec for this method

@user = current_user
if @user.update(developer: true)
MnoEnterprise::EventLogger.info('register_developer', current_user.id, "User developer register", @user)
render :show
else
render json: @user.errors, status: :bad_request
end
end

# PUT /mnoe/jpi/v1/current_user/update_password
def update_password
@user = current_user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def hash_for(res)
'created_at' => res.created_at ? res.created_at.iso8601 : nil,
'company' => res.company,
'phone' => res.phone,
'api_secret' => res.api_secret,
'api_key' => res.api_key,
'phone_country_code' => res.phone_country_code,
'country_code' => res.geo_country_code || 'US',
'website' => res.website,
Expand Down Expand Up @@ -111,6 +113,17 @@ def hash_for(res)
end
end

describe 'PUT #register_developer' do
before { api_stub_for(put: "/users/#{user.id}", response: from_api(user)) }
before { sign_in user }
subject { put :register_developer}

describe 'logged in' do
before { subject }
it { expect(response).to be_success }
end
end

describe 'PUT #update_password' do
let(:attrs) { {current_password: 'password', password: 'blablabla', password_confirmation: 'blablabla'} }
before { api_stub_for(put: "/users/#{user.id}", response: from_api(user)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module MnoEnterprise
RSpec.describe Jpi::V1::CurrentUsersController, type: :routing do
let!(:user) { build(:user, :with_deletion_request, :with_organizations) }
routes { MnoEnterprise::Engine.routes }

it 'routes to #show' do
Expand All @@ -12,6 +13,10 @@ module MnoEnterprise
expect(put('/jpi/v1/current_user')).to route_to("mno_enterprise/jpi/v1/current_users#update")
end

it 'routes to #register_developer' do
expect(put('/jpi/v1/current_user/register_developer')).to route_to("mno_enterprise/jpi/v1/current_users#register_developer")
end

it 'routes to #update_password' do
expect(put('/jpi/v1/current_user/update_password')).to route_to("mno_enterprise/jpi/v1/current_users#update_password")
end
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/mno_enterprise/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class User < BaseResource
:last_sign_in_ip, :confirmation_token, :confirmed_at, :confirmation_sent_at, :unconfirmed_email,
:failed_attempts, :unlock_token, :locked_at, :name, :surname, :company, :phone, :phone_country_code,
:geo_country_code, :geo_state_code, :geo_city, :website, :orga_on_create, :sso_session, :current_password_required, :admin_role,
:api_key, :api_secret
:api_key, :api_secret, :developer

define_model_callbacks :validation #required by Devise
devise :remote_authenticatable, :registerable, :recoverable, :rememberable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ pricing:
enabled: false
dock:
enabled: true
developer:
enabled: false