Skip to content

Commit

Permalink
Merge pull request #14654 from imtayadeway/api/refactor/move-entrypoi…
Browse files Browse the repository at this point in the history
…nt-authorization-code

Move entrypoint authorization code
  • Loading branch information
abellotti authored Apr 19, 2017
2 parents bb86d05 + 2ab84e6 commit 9722d1d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 59 deletions.
59 changes: 59 additions & 0 deletions app/controllers/api/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ def entrypoint_versions
end
end

def auth_identity
user = User.current_user
group = user.current_group
{
:userid => user.userid,
:name => user.name,
:user_href => "#{@req.api_prefix}/users/#{user.id}",
:group => group.description,
:group_href => "#{@req.api_prefix}/groups/#{group.id}",
:role => group.miq_user_role_name,
:role_href => "#{@req.api_prefix}/roles/#{group.miq_user_role.id}",
:tenant => group.tenant.name,
:groups => user.miq_groups.pluck(:description),
}
end

def entrypoint_collections
collection_config.collections_with_description.sort.collect do |collection_name, description|
{
Expand Down Expand Up @@ -61,5 +77,48 @@ def product_info
:support_website_text => I18n.t("product.support_website_text"),
}
end

def auth_authorization
user = User.current_user
group = user.current_group
{
:product_features => product_features(group.miq_user_role)
}
end

def product_features(role)
pf_result = {}
role.feature_identifiers.each { |ident| add_product_feature(pf_result, ident) }
pf_result
end

def add_product_feature(pf_result, ident)
details = MiqProductFeature.features[ident.to_s][:details]
children = MiqProductFeature.feature_children(ident)
add_product_feature_details(pf_result, ident, details, children)
children.each { |child_ident| add_product_feature(pf_result, child_ident) }
end

def add_product_feature_details(pf_result, ident, details, children)
ident_str = ident.to_s
res = {
"name" => details[:name],
"description" => details[:description]
}
collection, method, action = collection_config.what_refers_to_feature(ident_str)
collections = collection_config.names_for_feature(ident_str)
res["href"] = "#{@req.api_prefix}/#{collections.first}" if collections.one?
res["action"] = api_action_details(collection, method, action) if collection.present?
res["children"] = children if children.present?
pf_result[ident_str] = res
end

def api_action_details(collection, method, action)
{
"name" => action[:name],
"method" => method,
"href" => "#{@req.api_prefix}/#{collection}"
}
end
end
end
59 changes: 0 additions & 59 deletions app/controllers/api/base_controller/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,6 @@ def require_api_user_or_token
log_api_auth
end

def auth_identity
user = User.current_user
group = user.current_group
{
:userid => user.userid,
:name => user.name,
:user_href => "#{@req.api_prefix}/users/#{user.id}",
:group => group.description,
:group_href => "#{@req.api_prefix}/groups/#{group.id}",
:role => group.miq_user_role_name,
:role_href => "#{@req.api_prefix}/roles/#{group.miq_user_role.id}",
:tenant => group.tenant.name,
:groups => user.miq_groups.pluck(:description),
}
end

def auth_authorization
user = User.current_user
group = user.current_group
{
:product_features => product_features(group.miq_user_role)
}
end

def user_settings
{
:locale => I18n.locale.to_s.sub('-', '_'),
Expand Down Expand Up @@ -84,41 +60,6 @@ def validate_user_identity(user_obj)

private

def product_features(role)
pf_result = {}
role.feature_identifiers.each { |ident| add_product_feature(pf_result, ident) }
pf_result
end

def add_product_feature(pf_result, ident)
details = MiqProductFeature.features[ident.to_s][:details]
children = MiqProductFeature.feature_children(ident)
add_product_feature_details(pf_result, ident, details, children)
children.each { |child_ident| add_product_feature(pf_result, child_ident) }
end

def add_product_feature_details(pf_result, ident, details, children)
ident_str = ident.to_s
res = {
"name" => details[:name],
"description" => details[:description]
}
collection, method, action = collection_config.what_refers_to_feature(ident_str)
collections = collection_config.names_for_feature(ident_str)
res["href"] = "#{@req.api_prefix}/#{collections.first}" if collections.one?
res["action"] = api_action_details(collection, method, action) if collection.present?
res["children"] = children if children.present?
pf_result[ident_str] = res
end

def api_action_details(collection, method, action)
{
"name" => action[:name],
"method" => method,
"href" => "#{@req.api_prefix}/#{collection}"
}
end

def api_token_mgr
Environment.user_token_service.token_mgr('api')
end
Expand Down

0 comments on commit 9722d1d

Please sign in to comment.