qalam_merit 4.5.05 → 4.5.10

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: 36dd98bb62a667ae5b42ca9edb1a6aa9d547a139d268f9da523476937d61d077
4
- data.tar.gz: 3d36fe5887fc5844b4e13f342e73216d7fc8ab1f6d70e1a458437c9b86fd247e
3
+ metadata.gz: a4171f388d1deb5ba55ac7d6c2da00ff1612b6b11ab9006131231097315dbb71
4
+ data.tar.gz: 11fa7b017b5bb9762a292b6bb6250895cbe2a98dd8c88e675260ebc68439a63c
5
5
  SHA512:
6
- metadata.gz: b797616130749f3f74ad7b2737dc32461866896547f32f9039d56474f309d20a07113a42f0fa3dd0af105450b511455ff4b769a517d5656885cdfc56194c6780
7
- data.tar.gz: 26bc8ce7e1adcee901aaa6f929a0e89d73d22b7088c30cc5321c1369ca4528593417a48336ff6e31b5c03d94505adc6df3701a92bd9f825e1828db0da6d3638b
6
+ metadata.gz: 98f2e9d35284ebcd1d0b43afc46082407ec04aa1f8645e4de50f45d17f6f0ba278e01b3f0fcc58853b848e507c2b087e7b6bd3ab29a78dd9be08c7a2dde5a634
7
+ data.tar.gz: d9b4e7bda1c8dda2c012b2cda57e2d7f9408c02dec0a4b51fc97cd626971e6d1046889c34e5ee6ac5f0d8e9a70c638feb2d6ba783117588d7f2acd3194a448c0
@@ -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
@@ -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
@@ -23,6 +23,9 @@ module Merit::Models::ActiveRecord
23
23
  class_name: 'Merit::ActivityLog',
24
24
  as: :related_change
25
25
  delegate :sash_id, to: :score
26
+ belongs_to :course,
27
+ foreign_key: "course_id",
28
+ class_name: 'Course'
26
29
  end
27
30
  end
28
31
  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
 
@@ -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.05'
10
- s.authors = ["Tute Costa", "Ahmed Abdelhamid"]
11
- s.email = ['tutecosta@gmail.com', 'a.hamid@nezam.io']
9
+ s.version = '4.5.10'
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.05
4
+ version: 4.5.10
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-01 00:00:00.000000000 Z
12
+ date: 2021-03-10 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: []