1
+ import gitbucket .core .model ._
2
+ import gitbucket .core .service .AccountService
1
3
import gitbucket .core .service .SystemSettingsService .SystemSettings
2
4
import gitbucket .gist .controller .GistController
3
- import gitbucket .core .plugin .PluginRegistry
5
+ import gitbucket .core .plugin ._
4
6
import gitbucket .core .util .Version
5
7
import java .io .File
6
8
import javax .servlet .ServletContext
@@ -15,22 +17,14 @@ class Plugin extends gitbucket.core.plugin.Plugin {
15
17
override val description : String = " Provides Gist feature on GitBucket."
16
18
17
19
override val versions : List [Version ] = List (
20
+ Version (1 , 3 ),
18
21
Version (1 , 2 ),
19
22
Version (1 , 0 )
20
23
)
21
24
22
25
override def initialize (registry : PluginRegistry , context : ServletContext , settings : SystemSettings ): Unit = {
23
26
super .initialize(registry, context, settings)
24
27
25
- // Add Snippet link to the header
26
- val path = settings.baseUrl.getOrElse(context.getContextPath)
27
- registry.addJavaScript(" .*" ,
28
- s """
29
- | $$ ('a.brand').after(
30
- | $$ ('<span style="float: left; margin-top: 10px;">| <a href=" ${path}/gist" style="color: black;">Snippet</a></span>')
31
- |);
32
- """ .stripMargin)
33
-
34
28
// Create gist repository directory
35
29
val rootdir = new File (GistRepoDir )
36
30
if (! rootdir.exists){
@@ -40,16 +34,39 @@ class Plugin extends gitbucket.core.plugin.Plugin {
40
34
println(" -- Gist plug-in initialized --" )
41
35
}
42
36
37
+ override val repositoryRoutings = Seq (
38
+ GitRepositoryRouting (" gist/(.+?)/(.+?)\\ .git" , " gist/$1/$2" , new GistRepositoryFilter ())
39
+ )
40
+
43
41
override val controllers = Seq (
44
42
" /*" -> new GistController ()
45
43
)
46
44
47
- override val images = Seq (
48
- " images/menu-revisions-active.png" -> fromClassPath(" images/menu-revisions-active.png" ),
49
- " images/menu-revisions.png" -> fromClassPath(" images/menu-revisions.png" ),
50
- " images/snippet.png" -> fromClassPath(" images/snippet.png" )
51
- )
45
+ override def javaScripts (registry : PluginRegistry , context : ServletContext , settings : SystemSettings ): Seq [(String , String )] = {
46
+ // Add Snippet link to the header
47
+ val path = settings.baseUrl.getOrElse(context.getContextPath)
48
+ Seq (
49
+ " .*" -> s """
50
+ | $$ ('a.global-header-menu:last').after(
51
+ | $$ ('<a href=" ${path}/gist" class="global-header-menu">Gist</a>')
52
+ |);
53
+ """ .stripMargin
54
+ )
55
+ }
56
+ }
57
+
58
+ class GistRepositoryFilter extends GitRepositoryFilter with AccountService {
52
59
53
- override def shutdown (registry : PluginRegistry , context : ServletContext , settings : SystemSettings ): Unit = {
60
+ override def filter (path : String , userName : Option [String ], settings : SystemSettings , isUpdating : Boolean )
61
+ (implicit session : Session ): Boolean = {
62
+ if (isUpdating){
63
+ (for {
64
+ userName <- userName
65
+ account <- getAccountByUserName(userName)
66
+ } yield
67
+ path.startsWith(" /" + userName + " /" ) || account.isAdmin
68
+ ).getOrElse(false )
69
+ } else true
54
70
}
71
+
55
72
}
0 commit comments