-
Notifications
You must be signed in to change notification settings - Fork 42
Add api endpoint for setting user password to be handled by moocfi #589
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
Open
Redande
wants to merge
18
commits into
master
Choose a base branch
from
api-set-password-handled-by-moocfi
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b25a155
Add api endpoint for setting user password to be handled by moocfi
Redande 28d495e
Validate request payload
Redande 7a0ee92
Lessen code complexity for codeclimate
Redande 17105ed
Further lessen code complexity
Redande e8e9296
Fix model spec
Redande c700924
Prune docker before spec_models
Redande a016ffd
Revert docker pruning before spec_models
Redande 4940b77
Specify courses.mooc.fi, delete password details from db
Redande 7f192b6
Add migration file, fix rubocop error
Redande d71bdd8
Update factorybot user for specs
Redande 968b875
Don't call @user.save twice
Redande ce1f10a
Authenticate via courses.mooc.fi if boolean true
Redande e0cdbae
Use rest-client for authentication request
Redande a900bc5
Update password through courses if boolean is set
Redande 0286f75
Add courses.mooc.fi user id to users-table
Redande cc333a4
User courses.mooc.fi user id instead of email
Redande 0794e94
Add courses.mooc.fi user id when moving password management
Redande 9f486e5
Authorize requests to courses.mooc.fi
Redande File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,27 @@ class UsersController < Api::V8::BaseController | |
end | ||
end | ||
|
||
swagger_path '/api/v8/users/{user_id}/set_password_managed_by_moocfi' do | ||
operation :post do | ||
key :description, 'Sets the boolean password_managed_by_moocfi for the user with the given id to payload value.' | ||
key :operationId, 'setPasswordManagedByMoocfi' | ||
key :produces, ['application/json'] | ||
key :tags, ['user'] | ||
parameter '$ref': '#/parameters/user_id' | ||
response 403, '$ref': '#/responses/error' | ||
response 404, '$ref': '#/responses/error' | ||
response 200 do | ||
key :description, "status 'ok' and sets the boolean password_managed_by_moocfi" | ||
schema do | ||
key :title, :status | ||
key :required, [:status] | ||
property :status, type: :string, example: 'Password managed by Mooc.fi set to true.' | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
||
def show | ||
unauthorize_guest! if current_user.guest? | ||
user = current_user | ||
|
@@ -149,6 +170,28 @@ def update | |
}, status: :bad_request | ||
end | ||
|
||
def set_password_managed_by_moocfi | ||
unauthorize_guest! if current_user.guest? | ||
|
||
@user = User.find_by!(id: params[:id]) | ||
authorize! :update, @user | ||
|
||
value = params[:set_password_managed_by_moocfi] | ||
unless value.in?([true, false]) | ||
@user.errors.add(:password_managed_by_moocfi, 'must be a boolean') | ||
else | ||
@user.password_managed_by_moocfi = value | ||
end | ||
|
||
if @user.errors.any? || [email protected] | ||
render json: { errors: @user.errors }, status: :bad_request | ||
else | ||
render json: { | ||
status: "Password managed by Mooc.fi set to #{value}." | ||
} | ||
end | ||
end | ||
|
||
private | ||
def set_email | ||
user_params = params[:user] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20250710194038_add_password_managed_by_moocfi_to_users.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddPasswordManagedByMoocfiToUsers < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :users, :password_managed_by_moocfi, :boolean, default: false | ||
end | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.