Class: AtomicLti::Config

Inherits:
Object
  • Object
show all
Defined in:
app/lib/atomic_lti/config.rb

Class Method Summary collapse

Class Method Details

.assignment_configs_from_args!(args, config, key) ⇒ Object



196
197
198
199
200
# File 'app/lib/atomic_lti/config.rb', line 196

def self.assignment_configs_from_args!(args, config, key)
  config[key] = args[key].stringify_keys
  config[key]["url"] ||= args[:launch_url]
  # launch_height and launch_width are optional. Include them in the LTI config to set to a specific value
end

.assignment_selection_from_args(_domain, _text, args = {}) ⇒ Object



135
136
137
138
139
140
# File 'app/lib/atomic_lti/config.rb', line 135

def self.assignment_selection_from_args(_domain, _text, args = {})
  if args[:assignment_selection].present?
    config = args[:assignment_selection].stringify_keys
    selection_config_from_args!(args, config, :assignment_selection)
  end
end

.assignment_view_from_args(domain, text, args = {}) ⇒ Object



149
150
151
152
153
154
155
# File 'app/lib/atomic_lti/config.rb', line 149

def self.assignment_view_from_args(domain, text, args = {})
  if args[:assignment_view].present?
    config = default_configs_from_args(args, domain, text, :assignment_view)
    config["visibility"] ||= "admins"
    config
  end
end

.content_migration_args(_domain, _text, args = {}) ⇒ Object



180
181
182
183
184
185
186
187
# File 'app/lib/atomic_lti/config.rb', line 180

def self.content_migration_args(_domain, _text, args = {})
  if args[:content_migration].present?
    config = args[:content_migration] || {}
    config["export_start_url"] ||= args[:export_url]
    config["import_start_url"] ||= args[:import_url]
    config
  end
end

.custom_fields_from_args(_domain, _text, args = {}) ⇒ Object



107
108
109
110
111
112
113
114
115
116
# File 'app/lib/atomic_lti/config.rb', line 107

def self.custom_fields_from_args(_domain, _text, args = {})
  custom_fields = {
    custom_canvas_api_domain: "$Canvas.api.domain",
  }
  if args[:custom_fields].present?
    custom_fields.merge(args[:custom_fields]).stringify_keys
  else
    custom_fields.stringify_keys
  end
end

.default_configs_from_args(_args, _domain, text, placement) ⇒ Object



202
203
204
205
206
207
208
209
210
211
# File 'app/lib/atomic_lti/config.rb', line 202

def self.default_configs_from_args(_args, _domain, text, placement)
  {
    "placement": placement,
    "text": text,
    "enabled": true,
    "icon_url": "https://{domain}/atomicjolt.png",
    "message_type": "LtiResourceLinkRequest",
    "target_link_uri": "https://{domain}/lti_launches",
  }
end

.editor_button_from_args(domain, _text, args = {}) ⇒ Object



126
127
128
129
130
131
132
133
# File 'app/lib/atomic_lti/config.rb', line 126

def self.editor_button_from_args(domain, _text, args = {})
  if args[:editor_button].present?
    config = args[:editor_button].stringify_keys
    config["icon_url"] = "https://#{domain}/#{args[:editor_button][:icon_url]}"
    config.delete("icon")
    selection_config_from_args!(args, config, :editor_button)
  end
end

.icon(domain, args) ⇒ Object



101
102
103
104
105
# File 'app/lib/atomic_lti/config.rb', line 101

def self.icon(domain, args)
  if args[:icon].present?
    args[:icon].include?("http") ? args[:icon] : "https://#{domain}/#{args[:icon]}"
  end
end


142
143
144
145
146
147
# File 'app/lib/atomic_lti/config.rb', line 142

def self.link_selection_from_args(_domain, _text, args = {})
  if args[:link_selection].present?
    config = args[:link_selection].stringify_keys
    selection_config_from_args!(args, config, :link_selection)
  end
end

.lti_to_lti_advantage(jwk, domain, args = {}) ⇒ Object

Converts old lti into lti advantage NOTE this is a work in progress and may not correctly convert all LTI configs.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/lib/atomic_lti/config.rb', line 35

