Permalink
Browse files

Merge pull request #1277 from operable/vanstee/list-command-improvements

Improve list templates and fix failing tests due to bugfixes
  • Loading branch information...
vanstee committed Jan 4, 2017
2 parents 731f733 + 2bf520a commit ae2608a823e9125c956caecf5ed423f60b516c51
Showing with 412 additions and 780 deletions.
  1. +76 −0 lib/cog/commands/alias/info.ex
  2. +2 −2 lib/cog/commands/rule/info.ex
  3. +6 −6 lib/cog/commands/rule/list.ex
  4. +1 −1 mix.lock
  5. +4 −0 priv/templates/embedded/alias-info.greenbar
  6. +4 −8 priv/templates/embedded/alias-list.greenbar
  7. +2 −4 priv/templates/embedded/bundle-info.greenbar
  8. +2 −4 priv/templates/embedded/bundle-list.greenbar
  9. +16 −7 priv/templates/embedded/bundle-versions.greenbar
  10. +0 −1 priv/templates/embedded/group-info.greenbar
  11. +0 −1 priv/templates/embedded/group-list-verbose.greenbar
  12. +3 −11 priv/templates/embedded/permission-info.greenbar
  13. +1 −2 priv/templates/embedded/permission-list.greenbar
  14. +0 −1 priv/templates/embedded/relay-group-info.greenbar
  15. +0 −1 priv/templates/embedded/relay-group-list-verbose.greenbar
  16. +2 −4 priv/templates/embedded/relay-list.greenbar
  17. +0 −1 priv/templates/embedded/role-info.greenbar
  18. +13 −1 priv/templates/embedded/role-list.greenbar
  19. +7 −10 priv/templates/embedded/rule-info.greenbar
  20. +0 −4 priv/templates/embedded/rule-list.greenbar
  21. +1 −1 priv/templates/embedded/trigger-create.greenbar
  22. +9 −15 priv/templates/embedded/trigger-info.greenbar
  23. +10 −6 priv/templates/embedded/trigger-list.greenbar
  24. +2 −19 priv/templates/embedded/trigger-update.greenbar
  25. +7 −15 priv/templates/embedded/user-info.greenbar
  26. +1 −6 priv/templates/embedded/user-list.greenbar
  27. +15 −0 test/cog/chat/hipchat/templates/embedded/alias_info_test.exs
  28. +3 −11 test/cog/chat/hipchat/templates/embedded/alias_list_test.exs
  29. +4 −4 test/cog/chat/hipchat/templates/embedded/bundle_info_test.exs
  30. +6 −16 test/cog/chat/hipchat/templates/embedded/bundle_list_test.exs
  31. +4 −11 test/cog/chat/hipchat/templates/embedded/bundle_versions_test.exs
  32. +3 −23 test/cog/chat/hipchat/templates/embedded/permission_info_test.exs
  33. +3 −8 test/cog/chat/hipchat/templates/embedded/permission_list_test.exs
  34. +3 −8 test/cog/chat/hipchat/templates/embedded/relay_list_test.exs
  35. +7 −4 test/cog/chat/hipchat/templates/embedded/role_list_test.exs
  36. +4 −27 test/cog/chat/hipchat/templates/embedded/rule_info_test.exs
  37. +6 −8 test/cog/chat/hipchat/templates/embedded/rule_list_test.exs
  38. +8 −8 test/cog/chat/hipchat/templates/embedded/trigger_create_test.exs
  39. +16 −44 test/cog/chat/hipchat/templates/embedded/trigger_info_test.exs
  40. +2 −11 test/cog/chat/hipchat/templates/embedded/trigger_list_test.exs
  41. +7 −27 test/cog/chat/hipchat/templates/embedded/trigger_update_test.exs
  42. +0 −35 test/cog/chat/hipchat/templates/embedded/user_info_test.exs
  43. +3 −42 test/cog/chat/hipchat/templates/embedded/user_list_test.exs
  44. +15 −0 test/cog/chat/slack/templates/embedded/alias_info_test.exs
  45. +2 −17 test/cog/chat/slack/templates/embedded/alias_list_test.exs
  46. +3 −3 test/cog/chat/slack/templates/embedded/bundle_info_test.exs
  47. +7 −28 test/cog/chat/slack/templates/embedded/bundle_list_test.exs
  48. +4 −18 test/cog/chat/slack/templates/embedded/bundle_versions_test.exs
  49. +2 −24 test/cog/chat/slack/templates/embedded/permission_info_test.exs
  50. +4 −13 test/cog/chat/slack/templates/embedded/permission_list_test.exs
  51. +4 −13 test/cog/chat/slack/templates/embedded/relay_list_test.exs
  52. +10 −7 test/cog/chat/slack/templates/embedded/role_list_test.exs
  53. +5 −30 test/cog/chat/slack/templates/embedded/rule_info_test.exs
  54. +19 −25 test/cog/chat/slack/templates/embedded/rule_list_test.exs
  55. +9 −8 test/cog/chat/slack/templates/embedded/trigger_create_test.exs
  56. +16 −42 test/cog/chat/slack/templates/embedded/trigger_info_test.exs
  57. +3 −15 test/cog/chat/slack/templates/embedded/trigger_list_test.exs
  58. +4 −27 test/cog/chat/slack/templates/embedded/trigger_update_test.exs
  59. +0 −34 test/cog/chat/slack/templates/embedded/user_info_test.exs
  60. +6 −54 test/cog/chat/slack/templates/embedded/user_list_test.exs
  61. +32 −0 test/commands/alias/info_test.exs
  62. +1 −1 test/commands/rule/info_test.exs
  63. +3 −3 test/commands/rule/list_test.exs
