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

Remove user id query prefixing. #266

Open
github-actions bot opened this issue Apr 13, 2022 · 0 comments
Open

Remove user id query prefixing. #266

github-actions bot opened this issue Apr 13, 2022 · 0 comments
Assignees

Comments

@github-actions
Copy link

Remove after June 2023, added to help with 2022 user id migration

Render the current user

# TODO: Remove user id query prefixing.

    ###############################################################################################

    getter user : Model::User do
      lookup = params["id"]

      # TODO: Remove user id query prefixing.
      # Remove after June 2023, added to help with 2022 user id migration
      lookup = "#{Model::User.table_name}-#{lookup}" unless lookup.starts_with?("#{Model::User.table_name}-")

      # Index ordering to use for resolving the user.
      ordering = if lookup.is_email?
                   {:email, :login_name}
                 else
                   {:id, :login_name, :staff_id}
                 end

      authority = current_user.authority_id.as(String)

      ordering.each.compact_map do |id_type|
        case id_type
        when :id
          Model::User.find(lookup)
        when :email
          Model::User.find_by_email(authority_id: authority, email: lookup)
        when :login_name
          Model::User.find_by_login_name(authority_id: authority, login_name: lookup)
        when :staff_id
          Model::User.find_by_staff_id(authority_id: authority, staff_id: lookup)
        end
      end.first do
        # 404 if the `User` was not found
        raise RethinkORM::Error::DocumentNotFound.new
      end.tap do |user|
        Log.context.set(user_id: user.id)
      end
    end

    ###############################################################################################

    # Render the current user
    get("/current", :current) do
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants