effective_learndash 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47f234d26d444d3ba71d72409db15186e4b1db00e1bf3c6aa007853143307265
4
- data.tar.gz: d97eea26d3a6cce1d8df2f154b06b8dbc558e8df8c731fdbff268185cb3d465c
3
+ metadata.gz: 0c988c1953adabbfc3e8bac44c28a11575423e93ffcd216e76c70c8a7045be09
4
+ data.tar.gz: db782e5f5971a1098d3f5268e3218c34341f567971d8159c9a3e431a06f612c2
5
5
  SHA512:
6
- metadata.gz: 6aeaa81878fe93276c6bcdc366ec2f61f1fdc5ee952a6b9328890387619605ddb7883210765f203bef8ae053065c781eb59c109b084b06d164be079ebe7689b8
7
- data.tar.gz: 2d53168beee83ee8766389eaec11b48f6208e97e202d63ba3155f85278357b673ff1fab06de53cf9e8570fb57397ed5cf4cbfb4a2500a870c42691512fe061b8
6
+ metadata.gz: 577324f8a74fbc1622327c97e83efef53bb67aaaf2e506805ac697b25be8ad43a197a6b373d33c1061f0f81ea6526d9123c5e4a7e4eb89ebc44a3a21725c3ada
7
+ data.tar.gz: ca4487a5aec94110d60ec5872d1806d96b1c3ef3fa0111c4c65ab7d6c914ae63008c5fcb44e472485b1548bdd033a1080757926d71b9024534827927e2d8b6d2
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
@@ -2,8 +2,8 @@
2
2
 
3
3
  class EffectiveCourseRegistrantsDatatable < Effective::Datatable
4
4
  datatable do
5
- col :learndash_course
6
- col :owner, label: 'User', action: false
5
+ col :learndash_course, label: 'Title'
6
+ col :owner, label: 'Registrant', action: false
7
7
  col :price, as: :price
8
8
  end
9
9
 
@@ -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.
@@ -1,3 +1,3 @@
1
1
  module EffectiveLearndash
2
- VERSION = '0.1.7'.freeze
2
+ VERSION = '0.2.0'.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.7
4
+ version: 0.2.0
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