@@ -0,0 +1,76 @@
defmodule Cog.Commands.Alias.Info do
use Cog.Command.GenCommand.Base,
bundle: Cog.Util.Misc.embedded_bundle,
name: "alias-info"
alias Cog.Models.User
alias Cog.Queries
alias Cog.Repo
require Cog.Commands.Helpers, as: Helpers
@description "Shows a specific alias"
@arguments "<alias-name>"
@examples """
Showing a specific alias:
alias info user:my-awesome-alias
"""
@output_description "Returns a serialized alias"
@output_example """
[
{
"visibility": "user",
"pipeline": "echo \\\"My Awesome Alias\\\"",
"name": "my-awesome-alias"
}
]
"""
rule "when command is #{Cog.Util.Misc.embedded_bundle}:alias-info allow"
def handle_message(req = %{args: [name]}, state) when is_binary(name) do
user_id = req.user["id"]
result = case find_alias(name, %User{id: user_id}) do
{:ok, alias} ->
{:ok, "alias-info", Helpers.jsonify(alias)}
error ->
error
end
case result do
{:ok, template, data} ->
{:reply, req.reply_to, template, data, state}
{:error, err} ->
{:error, req.reply_to, Helpers.error(err), state}
end
end
def handle_message(req = %{args: []}, state),
do: {:error, req.reply_to, Helpers.error({:not_enough_args, 1}), state}
def handle_message(req, state),
do: {:error, req.reply_to, Helpers.error({:too_many_args, 1}), state}
def find_alias(full_name, user) do
query = case full_name do
"site:" <> name ->
Queries.Alias.site_alias_by_name(name)
"user:" <> name ->
Queries.Alias.user_alias_by_name(user, name)
name ->
Queries.Alias.user_alias_by_name(user, name)
end
case Repo.one(query) do
nil ->
{:error, :not_found}
alias ->
{:ok, alias}
end
end
end
@@ -18,7 +18,7 @@ defmodule Cog.Commands.Rule.Info do
{
"rule": "when command is operable:min allow",
"id": "00000000-0000-0000-0000-000000000000",
"command_name": "operable:min"
"command": "operable:min"
}
]
"""
@@ -40,7 +40,7 @@ defmodule Cog.Commands.Rule.Info do
if Cog.UUID.is_uuid?(id) do
case Rules.rule(id) do
%Rule{}=rule ->
{:ok, Cog.V1.RuleView.render("show.json", %{rule: rule})[:rule]}
{:ok, rule}
nil ->
{:error, {:resource_not_found, "rule", id}}
end
@@ -6,7 +6,9 @@ defmodule Cog.Commands.Rule.List do
alias Cog.Commands.Rule
alias Cog.Repository.Rules
@description "List all rules or rules for the provided command."
@description "List all rules or rules for the provided command"
@arguments "[command]"
@output_description "Returns the list of rules."
@@ -25,22 +27,20 @@ defmodule Cog.Commands.Rule.List do
]
"""
option "command", type: "string", short: "c", description: "List rules belonging to command"
permission "manage_commands"
rule "when command is #{Cog.Util.Misc.embedded_bundle}:rule-list must have #{Cog.Util.Misc.embedded_bundle}:manage_commands"
def handle_message(req, state) do
case list(req) do
def handle_message(req = %{args: args}, state) do
case list(args) do
{:ok, rules} ->
{:reply, req.reply_to, "rule-list", rules, state}
{:error, error} ->
{:error, req.reply_to, Rule.error(error), state}
end
end
defp list(%{options: %{"command" => command}}),
defp list([command]),
do: Rules.rules_for_command(command)
defp list(_req),
do: {:ok, Rules.all_rules}
View
@@ -27,7 +27,7 @@
"getopt": {:git, "https://github.com/jcomellas/getopt.git", "68fe326f2c7585eb32a5b136dffc75428a53fc02", [branch: "master"]},
"goldrush": {:hex, :goldrush, "0.1.8", "2024ba375ceea47e27ea70e14d2c483b2d8610101b4e852ef7f89163cdb6e649", [:rebar3], []},
"gproc": {:hex, :gproc, "0.5.0", "2df2d886f8f8a7b81a4b04aa17972b5965bbc5bf0100ea6d8e8ac6a0e7389afe", [:rebar], []},
"greenbar": {:git, "https://github.com/operable/greenbar.git", "e56d7e6004765613feddd8bb45114de35aad1cb7", []},
"greenbar": {:git, "https://github.com/operable/greenbar.git", "b8cc204d05387354e2ecaaecde64bed9661b3f0c", []},
"greenbar_markdown": {:git, "https://github.com/operable/greenbar_markdown.git", "ad6d027c92ef095a0461c08847d3eb999659c3a2", []},
"hackney": {:hex, :hackney, "1.6.1", "ddd22d42db2b50e6a155439c8811b8f6df61a4395de10509714ad2751c6da817", [:rebar3], [{:certifi, "0.4.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.0", [hex: :ssl_verify_fun, optional: false]}]},
"html_entities": {:hex, :html_entities, "0.3.0", "2f278ffc69c3f0cbd5996628fef37cf922fa715f3e04b9f38924c8adced3f25a", [:mix], []},
@@ -0,0 +1,4 @@
~each var=$results~
**Name:** ~$item.visibility~:~$item.name~
**Pipeline:** `~$item.pipeline~`
~end~
@@ -1,18 +1,14 @@
~each var=$results~
~if cond=$item.visibility == "user"~
~attachment color="blue"~
**Name:** ~$item.name~
**Visibility:** ~$item.visibility~
**Pipeline:** `~$item.pipeline~`
~attachment color="green"~
~$item.visibility~:~$item.name~
~end~
~end~
~if cond=$item.visibility == "site"~
~attachment color="gray"~
**Name:** ~$item.name~
**Visibility:** ~$item.visibility~
**Pipeline:** `~$item.pipeline~`
~attachment color="blue"~
~$item.visibility~:~$item.name~
~end~
~end~
@@ -1,10 +1,8 @@
~each var=$results as=bundle~
**ID:** ~$bundle.id~
**Name:** ~$bundle.name~
**Relay Groups:** ~if cond=$bundle.relay_groups empty?~Unassigned~end~~join var=$bundle.relay_groups with=", "~~$item.name~~end~
**Versions:** ~join var=$bundle.versions with=", "~~$item.version~~end~
~if cond=$bundle.incompatible_versions not_empty?~
**Incompatible Versions:** ~join var=$bundle.incompatible_versions with=", "~~$item.version~~end~
~end~
**Version Enabled:** ~if cond=$bundle.enabled_version bound?~~$bundle.enabled_version.version~~end~~if cond=$bundle.enabled_version not_bound?~Disabled~end~
**Relay Groups:** ~if cond=$bundle.relay_groups empty?~Unassigned~end~~join var=$bundle.relay_groups with=", "~~$item.name~~end~
~if cond=$bundle.incompatible_versions not_empty?~**Incompatible Versions:** ~join var=$bundle.incompatible_versions with=", "~~$item.version~~end~~end~
~end~
@@ -2,15 +2,13 @@
~if cond=$item.enabled_version bound?~
~attachment color="green"~
**Name:** ~$item.name~
**Version Enabled:** ~$item.enabled_version.version~
~$item.name~ (~$item.enabled_version.version~)
~end~
~end~
~if cond=$item.enabled_version not_bound?~
~attachment color="red"~
**Name:** ~$item.name~
**Version Enabled:** Disabled
~$item.name~ (disabled)
~end~
~end~
@@ -1,15 +1,24 @@
~each var=$results~
~$item.compatible~
~if cond=$item.incompatible not_bound?~
~attachment color="gray"~
**Version:** ~$item.version~
**Enabled:** ~$item.enabled~
~if cond=$item.enabled == true~
~attachment color="green"~
~$item.version~ (enabled)
~end~
~end~
~if cond=$item.incompatible bound?~
~if cond=$item.enabled == false~
~attachment color="red"~
**Version:** ~$item.version~
**Incompatible**
~$item.version~ (disabled)
~end~
~end~
~end~
~if cond=$item.incompatible bound?~
~attachment color="yellow"~
~$item.version~ (incompatible)
~end~
~end~
@@ -2,6 +2,5 @@
**Name:** ~$group.name~
**ID:** ~$group.id~
**Roles:** ~if cond=$group.roles empty?~Unassigned~end~~join var=$group.roles with=", "~~$item.name~~end~
**Members:** ~if cond=$group.members empty?~No members~end~~join var=$group.members with=", "~~$item.username~~end~
~end~
@@ -3,7 +3,6 @@
**Name:** ~$group.name~
**ID:** ~$group.id~
**Roles:** ~if cond=$group.roles empty?~Unassigned~end~~join var=$group.roles with=", "~~$item.name~~end~
**Members:** ~if cond=$group.members empty?~No members~end~~join var=$group.members with=", "~~$item.username~~end~
~end~
~end~
@@ -1,12 +1,4 @@
~if cond=length($results) == 1~
**ID**: ~$results[0].id~
**Bundle**: ~$results[0].bundle~
**Name**: ~$results[0].name~
~end~
~if cond=length($results) > 1~
| Bundle | Name | ID |
|--------|------|----|
~each var=$results~
|~$item.bundle~|~$item.name~|~$item.id~|
~end~
~each var=$results as=permission~
**Name:** ~$permission.bundle~:~$permission.name~
**ID:** ~$permission.id~
~end~
@@ -1,6 +1,5 @@
~each var=$results~
~attachment color="gray"~
**Name:** ~$item.name~
**Bundle:** ~$item.bundle~
~$item.bundle~:~$item.name~
~end~
~end~
@@ -2,7 +2,6 @@
~attachment color="gray"~
**Name:** ~$relay_group.name~
**Relays:** ~if cond=$relay_group.relays empty?~No relays~end~~join var=$relay_group.relays with=", "~~$item.name~~end~
**Bundles:** ~if cond=$relay_group.bundles empty?~No bundles assigned~end~~join var=$relay_group.bundles with=", "~~$item.name~~end~
~end~
~end~
@@ -2,7 +2,6 @@
~attachment color="gray"~
**Name:** ~$relay_group.name~
**Relays:** ~if cond=$relay_group.relays empty?~No relays~end~~join var=$relay_group.relays with=", "~~$item.name~~end~
**Bundles:** ~if cond=$relay_group.bundles empty?~No bundles assigned~end~~join var=$relay_group.bundles with=", "~~$item.name~~end~
~end~
~end~
@@ -2,15 +2,13 @@
~if cond=$relay.status == "enabled"~
~attachment color="green"~
**Name:** ~$relay.name~
**Status:** ~$relay.status~
~$relay.name~ (enabled)
~end~
~end~
~if cond=$relay.status == "disabled"~
~attachment color="red"~
**Name:** ~$relay.name~
**Status:** ~$relay.status~
~$relay.name~ (disabled)
~end~
~end~
@@ -1,5 +1,4 @@
~each var=$results as=role~
**Name:** ~$role.name~
**ID:** ~$role.id~
**Permissions:** ~if cond=$role.permissions empty?~No permissions~end~~join var=$role.permissions with=", "~~$item.bundle~:~$item.name~~end~
@@ -1,3 +1,15 @@
~each var=$results as=role~
~$role.name~
~if cond=$role.permissions not_empty?~
~attachment color="blue"~
~$role.name~ (~count var=$role.permissions~ permissions)
~end~
~end~
~if cond=$role.permissions empty?~
~attachment color="gray"~
~$role.name~ (0 permissions)
~end~
~end~
~end~
@@ -1,11 +1,8 @@
~if cond=length($results) == 1~
**ID**: ~$results[0].id~
**Command**: ~$results[0].command_name~
**Rule**: ~$results[0].rule~
~end~
~if cond=length($results) > 1~
| Command | Rule | ID |
|---------|------|----|
~each var=$results~|~$item.command_name~|~$item.rule~|~$item.id~|
~end~
~each var=$results as=rule~
**ID:** ~$rule.id~
**Rule:**
```
~$rule.rule~
```
~end~
@@ -1,12 +1,8 @@
~each var=$results as=rule~
~attachment color="gray"~
**Command:** ~$rule.command~
**ID:** ~$rule.id~
**Rule:**
```
~$rule.rule~
```
~end~
~end~
@@ -1,3 +1,3 @@
~each var=$results~
Created trigger '~$item.id~'
Created trigger '~$item.name~'
~end~
@@ -1,16 +1,10 @@
~if cond=length($results) == 1~
**ID**: ~$results[0].id~
**Name**: ~$results[0].name~
**Description**: ~$results[0].description~
**Enabled?**: ~$results[0].enabled~
**Pipeline**: `~$results[0].pipeline~`
**As User**: ~$results[0].as_user~
**Timeout (sec)**: ~$results[0].timeout_sec~
**Invocation URL**: ~$results[0].invocation_url~
~end~
~if cond=length($results) > 1~
| ID | Name | Description | Enabled? | Pipeline | As User | Timeout | Invocation URL |
|----|------|-------------|----------|----------|---------|---------|----------------|
~each var=$results~|~$item.id~|~$item.name~|~if cond=$item.description bound?~~$item.description~~end~|~$item.enabled~|`~$item.pipeline~`|~if cond=$item.as_user~~$item.as_user~~end~|~$item.timeout_sec~|~$item.invocation_url~|
~end~
~each var=$results as=trigger~
**Name:** ~$trigger.name~
**ID:** ~$trigger.id~
**Description:** ~$trigger.description~
**Status:** ~if cond=$trigger.enabled == true~Enabled~end~~if cond=$trigger.enabled == false~Disabled~end~
**Pipeline:** `~$trigger.pipeline~`
**As User:** ~$trigger.as_user~
**Timeout:** ~$trigger.timeout_sec~ second~if cond=$trigger.timeout_sec > 1~s~end~
**Invocation URL:** ~$trigger.invocation_url~
~end~
Oops, something went wrong.

0 comments on commit ae2608a

Please sign in to comment.