FEATURE: rake task to bulk grant badge to members of a group

FEATURE: rake task to bulk grant badge to members of a group

diff --git a/lib/tasks/groups.rake b/lib/tasks/groups.rake
new file mode 100644
index 0000000..b0d6bf1
--- /dev/null
+++ b/lib/tasks/groups.rake
@@ -0,0 +1,29 @@
+# bulk grant badge to members of a specific group
+task "groups:grant_badge", [:group_id, :badge_id] => [:environment] do |_, args|
+  group_id = args[:group_id]
+  badge_id = args[:badge_id]
+
+  if !group_id || !badge_id
+    puts "ERROR: Expecting groups:grant_badge[group_id,badge_id]"
+    exit 1
+  end
+
+  group = Group.find(group_id)
+  badge = Badge.find(badge_id)
+
+  if group.present? && badge.present?
+    puts "Granting badge '#{badge.name}' to all users in group '#{group.name}'..."
+
+    count = 0
+    group.users.each do |user|
+      begin
+        BadgeGranter.grant(badge, user)
+      rescue => e
+        puts "", "Failed to grant badge to #{user.username}", e, e.backtrace.join("\n")
+      end
+      putc "." if (count += 1) % 5 == 0
+    end
+  end
+
+  puts "", "Done! Badge granted to #{count} members.", ""
+end

GitHub sha: 6ba91403

Fix incorrect condition in `groups:grant_badge` rake task.