effective_learndash 0.1.8 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb60befd537b5ed6b7111baf26c546997223c4350c60d0b66cf6803281616c64
4
- data.tar.gz: '0087f4c16776214a5bb6b098078ade3f3a215742f75820b1c9046180faa0cf0b'
3
+ metadata.gz: 076d625d658223be135f56e74dc7f7c6e6e077688f2ed38a51f7ac4eb88b1233
4
+ data.tar.gz: 94849221f3f64496dcff99ee3f8a313d3143a809c750ca62edcceabbb204b68d
5
5
  SHA512:
6
- metadata.gz: 0a9def7fbe45dec58d8768454a9adccffb989b44a1f387ee1b04de0c56f9db48ba5f104012ee4060fbf4adb9e35ec3ebc0281ff4274f10c486efc3ba7416e526
7
- data.tar.gz: 5b8bd37c4ea919fc77aa4f61d6f8aa8b4c638dbb8b9deb72bcf632fa4c56cd01da62024f0e8ff98656060e9e2d25315a5882bebb4760a6b21d7c860cc49165f6
6
+ metadata.gz: f1a22b8cedfb1eb29584a114373991dfc1acab6b544326ccb24456d7b9078e535d449d828d25ce6390a5e69b3f78c725eef08e8e3f6689da2269f79073f0da93
7
+ data.tar.gz: 47841e76f2d3d4a7185e44b8a49ff3eccb186f3229eb9472715770ce4f6355dae60a684e2f455feb6da35167513aee669ddd97b2d40a0b52a58d2feb21a003b6
data/README.md CHANGED
@@ -115,6 +115,12 @@ There are no webhooks or callbacks from LearnDash, everything is a GET request t
115
115
 
116
116
  You can refresh an entire LearnDash user in one operation and it will sync the entire user at once, `user.learndash_user.refresh!`
117
117
 
118
+ ## Delete User
119
+
120
+ If you need to delete a user, from wordpress:
121
+
122
+ 1. Top Left Corner -> My Sites -> Network Admin -> Users
123
+
118
124
  ## License
119
125
 
120
126
  MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
@@ -7,5 +7,13 @@ module Admin
7
7
 
8
8
  on :refresh, success: -> { "Successfully refreshed #{resource} and all course enrollments" }
9
9
 
10
+ submit :update_password, 'Update Password'
11
+
12
+ private
13
+
14
+ def permitted_params
15
+ params.require(:effective_learndash_user).permit!
16
+ end
17
+
10
18
  end
11
19
  end
@@ -87,8 +87,9 @@ module EffectiveLearndashCourseRegistration
87
87
  course_registrants
88
88
  end
89
89
 
90
- # Enroll them in all courses.
90
+ # Create learndash user and enroll in all courses
91
91
  def after_submit_purchased!
92
+ learndash_owner.create_learndash_user
92
93
  course_registrants.each { |registrant| registrant.owner.create_learndash_enrollment(course: registrant.learndash_course) }
93
94
  end
94
95
 
@@ -155,12 +156,6 @@ module EffectiveLearndashCourseRegistration
155
156
 
156
157
  # Save record
157
158
  save!
158
-
159
- # Create a learndash user now before payment to catch any errors in server stuff before payment.
160
- learndash_owner.create_learndash_user
161
- raise('expected a persisted learndash user') unless learndash_owner.learndash_user&.persisted?
162
-
163
- true
164
159
  end
165
160
 
166
161
  private
@@ -52,6 +52,17 @@ module Effective
52
52
  nil
53
53
  end
54
54
 
55
+ def update_password(owner, password)
56
+ raise('expected a leardash owner') unless owner.class.respond_to?(:effective_learndash_owner?)
57
+ raise('expected an existing learndash user') unless owner.learndash_user&.persisted?
58
+ raise('expected a password') unless password.present?
59
+
60
+ user = user_id(owner) || raise('expected a user')
61
+ payload = { password: password }
62
+
63
+ post("/wp/v2/users/#{user}", payload.stringify_keys)
64
+ end
65
+
55
66
  # Create User
56
67
  # Usernames can only contain lowercase letters (a-z) and numbers.
57
68
  def create_user(owner)
@@ -98,5 +98,11 @@ module Effective
98
98
  assign_attributes(last_synced_at: Time.zone.now)
99
99
  end
100
100
 
101
+ def update_password!
102
+ save!
103
+ EffectiveLearndash.api.update_password(owner, password)
104
+ true
105
+ end
106
+
101
107
  end
102
108
  end
@@ -1,6 +1,16 @@
1
1
  = effective_form_with(model: [:admin, learndash_user], engine: true) do |f|
2
2
 
3
- = f.select :owner, {'Owners' => current_user.class.sorted }, polymorphic: true,
4
- hint: 'Create a LearnDash account for this user'
3
+ - if f.object.new_record?
4
+ = f.select :owner, {'Owners' => current_user.class.sorted }, polymorphic: true,
5
+ hint: 'Create a LearnDash account for this user'
5
6
 
6
- = f.submit
7
+ = f.submit
8
+
9
+ - if f.object.persisted?
10
+ = f.text_field :password, label: 'New Password',
11
+ value: EffectiveLearndash.wp_password_for(learndash_user.owner)
12
+
13
+ %p.text-muted
14
+ This action will also update the LearnDash LMS wordpress user account password.
15
+
16
+ = f.submit 'Update Password'
@@ -3,12 +3,18 @@
3
3
  = link_to(learndash_user.owner, "/admin/users/#{learndash_user.owner.to_param}/edit")
4
4
  has an existing account on LearnDash.
5
5
 
6
+ %p= link_to "LearnDash LMS User Admin", EffectiveLearndash.learndash_url.chomp('/') + "/wp-admin/user-edit.php?user_id=#{learndash_user.user_id}", target: '_blank'
7
+
6
8
  %ul
7
9
  %li Email: #{learndash_user.email}
8
10
  %li Username: #{learndash_user.username}
9
- %li Password: #{learndash_user.password}
11
+ %li
10
12
 
11
- %p= link_to "LearnDash LMS User Admin", EffectiveLearndash.learndash_url.chomp('/') + "/wp-admin/user-edit.php?user_id=#{learndash_user.user_id}", target: '_blank'
13
+ Password: #{learndash_user.password}
14
+
15
+ = collapse('change password', card_class: 'my-2') do
16
+ .row
17
+ .col-lg-4= render('admin/learndash_users/form', learndash_user: learndash_user)
12
18
 
13
19
  %p
14
20
  %small Last refreshed #{time_ago_in_words(learndash_user.last_synced_at)} ago.
@@ -13,7 +13,7 @@ module EffectiveLearndash
13
13
 
14
14
  # Include acts_as_addressable concern and allow any ActiveRecord object to call it
15
15
  initializer 'effective_learndash.active_record' do |app|
16
- ActiveSupport.on_load :active_record do
16
+ app.config.to_prepare do
17
17
  ActiveRecord::Base.extend(EffectiveLearndashOwner::Base)
18
18
  ActiveRecord::Base.extend(EffectiveLearndashCourseRegistration::Base)
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveLearndash
2
- VERSION = '0.1.8'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_learndash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-02 00:00:00.000000000 Z
11
+ date: 2022-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails