qalam_merit 4.5.04 → 4.5.09

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: 140a8d032105ba04f4aa8437a96c11a3dfb16d8a0f69f0d8f35ffba23fed32cc
4
- data.tar.gz: 19c14cbe7e3bd1b43ad3a40bd708fb1c4b987200ec6644286b069cc3d69c7384
3
+ metadata.gz: 54fd36c8d0594e5288774e2caf5b4bca4b642e63fefd50d564b80ce5abdbaae0
4
+ data.tar.gz: 7bf97cb6b288354c70bf82f2573d37db6b363230309243848ed7335240282e30
5
5
  SHA512:
6
- metadata.gz: 4980b0106912407b27bb599417109b8b8d43da16f97015fbb82fd6ea71be7eef7a740c73ef773bc95dbd7e0a5d168ecbfdc2d9798210f92d90fb61e42a1119e1
7
- data.tar.gz: a851a6488e8b3ae6ab62d431c01f3c1b28f1f138c210a22b8daaab84ac8174654da0378057c91c8fdb2b9d37aa9bd7fa75c84b2ff8abdb808bb5dbdfaddbc86f
6
+ metadata.gz: 0ecdd00a696088ac97a9ed78671f3c3f8a98da81a89d1d722306c4b6c46cd86f3cc8c9262eb09408afaee973a62891ead6f2260b0b2de775c3eacef09c8ea3f8
7
+ data.tar.gz: f04638fd6694a4f0af6aae82d5db77b30263d494f3267530247b161a31f07454275cf6abfa994b783c40ee58370cb0b7f90a691ee4f61981168ae9af937b0b85
@@ -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
@@ -8,8 +8,10 @@ module Merit
8
8
  def inject_merit_content
9
9
  if model_exists?
10
10
  inject_into_class(model_path, class_name, " ### END ###\n\n")
11
- inject_into_class(model_path, class_name, " has_many :created_badges, class_name: 'Merit::Badge'\n")
12
- inject_into_class(model_path, class_name, " belongs_to :sash, foreign_key: 'sash_id', class_name: 'Merit::Sash'\n")
11
+ inject_into_class(model_path, class_name, " has_many :created_badges, class_name: 'Merit::Badge', :dependent => :destroy\n")
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
+ inject_into_class(model_path, class_name, " belongs_to :sash, foreign_key: 'sash_id', class_name: 'Merit::Sash', :dependent => :destroy\n")
13
15
  inject_into_class(model_path, class_name, " has_merit\n")
14
16
  inject_into_class(model_path, class_name, " ### QALAM_MERIT ###\n")
15
17
  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 :root_account_id, presence: true
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: false, length: { maximum: 50 }
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
- # self.image.public_url if self.image
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.shard.activate do
62
- att = Attachment.create_data_attachment(badge, attachment)
63
- badge.image = att
64
- badge.save!
65
- badge
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
@@ -6,6 +6,7 @@ module Merit::Models::ActiveRecord
6
6
  has_many :activity_logs,
7
7
  class_name: 'Merit::ActivityLog',
8
8
  as: :related_change
9
+ belongs_to :course, foreign_key: "course_id", class_name: 'Course'
9
10
 
10
11
  validates_presence_of :badge_id, :sash
11
12
  end
@@ -1,18 +1,24 @@
1
1
  module Merit::Models::ActiveRecord
2
2
  class QalamScore < ActiveRecord::Base
3
3
  self.table_name = :merit_scores
4
- belongs_to :sash
4
+ belongs_to :sash,
5
+ foreign_key: "sash_id",
6
+ class_name: 'Merit::Sash'
5
7
  has_many :score_points,
6
- dependent: :destroy,
7
- class_name: 'Merit::QalamScore::Point'
8
+ dependent: :destroy,
9
+ foreign_key: "score_id",
10
+ class_name: 'Merit::QalamScore::Point'
8
11
 
9
12
  def points
10
13
  score_points.group(:score_id).sum(:num_points).values.first || 0
11
14
  end
12
15
 
13
16
  class Point < ActiveRecord::Base
14
- belongs_to :score, foreign_key: "score_id", class_name: 'Merit::QalamScore'
15
- has_one :sash, through: :score
17
+ self.table_name = :merit_score_points
18
+ belongs_to :score,
19
+ foreign_key: "score_id",
20
+ class_name: 'Merit::QalamScore'
21
+ has_one :sash, through: :score, source: :sash
16
22
  has_many :activity_logs,
17
23
  class_name: 'Merit::ActivityLog',
18
24
  as: :related_change
@@ -8,14 +8,22 @@ module Merit::Models
8
8
  badges_sashes.map(&:badge_id)
9
9
  end
10
10
 
11
- def add_badge(badge_id)
12
- bs = Merit::BadgesSash.new(badge_id: badge_id.to_i)
13
- badges_sashes << bs
14
- bs
11
+ def add_badge(badge_id, options = {})
12
+ if (course_id = options[:course_id])
13
+ bs = Merit::BadgesSash.new(badge_id: badge_id.to_i, course_id: course_id.to_i)
14
+ else
15
+ bs = Merit::BadgesSash.new(badge_id: badge_id.to_i)
16
+ end
17
+ badges_sashes << bs
18
+ bs
15
19
  end
16
20
 
17
- def rm_badge(badge_id)
18
- badges_sashes.where(badge_id: badge_id.to_i).first.try(:destroy)
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
19
27
  end
20
28
 
21
29
  # Retrieve the number of points from a category
@@ -33,10 +41,11 @@ module Merit::Models
33
41
  def add_points(num_points, options = {})
34
42
  point = Merit::QalamScore::Point.new
35
43
  point.num_points = num_points
44
+ point.course_id = options[:course_id].to_i
36
45
  scores
37
- .where(category: options[:category] || 'default')
38
- .first_or_create
39
- .score_points << point
46
+ .where(category: options[:category] || 'default')
47
+ .first_or_create
48
+ .score_points << point
40
49
  point
41
50
  end
42
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.04'
10
- s.authors = ["Tute Costa", "Ahmed Abdelhamid"]
11
- s.email = ['tutecosta@gmail.com', 'a.hamid@nezam.io']
9
+ s.version = '4.5.09'
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.04
4
+ version: 4.5.09
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-02-28 00:00:00.000000000 Z
12
+ date: 2021-03-08 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: []