Skip to content

extract many auth helpers from shared to middleware - #47934

Merged
davidsbailey merged 11 commits into
stagingfrom
extract-middleware-auth-helpers
Sep 6, 2022
Merged

extract many auth helpers from shared to middleware#47934
davidsbailey merged 11 commits into
stagingfrom
extract-middleware-auth-helpers

Conversation

@davidsbailey

@davidsbailey davidsbailey commented Sep 2, 2022

Copy link
Copy Markdown
Member

depends on #47931 .

as part of rounding up remaining DASHBOARD_DB uses outside of the dashboard directory, I discovered that many helpers within auth_helpers.rb are now only used by dashboard/legacy, and can therefore be moved into dashboard/legacy. This kind of move will help us add rules which enforce that only dashboard code is accessing dashboard DB.

Testing story

existing unit tests appear to cover this change pretty well.

@davidsbailey davidsbailey changed the title Extract middleware auth helpers extract middleware auth helpers Sep 2, 2022
@davidsbailey
davidsbailey changed the base branch from staging to move-dashboard-legacy September 2, 2022 16:44
@davidsbailey davidsbailey changed the title extract middleware auth helpers extract many auth helpers from shared to middleware Sep 2, 2022
@davidsbailey
davidsbailey marked this pull request as ready for review September 2, 2022 16:45
# @returns [Boolean] true if the current user is an admin.
def admin?
current_user && !!current_user[:admin]
end

@davidsbailey davidsbailey Sep 2, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

still used outside of dashboard here:

def has_permission?(permission)
permission = permission.to_s.strip.downcase
case permission
when 'admin' then admin?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

has_permission? just got removed in #47921, so now admin? can move to dashboard too.

Base automatically changed from move-dashboard-legacy to staging September 2, 2022 18:44
def current_user
return nil if (id = current_user_id).nil?
@dashboard_user ||= DASHBOARD_DB[:users][id: id]
end

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

current_user is still used in pegasus here:

since we are just checking whether the user is signed in, it looks possible to change it so that it gets that information from a cookie instead, like we do here:

- cookie_key = environment_specific_cookie_name '_user_type'
- user_type = request.cookies[cookie_key]
- user_type = "student" if user_type == "student_y"
- if ["student", "teacher"].include?(user_type)
but I am going to save that for a future PR.

@davidsbailey
davidsbailey merged commit 11d0e80 into staging Sep 6, 2022
@davidsbailey
davidsbailey deleted the extract-middleware-auth-helpers branch September 6, 2022 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants