qalam_merit 4.5.06 → 4.5.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/merit/class_methods.rb +1 -1
- data/lib/merit/generators/active_record/templates/create_merit_badges.erb +0 -1
- data/lib/merit/generators/merit_generator.rb +9 -1
- data/lib/merit/generators/templates/badge.erb +36 -15
- data/lib/merit/models/active_record/qalam_score.rb +3 -0
- data/lib/merit/models/active_record/sash.rb +2 -0
- data/lib/merit/models/sash_concern.rb +10 -12
- data/qalam_merit.gemspec +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: deec567df823559e660d23204391e9552705a649f57201eb79d30e21d5be727f
|
4
|
+
data.tar.gz: 7e1bb67952c7ec3cc5f00e8649b59b1526a5099590b22d51240af7af54f21652
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6a50d73f6e1cad5dbfd5658874fa1412f41abf2543aec1659ea0aaf5a67627935601abd5a9726544545402222d074d857f9b162c19a8efc333dce60079442de
|
7
|
+
data.tar.gz: 3758d8266ea7dea46c9a7282e314569f4cdbb7421486255ad26a0f245be880a4acef9eb66d04c4f6b311c3e60a353b0af70e5198005683c8cc41bf78b895e83a
|
data/lib/merit/class_methods.rb
CHANGED
@@ -16,7 +16,7 @@ module Merit
|
|
16
16
|
|
17
17
|
# Delegate methods from meritable models to their sash
|
18
18
|
def _merit_delegate_methods_to_sash
|
19
|
-
methods = %w(badge_ids badges points add_badge
|
19
|
+
methods = %w(badge_ids badges points add_badge rm_badge
|
20
20
|
add_points subtract_points score_points)
|
21
21
|
methods.each { |method| delegate method, to: :_sash }
|
22
22
|
end
|
@@ -9,7 +9,6 @@ class CreateMeritBadges < ActiveRecord::Migration<%= migration_version %>
|
|
9
9
|
t.string :difficulty
|
10
10
|
t.boolean :active, default: true
|
11
11
|
t.references :user, limit: 8, foreign_key: true, index: true, null: true
|
12
|
-
t.references :root_account, foreign_key: { to_table: 'accounts'}, limit: 8, null: false, index: true
|
13
12
|
|
14
13
|
t.timestamps
|
15
14
|
end
|
@@ -10,10 +10,14 @@ module Merit
|
|
10
10
|
inject_into_class(model_path, class_name, " ### END ###\n\n")
|
11
11
|
inject_into_class(model_path, class_name, " has_many :created_badges, class_name: 'Merit::Badge', :dependent => :destroy\n")
|
12
12
|
inject_into_class(model_path, class_name, " has_many :assigned_badges, through: :sash, source: :badges, :dependent => :destroy\n")
|
13
|
-
inject_into_class(model_path, class_name, " has_many :badges_sashes, through: :sash, source: :badges_sashes, :dependent => :destroy\n")
|
14
13
|
inject_into_class(model_path, class_name, " belongs_to :sash, foreign_key: 'sash_id', class_name: 'Merit::Sash', :dependent => :destroy\n")
|
15
14
|
inject_into_class(model_path, class_name, " has_merit\n")
|
16
15
|
inject_into_class(model_path, class_name, " ### QALAM_MERIT ###\n")
|
16
|
+
|
17
|
+
inject_into_class(course_path, "Course", " ### END ###\n\n")
|
18
|
+
inject_into_class(course_path, "Course", " has_many :badges_sashes, class_name: 'Merit::BadgesSash', dependent: :destroy\n")
|
19
|
+
inject_into_class(course_path, "Course", " has_many :score_points, class_name: 'Merit::QalamScore::Point', dependent: :destroy\n")
|
20
|
+
inject_into_class(course_path, "Course", " ### QALAM_MERIT ###\n")
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
@@ -30,6 +34,10 @@ module Merit
|
|
30
34
|
def model_path
|
31
35
|
@model_path ||= File.join('app', 'models', "#{file_path}.rb")
|
32
36
|
end
|
37
|
+
|
38
|
+
def course_path
|
39
|
+
@course_path ||= File.join('app', 'models', "course.rb")
|
40
|
+
end
|
33
41
|
end
|
34
42
|
end
|
35
43
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
### QALAM_MERIT ###
|
2
2
|
class Merit::Badge < ActiveRecord::Base
|
3
|
+
# include Workflow
|
4
|
+
# include Context
|
3
5
|
self.table_name = "merit_badges"
|
6
|
+
@valid_images = ["image/jpeg", "image/png", "image/bmp", "image/jpg"]
|
4
7
|
|
5
8
|
before_validation :strip_whitespace
|
6
9
|
def strip_whitespace
|
@@ -8,19 +11,27 @@ class Merit::Badge < ActiveRecord::Base
|
|
8
11
|
self.description = self.description.strip unless self.description.nil?
|
9
12
|
end
|
10
13
|
|
11
|
-
validates :
|
12
|
-
validates :name, presence: true, length: { minimum: 3, maximum: 10 }
|
14
|
+
validates :name, presence: true, length: { minimum: 1, maximum: 20 }
|
13
15
|
validates :points, presence: true, numericality: true, :inclusion => 1..100
|
14
|
-
validates :description, presence:
|
16
|
+
validates :description, presence: true, length: { minimum: 3, maximum: 100 }
|
15
17
|
|
16
18
|
has_one :image, :class_name => 'Attachment', :as => :context, :inverse_of => :context, :dependent => :destroy
|
17
|
-
belongs_to :root_account, foreign_key: "root_account_id", class_name: 'Account'
|
18
19
|
belongs_to :created_by, foreign_key: "user_id", class_name: 'User'
|
19
|
-
has_many :badges_sashes, class_name: 'Merit::QalamBadgeSash'
|
20
|
-
has_many :sashes, through: :badges_sashes, source: :sash
|
21
20
|
|
22
21
|
def image_url
|
23
|
-
|
22
|
+
if self.image
|
23
|
+
return self.image.public_url
|
24
|
+
else
|
25
|
+
return '/images/apple-touch-icon.png'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.valid_images
|
30
|
+
@valid_images
|
31
|
+
end
|
32
|
+
|
33
|
+
def badges_sashes
|
34
|
+
Merit::BadgesSash.where(badge_id: self.id)
|
24
35
|
end
|
25
36
|
|
26
37
|
class << self
|
@@ -47,9 +58,6 @@ class Merit::Badge < ActiveRecord::Base
|
|
47
58
|
badge
|
48
59
|
end
|
49
60
|
|
50
|
-
# Defines Badge#meritable_models method, to get related
|
51
|
-
# entries with certain badge. For instance, Badge.find(3).users
|
52
|
-
# orm-specified
|
53
61
|
def _define_related_entries_method(meritable_class_name)
|
54
62
|
define_method(:"#{meritable_class_name.underscore.pluralize}") do
|
55
63
|
sashes = Merit::QalamBadgeSash.where(badge_id: id).pluck(:sash_id)
|
@@ -58,11 +66,24 @@ class Merit::Badge < ActiveRecord::Base
|
|
58
66
|
end
|
59
67
|
|
60
68
|
def create_with_attachment(account, badge, attachment)
|
61
|
-
account.
|
62
|
-
|
63
|
-
badge.
|
64
|
-
|
65
|
-
|
69
|
+
if ((attachment.nil? || attachment.to_s == "null") || account.nil? || badge.nil?)
|
70
|
+
badge.errors.add(:image, :image_required, message: 'Image Required')
|
71
|
+
badge.destroy if badge.id
|
72
|
+
return false
|
73
|
+
end
|
74
|
+
|
75
|
+
if attachment.content_type && @valid_images.include?(attachment.content_type)
|
76
|
+
account.shard.activate do
|
77
|
+
att = Attachment.create_data_attachment(badge, attachment)
|
78
|
+
badge.image = att
|
79
|
+
badge.save!
|
80
|
+
badge
|
81
|
+
end
|
82
|
+
return true
|
83
|
+
else
|
84
|
+
badge.errors.add(:image, :invalid_format, message: 'invalid image format')
|
85
|
+
badge.destroy if badge.id
|
86
|
+
return false
|
66
87
|
end
|
67
88
|
end
|
68
89
|
end
|
@@ -12,6 +12,8 @@ module Merit::Models::ActiveRecord
|
|
12
12
|
has_many :badges_sashes, dependent: :destroy
|
13
13
|
has_many :badges, through: :badges_sashes, source: :badge
|
14
14
|
has_many :scores, dependent: :destroy, class_name: 'Merit::QalamScore'
|
15
|
+
has_many :score_points, through: :scores, source: :badge
|
16
|
+
|
15
17
|
|
16
18
|
after_create :create_scores
|
17
19
|
|
@@ -18,17 +18,14 @@ module Merit::Models
|
|
18
18
|
bs
|
19
19
|
end
|
20
20
|
|
21
|
-
def rm_badge(badge_id)
|
22
|
-
|
21
|
+
def rm_badge(badge_id, options = {})
|
22
|
+
if (course_id = options[:course_id])
|
23
|
+
badges_sashes.where(badge_id: badge_id.to_i, course_id: course_id.to_i).first.try(:destroy)
|
24
|
+
else
|
25
|
+
badges_sashes.where(badge_id: badge_id.to_i).first.try(:destroy)
|
26
|
+
end
|
23
27
|
end
|
24
28
|
|
25
|
-
########################QALAM_DEV#########################
|
26
|
-
def add_qalam_badge(badge_id, course_id)
|
27
|
-
bs = Merit::BadgesSash.new(badge_id: badge_id.to_i, course_id: course_id.to_i)
|
28
|
-
badges_sashes << bs
|
29
|
-
bs
|
30
|
-
end
|
31
|
-
########################END###################################
|
32
29
|
# Retrieve the number of points from a category
|
33
30
|
# By default all points are summed up
|
34
31
|
# @param category [String] The category
|
@@ -44,10 +41,11 @@ module Merit::Models
|
|
44
41
|
def add_points(num_points, options = {})
|
45
42
|
point = Merit::QalamScore::Point.new
|
46
43
|
point.num_points = num_points
|
44
|
+
point.course_id = options[:course_id].to_i
|
47
45
|
scores
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
.where(category: options[:category] || 'default')
|
47
|
+
.first_or_create
|
48
|
+
.score_points << point
|
51
49
|
point
|
52
50
|
end
|
53
51
|
|
data/qalam_merit.gemspec
CHANGED
@@ -6,9 +6,9 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.files = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
|
7
7
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
8
8
|
s.license = 'MIT'
|
9
|
-
s.version = '4.5.
|
10
|
-
s.authors = ["
|
11
|
-
s.email = ['
|
9
|
+
s.version = '4.5.11'
|
10
|
+
s.authors = ["Ahmed Abdelhamid", "Zeyad Saleh"]
|
11
|
+
s.email = ['a.hamid@nezam.io', 'zeyad.saleh@nezam.io']
|
12
12
|
|
13
13
|
s.required_ruby_version = '>= 2.3.0'
|
14
14
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qalam_merit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.5.
|
4
|
+
version: 4.5.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Tute Costa
|
8
7
|
- Ahmed Abdelhamid
|
8
|
+
- Zeyad Saleh
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-03-
|
12
|
+
date: 2021-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: zeitwerk
|
@@ -111,8 +111,8 @@ dependencies:
|
|
111
111
|
version: '0'
|
112
112
|
description: Manage badges, points and rankings (reputation) in your Rails app.
|
113
113
|
email:
|
114
|
-
- tutecosta@gmail.com
|
115
114
|
- a.hamid@nezam.io
|
115
|
+
- zeyad.saleh@nezam.io
|
116
116
|
executables: []
|
117
117
|
extensions: []
|
118
118
|
extra_rdoc_files: []
|