discourse_task 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +3 -0
- data/lib/discourse_task.rb +4 -0
- data/lib/discourse_task/engine.rb +20 -0
- data/lib/discourse_task/plugin.rb +92 -0
- data/lib/discourse_task/version.rb +3 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6c93d042a2361aa1d6247c1b552401de8dcbbe1
|
4
|
+
data.tar.gz: 0e42c9f36d214dd65b87e078dc920dbfe662e893
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6de12f42b6047ae51fd454dd6e3ba34b34a97b3c9a373ab053c56da80d2ce31f028a46095e44c4de6c40a8e8eea77a5185148def25cf2f0150f3f1eff1bef99f
|
7
|
+
data.tar.gz: c8ed27275a08a5c6042a750a3dd43cf43f06caf4931ec1f540d19fbc8d9a08144686020c5836cddc0311c8e8056e62018af9a31ed1b664057120839c5a9ef6c0
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Robin Ward
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'discourse_task/plugin'
|
2
|
+
|
3
|
+
module DiscourseTask
|
4
|
+
class Engine < Rails::Engine
|
5
|
+
|
6
|
+
engine_name 'discourse_task'
|
7
|
+
|
8
|
+
initializer "discourse_task.configure_rails_initialization" do |app|
|
9
|
+
|
10
|
+
app.config.after_initialize do
|
11
|
+
DiscoursePluginRegistry.setup(DiscourseTask::Plugin)
|
12
|
+
end
|
13
|
+
|
14
|
+
app.config.to_prepare do
|
15
|
+
DiscourseTask::Plugin.include_mixins
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'discourse_plugin'
|
2
|
+
|
3
|
+
module DiscourseTask
|
4
|
+
|
5
|
+
class Plugin < DiscoursePlugin
|
6
|
+
|
7
|
+
def self.archetype
|
8
|
+
'task'
|
9
|
+
end
|
10
|
+
|
11
|
+
def setup
|
12
|
+
# Add our Assets
|
13
|
+
register_js('discourse_task')
|
14
|
+
register_css('discourse_task')
|
15
|
+
|
16
|
+
# Add the archetype
|
17
|
+
register_archetype(DiscourseTask::Plugin.archetype)
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
module TopicViewSerializerMixin
|
22
|
+
def self.included(base)
|
23
|
+
base.attributes :can_complete_task, :complete, :completed_at
|
24
|
+
end
|
25
|
+
|
26
|
+
def can_complete_task
|
27
|
+
scope.can_complete_task?(object.topic)
|
28
|
+
end
|
29
|
+
|
30
|
+
def complete
|
31
|
+
object.topic.has_meta_data_boolean?(:complete)
|
32
|
+
end
|
33
|
+
|
34
|
+
def completed_at
|
35
|
+
dt = Date.parse(object.topic.meta_data_string(:completed_at)).strftime("%d %b, %Y")
|
36
|
+
end
|
37
|
+
def include_completed_at?
|
38
|
+
object.topic.meta_data_string(:completed_at).present?
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
module GuardianMixin
|
44
|
+
|
45
|
+
# We need to be able to determine if a user can complete a task
|
46
|
+
def can_complete_task?(topic)
|
47
|
+
return false if @user.blank?
|
48
|
+
return false if topic.blank?
|
49
|
+
return false unless topic.archetype == DiscourseTask::Plugin.archetype
|
50
|
+
return true if @user.moderator?
|
51
|
+
return true if @user.admin?
|
52
|
+
|
53
|
+
# The OP can complete the topic
|
54
|
+
return @user == topic.user
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
module TopicsControllerMixin
|
60
|
+
|
61
|
+
def complete
|
62
|
+
topic = Topic.where(id: params[:topic_id]).first
|
63
|
+
guardian.ensure_can_complete_task!(topic)
|
64
|
+
|
65
|
+
Topic.transaction do
|
66
|
+
if params[:complete] == 'true'
|
67
|
+
topic.update_meta_data(complete: true, completed_at: Time.now)
|
68
|
+
topic.add_moderator_post(current_user, I18n.t(:'task.completed'))
|
69
|
+
else
|
70
|
+
topic.update_meta_data(complete: false)
|
71
|
+
topic.add_moderator_post(current_user, I18n.t(:'task.reversed'))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
render nothing: true
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
module TopicListItemSerializerMixin
|
81
|
+
def self.included(base)
|
82
|
+
base.attributes :complete
|
83
|
+
end
|
84
|
+
|
85
|
+
def complete
|
86
|
+
object.has_meta_data_boolean?(:complete)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: discourse_task
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robin Ward
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This gem add a Task archetype to discourse that can be closed
|
14
|
+
email:
|
15
|
+
- robin.ward@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- LICENSE
|
21
|
+
- README.md
|
22
|
+
- lib/discourse_task.rb
|
23
|
+
- lib/discourse_task/engine.rb
|
24
|
+
- lib/discourse_task/plugin.rb
|
25
|
+
- lib/discourse_task/version.rb
|
26
|
+
homepage: ''
|
27
|
+
licenses: []
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.2.0
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: This gem add a Task archetype to discourse that can be closed
|
49
|
+
test_files: []
|
50
|
+
has_rdoc:
|