-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding GraphQL mutations to add and remove NLU keywords to/from tipli…
…ne menu options Only super-admins can use these mutations. Reference: CV2-3709.
- Loading branch information
Showing
7 changed files
with
491 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module NluMutations | ||
class ToggleKeywordInTiplineMenu < Mutations::BaseMutation | ||
argument :language, GraphQL::Types::String, required: true | ||
argument :keyword, GraphQL::Types::String, required: true | ||
argument :menu, GraphQL::Types::String, required: true # "main" or "secondary" | ||
argument :menu_option_index, GraphQL::Types::Int, required: true # zero-based... the order is the same displayed in the tipline and in the tipline settings page | ||
|
||
field :success, GraphQL::Types::Boolean, null: true | ||
|
||
def resolve(language:, menu:, menu_option_index:, keyword:) | ||
begin | ||
if User.current.is_admin | ||
nlu = SmoochNlu.new(Team.current.slug) | ||
nlu.enable! | ||
if toggle == :add | ||
nlu.add_keyword_to_menu_option(language, menu, menu_option_index, keyword) | ||
elsif toggle == :remove | ||
nlu.remove_keyword_from_menu_option(language, menu, menu_option_index, keyword) | ||
end | ||
{ success: true } | ||
else | ||
{ success: false } | ||
end | ||
rescue | ||
{ success: false } | ||
end | ||
end | ||
end | ||
|
||
class AddKeywordToTiplineMenu < ToggleKeywordInTiplineMenu | ||
def toggle | ||
:add | ||
end | ||
end | ||
|
||
class RemoveKeywordFromTiplineMenu < ToggleKeywordInTiplineMenu | ||
def toggle | ||
:remove | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.