Skip to content

Commit

Permalink
[webui][api] split Flag#default_status in tw routines default_status …
Browse files Browse the repository at this point in the history
…and effective_status, make WebUI call default_status for flag toggling and make get_flags call effective_status to fill its flag status array
  • Loading branch information
mmohring committed Nov 3, 2016
1 parent 579cd3f commit 6ee6edf
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/api/app/mixins/get_flags.rb
Expand Up @@ -19,7 +19,7 @@ def get_flags(flag_type)
# If there is no flag create a temporary one.
unless flag
flag = flags.new( flag: flag_type, repo: repository, architecture: architecture )
flag.status = flag.default_status
flag.status = flag.effective_status
end
the_flags[repository] << flag
end
Expand Down
34 changes: 34 additions & 0 deletions src/api/app/models/flag.rb
Expand Up @@ -70,6 +70,40 @@ def default_status
all_flag || arch_flag
all_flag = main_object.project.flags.where("flag = ? AND repo IS NULL AND architecture_id IS NULL", flag).first unless all_flag
end

if same_flag
return repo_flag.status if repo_flag
return arch_flag.status if arch_flag
return all_flag.status if all_flag
end
if arch_flag
return all_flag.status if all_flag
end
if repo_flag
return all_flag.status if all_flag
end
if main_object.kind_of? Package
return all_flag.status if all_flag
end
return Flag.default_status(flag)
end

def effective_status
all_flag = main_object.flags.where("flag = ? AND repo IS NULL AND architecture_id IS NULL", flag).first
repo_flag = main_object.flags.where("flag = ? AND repo = ? AND architecture_id IS NULL", flag, repo).first
arch_flag = main_object.flags.where("flag = ? AND repo IS NULL AND architecture_id = ?", flag, architecture_id).first
same_flag = main_object.flags.where("flag = ? AND repo = ? AND architecture_id = ?", flag, repo, architecture_id).first
# Package settings only override project settings...
if main_object.kind_of? Package
# do the same_flag check first to see if all_flag or same_flag had been set on package level, they *both* overwrite the project level
same_flag = main_object.project.flags.where("flag = ? AND repo = ? AND architecture_id = ?", flag, repo, architecture_id).first unless
all_flag || same_flag || repo_flag || arch_flag
repo_flag = main_object.project.flags.where("flag = ? AND repo = ? AND architecture_id IS NULL", flag, repo).first unless
all_flag || repo_flag || arch_flag
arch_flag = main_object.project.flags.where("flag = ? AND repo IS NULL AND architecture_id = ?", flag, architecture_id).first unless
all_flag || arch_flag
all_flag = main_object.project.flags.where("flag = ? AND repo IS NULL AND architecture_id IS NULL", flag).first unless all_flag
end

return same_flag.status if same_flag
return repo_flag.status if repo_flag
Expand Down
Expand Up @@ -37,8 +37,8 @@
<div class="iconwrapper"><div class="icons-<%= flag.flag %>_enable_blue icon_24"></div></div>
<%= link_to 'Enable', { action: :toggle_flag, project: @project, package: @package, flag: flag }, id: "#{flag.fullname}_enable", class: "flag_spinner_trigger_#{flag.flag}", method: :put, remote: remote %>
<% end %>
<div class="iconwrapper"><div class="icons-<%= flag.flag %>_<%= Flag.default_status(flag.flag) %>_grey icon_24"></div></div>
<%= link_to "Take default (#{Flag.default_status(flag.flag)})", { action: :remove_flag, project: @project, package: @package, flag: flag }, id: "#{flag.fullname}_remove", class: "flag_spinner_trigger_#{flag.flag}", method: :delete, remote: remote %>
<div class="iconwrapper"><div class="icons-<%= flag.flag %>_<%= flag.default_status %>_grey icon_24"></div></div>
<%= link_to "Take default (#{flag.default_status})", { action: :remove_flag, project: @project, package: @package, flag: flag }, id: "#{flag.fullname}_remove", class: "flag_spinner_trigger_#{flag.flag}", method: :delete, remote: remote %>
<% end %>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/api/test/unit/code_quality_test.rb
Expand Up @@ -87,7 +87,8 @@ def setup
'PersonController#internal_register' => 112.01,
'Package#find_changed_issues' => 93.74,
'Package#close_requests' => 84.82,
'Flag#default_status' => 90.56,
'Flag#default_status' => 93.79,
'Flag#effective_status' => 90.56,
'PublicController#binary_packages' => 126.16,
'Repository#cleanup_before_destroy' => 82.98,
'RequestController#render_request_collection' => 82.38,
Expand Down

0 comments on commit 6ee6edf

Please sign in to comment.