def self.lti_to_lti_advantage(jwk, domain, args = {})
  raise AtomicLti::Exceptions::LtiConfigMissing, "Please provide an LTI launch url" if args[:launch_url].blank?
  raise AtomicLti::Exceptions::LtiConfigMissing, "Please provide an LTI secure launch url" if args[:secure_launch_url].blank?

  if args[:content_migration].present?
    raise AtomicLti::Exceptions::LtiConfigMissing, "Please provide an IMS export url" if args[:export_url].blank?
    raise AtomicLti::Exceptions::LtiConfigMissing, "Please provide an IMS import url" if args[:import_url].blank?
  end

  {
    title: args[:title],
    scopes: AtomicLti::Definitions.scopes,
    icon: icon(domain, args),
    target_link_uri: args[:launch_url],
    oidc_initiation_url: "#{args[:launch_url]}/init",
    public_jwk: jwk.to_json,
    description: args[:description],
    custom_fields: custom_fields_from_args(domain, args[:title], args),
    extensions: [
      {
        "platform": "canvas.instructure.com",
        "domain": "https://#{domain}",
        "tool_id": "helloworld",
        "settings": {
          "privacy_level": "public",
          "text": args[:title],
          "icon_url": "https://#{domain}/atomicjolt.png",
          "selection_width": 500,
          "selection_height": 500,
          "placements": placements(domain, args[:title], args),
        },
      },
    ],
  }
end

.module_menu_from_args(domain, text, args = {}) ⇒ Object



157
158
159
160
161
162
163
164
165
# File 'app/lib/atomic_lti/config.rb', line 157

def self.module_menu_from_args(domain, text, args = {})
  if args[:module_menu].present?
    config["module_menu"] = args[:module_menu].stringify_keys
    if config["module_menu"]["message_type"].present?
      selection_config_from_args!(args, config, :module_menu)
    end
    default_configs_from_args(args, domain, text, :module_menu)
  end
end

.placement_from_args(placement, domain, text, args = {}) ⇒ Object



118
119
120
121
122
123
124
# File 'app/lib/atomic_lti/config.rb', line 118

def self.placement_from_args(placement, domain, text, args = {})
  if args[placement].present?
    default_configs_from_args(args, domain, text, placement).merge(
      args[:placement].stringify_keys,
    )
  end
end

.placements(domain, text, args) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/lib/atomic_lti/config.rb', line 71

def self.placements(domain, text, args)
  conf = []
  conf << placement_from_args(:resource_selection, domain, text, args)
  conf << placement_from_args(:global_navigation, domain, text, args)
  conf << placement_from_args(:user_navigation, domain, text, args)
  conf << placement_from_args(:course_navigation, domain, text, args)
  conf << placement_from_args(:account_navigation, domain, text, args)
  conf << placement_from_args(:post_grades, domain, text, args)
  conf << placement_from_args(:assignment_configuration, domain, text, args)
  conf << placement_from_args(:assignment_edit, domain, text, args)
  conf << placement_from_args(:assignment_menu, domain, text, args)
  conf << placement_from_args(:collaboration, domain, text, args)
  conf << placement_from_args(:course_home_sub_navigation, domain, text, args)
  conf << placement_from_args(:course_settings_sub_navigation, domain, text, args)
  conf << placement_from_args(:discussion_topic_menu, domain, text, args)
  conf << placement_from_args(:file_menu, domain, text, args)
  conf << placement_from_args(:homework_submission, domain, text, args)
  conf << placement_from_args(:migration_selection, domain, text, args)
  conf << placement_from_args(:quiz_menu, domain, text, args)
  conf << placement_from_args(:tool_configuration, domain, text, args)
  conf << editor_button_from_args(domain, text, args)
  conf << assignment_selection_from_args(domain, text, args)
  conf << link_selection_from_args(domain, text, args)
  conf << assignment_view_from_args(domain, text, args)
  conf << module_menu_from_args(domain, text, args)
  conf << wiki_page_menu_from_args(domain, text, args)
  conf << content_migration_args(domain, text, args)
  conf.compact
end

.selection_config_from_args!(args, config, placement) ⇒ Object



189
190
191
192
193
194
# File 'app/lib/atomic_lti/config.rb', line 189

def self.selection_config_from_args!(args, config, placement)
  config["placement"] = placement
  config["message_type"] ||= "ContentItemSelectionRequest"
  config["url"] ||= args[:launch_url]
  config
end

.wiki_page_menu_from_args(domain, text, args = {}) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
# File 'app/lib/atomic_lti/config.rb', line 167

def self.wiki_page_menu_from_args(domain, text, args = {})
  if args[:wiki_page_menu].present?
    config = default_configs_from_args(args, domain, text, :wiki_page_menu).merge(
      args[:wiki_page_menu].stringify_keys,
    )
    if args[:wiki_page_menu][:message_type].present?
      selection_config_from_args!(args, config, :wiki_page_menu)
    else
      config
    end
  end
end