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

Improve list templates and fix failing tests due to bugfixes #1277

Merged
merged 5 commits into from
Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions lib/cog/commands/alias/info.ex
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions lib/cog/commands/rule/info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
"""
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/cog/commands/rule/list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand All @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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], []},
Expand Down
4 changes: 4 additions & 0 deletions priv/templates/embedded/alias-info.greenbar
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
~each var=$results~
**Name:** ~$item.visibility~:~$item.name~
**Pipeline:** `~$item.pipeline~`
~end~
12 changes: 4 additions & 8 deletions priv/templates/embedded/alias-list.greenbar
Original file line number Diff line number Diff line change
@@ -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~

Expand Down
6 changes: 2 additions & 4 deletions priv/templates/embedded/bundle-info.greenbar
Original file line number Diff line number Diff line change
@@ -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~
6 changes: 2 additions & 4 deletions priv/templates/embedded/bundle-list.greenbar
Original file line number Diff line number Diff line change
Expand Up @@ -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~

Expand Down
23 changes: 16 additions & 7 deletions priv/templates/embedded/bundle-versions.greenbar
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
~each var=$results~
~$item.compatible~

Copy link
Member Author

Choose a reason for hiding this comment

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

@mpeck Wasn't sure what this did. Let me know if we need to keep it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Confirmed with @mpeck that this can be removed.

~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~

Expand Down
1 change: 0 additions & 1 deletion priv/templates/embedded/group-info.greenbar
Original file line number Diff line number Diff line change
Expand Up @@ -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~
1 change: 0 additions & 1 deletion priv/templates/embedded/group-list-verbose.greenbar
Original file line number Diff line number Diff line change
Expand Up @@ -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~
14 changes: 3 additions & 11 deletions priv/templates/embedded/permission-info.greenbar
Original file line number Diff line number Diff line change
@@ -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~
3 changes: 1 addition & 2 deletions priv/templates/embedded/permission-list.greenbar
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
~each var=$results~
~attachment color="gray"~
**Name:** ~$item.name~
**Bundle:** ~$item.bundle~
~$item.bundle~:~$item.name~
~end~
~end~
1 change: 0 additions & 1 deletion priv/templates/embedded/relay-group-info.greenbar
Original file line number Diff line number Diff line change
Expand Up @@ -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~
1 change: 0 additions & 1 deletion priv/templates/embedded/relay-group-list-verbose.greenbar
Original file line number Diff line number Diff line change
Expand Up @@ -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~
6 changes: 2 additions & 4 deletions priv/templates/embedded/relay-list.greenbar
Original file line number Diff line number Diff line change
Expand Up @@ -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~

Expand Down
1 change: 0 additions & 1 deletion priv/templates/embedded/role-info.greenbar
Original file line number Diff line number Diff line change
@@ -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~
Expand Down
14 changes: 13 additions & 1 deletion priv/templates/embedded/role-list.greenbar
Original file line number Diff line number Diff line change
@@ -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~
17 changes: 7 additions & 10 deletions priv/templates/embedded/rule-info.greenbar
Original file line number Diff line number Diff line change
@@ -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~
4 changes: 0 additions & 4 deletions priv/templates/embedded/rule-list.greenbar
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
~each var=$results as=rule~
~attachment color="gray"~
**Command:** ~$rule.command~
**ID:** ~$rule.id~
**Rule:**

```
~$rule.rule~
```

~end~
~end~
2 changes: 1 addition & 1 deletion priv/templates/embedded/trigger-create.greenbar
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
~each var=$results~
Created trigger '~$item.id~'
Created trigger '~$item.name~'
~end~
24 changes: 9 additions & 15 deletions priv/templates/embedded/trigger-info.greenbar
Original file line number Diff line number Diff line change
@@ -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~
Loading