Compare commits

...

3 Commits

15 changed files with 59 additions and 77 deletions

View File

@ -10,7 +10,7 @@ The pages of the wiki are written in markdown and committed on the git repositor
### Dependencies ### Dependencies
Verify that you have crystal v0.26.1 or greater installed, as well as shards and git. Verify that you have crystal v0.36.1 or greater installed, as well as shards and git.
### Get the application ### Get the application

View File

@ -1,34 +1,34 @@
version: 1.0 version: 2.0
shards: shards:
exception_page: exception_page:
github: crystal-loot/exception_page git: https://github.com/crystal-loot/exception_page.git
version: 0.1.1 version: 0.1.4
kemal: kemal:
github: kemalcr/kemal git: https://github.com/kemalcr/kemal.git
commit: b389022b35202319b59396f30b3cac87fd8d393a version: 0.27.0+git.commit.2d46beea5debefbb836a7e148a8e24452608471b
kemal-flash: kemal-flash:
github: neovintage/kemal-flash git: https://github.com/Nephos/kemal-flash.git
commit: c0eb4e91573322f05ddf602abbfe748c1d2fd184 version: 0.1.0+git.commit.d1ea6ce9caaed840a062e07a9223cc404cf3adc7
kemal-session: kemal-session:
github: kemalcr/kemal-session git: https://github.com/kemalcr/kemal-session.git
commit: b98aec297110f148cfdf0c250810bdcce30aede9 version: 0.13.0+git.commit.51244a899f9004082a5f58fa8fdb4be0eb5bd530
kilt: kilt:
github: jeromegn/kilt git: https://github.com/jeromegn/kilt.git
version: 0.4.0 version: 0.4.0
markd: markd:
github: icyleaf/markd git: https://github.com/icyleaf/markd.git
commit: 69f49f565bb4a015f8745242f6e4daf9b510782d version: 0.3.0+git.commit.5d5087e4c3be46e499966cc493b594b819f64c63
radix: radix:
github: luislavena/radix git: https://github.com/luislavena/radix.git
version: 0.3.8 version: 0.4.0
slang: slang:
github: jeromegn/slang git: https://github.com/jeromegn/slang.git
commit: f33c23be9d477a07627a124d0b79d6cdb7a9132e version: 1.7.2+git.commit.9b41cef0ddf2cd5ba34094742e954570f170c284

View File

@ -1,10 +1,10 @@
name: wikicr name: wikicr
version: 0.1.1 version: 0.1.2
authors: authors:
- Arthur Poulet <arthur.poulet@sceptique.eu> - Arthur Poulet <arthur.poulet@sceptique.eu>
crystal: 0.26.1 crystal: 0.36.1
license: MIT license: MIT
@ -19,9 +19,8 @@ dependencies:
github: kemalcr/kemal-session github: kemalcr/kemal-session
branch: master branch: master
kemal-flash: kemal-flash:
github: neovintage/kemal-flash github: Nephos/kemal-flash
branch: master branch: bugfix/update-crystal-json
#version: 0.1.0
markd: markd:
github: icyleaf/markd github: icyleaf/markd
branch: master branch: master

View File

@ -44,7 +44,7 @@ class AdminController < ApplicationController
perm_str = params.body["perm"] perm_str = params.body["perm"]
perm = Acl::PERM_STR[perm_str] perm = Acl::PERM_STR[perm_str]
Wikicr::ACL.transaction! do |acls| Wikicr::ACL.transaction! do |acls|
acls.add Acl::Group.new group if acls[group]?.nil? acls.add Acl::Group.new(group) if acls[group]?.nil?
acls[group][path] = perm acls[group][path] = perm
end end
flash["success"] = "ACL #{group} :: #{path} :: #{perm} has been added" flash["success"] = "ACL #{group} :: #{path} :: #{perm} has been added"

View File

@ -7,7 +7,7 @@ class ApplicationController
end end
def delete_cookie(name) def delete_cookie(name)
set_cookie(name: name, value: "", expires: Time.now) set_cookie(name: name, value: "", expires: Time.local)
end end
end end
end end

View File

@ -6,15 +6,11 @@ require "./perm"
# It is used by `Groups`. # It is used by `Groups`.
# NOTE: I did not used Hash().new(default) because it is annoying with passing the permissions in the constructor # NOTE: I did not used Hash().new(default) because it is annoying with passing the permissions in the constructor
class Acl::Group class Acl::Group
# getter name : String include YAML::Serializable
# getter permissions : Hash(String, Acl::Perm)
# property default : Acl::Perm
YAML.mapping( property name : String
name: String, property permissions : Hash(Acl::Path, Acl::Perm)
permissions: Hash(Acl::Path, Acl::Perm), property default : Acl::Perm
default: Acl::Perm
)
# Create a new named Group with optional parameters. # Create a new named Group with optional parameters.
# #
@ -105,7 +101,7 @@ class Acl::Group
# Remove the permissions associated to the path # Remove the permissions associated to the path
def delete(path : String) def delete(path : String)
@permissions.delete_if { |current_path| current_path.to_s == path } @permissions.reject! { |current_path| current_path.to_s == path }
self self
end end
end end

View File

@ -6,13 +6,10 @@ require "./entity"
# The Groups is used to handle a set of uniq `Group`, by *name*. # The Groups is used to handle a set of uniq `Group`, by *name*.
class Acl::Groups < Lockable class Acl::Groups < Lockable
# @groups : Hash(String, Acl::Group) include YAML::Serializable
# property file : String
YAML.mapping( property file : String
file: String, property groups : Hash(String, Acl::Group)
groups: Hash(String, Acl::Group)
)
# ``` # ```
# acls = Acl::Groups.new # acls = Acl::Groups.new
@ -42,15 +39,13 @@ class Acl::Groups < Lockable
end end
def self.read(file : String) def self.read(file : String)
Acl::Groups.from_yaml(File.read file) Acl::Groups.from_yaml File.read(file)
end end
# Check if an `Entity` has a group with the required permissions to operate. # Check if an `Entity` has a group with the required permissions to operate.
# #
# ``` # ```
# acls = Groups.new ... # acls = Groups.new...user = User.new...acls.permitted?(user, "/my/path", Perm::Read)
# user = User.new ...
# acls.permitted?(user, "/my/path", Perm::Read)
# ``` # ```
def permitted?(entity : Acl::Entity, path : String, access : Acl::Perm) def permitted?(entity : Acl::Entity, path : String, access : Acl::Perm)
entity.groups.any? do |group| entity.groups.any? do |group|

View File

@ -1,9 +1,8 @@
class Acl::Path class Acl::Path
YAML.mapping( include YAML::Serializable
value: String, property value : String
)
getter value : String @[YAML::Field(key: "regex", ignore: true)]
getter regex : Regex? getter regex : Regex?
def self.value_to_regex(value : String) def self.value_to_regex(value : String)

View File

@ -5,6 +5,7 @@ abstract class Lockable
abstract def load! abstract def load!
abstract def save! abstract def save!
@[YAML::Field(key: "lock", ignore: true)]
@lock : Mutex = Mutex.new @lock : Mutex = Mutex.new
# Execute some operation on the object, and then save it. # Execute some operation on the object, and then save it.

View File

@ -52,7 +52,7 @@ struct Wikicr::Page
end end
def self.sanitize(url : String) def self.sanitize(url : String)
Index::Entry.title_to_slug URI.unescape(url) Index::Entry.title_to_slug URI.decode_www_form(url)
end end
def read_title! def read_title!
@ -141,7 +141,7 @@ struct Wikicr::Page
begin begin
Dir.cd Wikicr::OPTIONS.basedir Dir.cd Wikicr::OPTIONS.basedir
puts `git add -- #{@path}` puts `git add -- #{@path}`
puts `git commit --no-gpg-sign --author \"#{user.name} <#{user.name}@localhost>\" -m \"#{message} #{@url}\" -- #{@path} #{other_files.join(" ")}` puts `git commit --no-gpg-sign --author "#{user.name} <#{user.name}@localhost>" -m "#{message} #{@url}" -- #{@path} #{other_files.join(" ")}`
ensure ensure
Dir.cd dir Dir.cd dir
end end

View File

@ -6,10 +6,9 @@ require "./index/entry"
# like related url, the title, the table of content, ... # like related url, the title, the table of content, ...
struct Wikicr::Page struct Wikicr::Page
class Index < Lockable class Index < Lockable
YAML.mapping( include YAML::Serializable
file: String, property file : String
entries: Hash(String, Entry) # path, entry property entries : Hash(String, Entry) # path, entry
)
def initialize(@file : String) def initialize(@file : String)
@entries = {} of String => Entry @entries = {} of String => Entry

View File

@ -6,14 +6,13 @@ require "../internal_links"
struct Wikicr::Page struct Wikicr::Page
class Index < Lockable class Index < Lockable
class Entry class Entry
YAML.mapping( include YAML::Serializable
path: String, # path of the file /srv/wiki/data/xxx property path : String # path of the file /srv/wiki/data/xxx
url: String, # real url of the page /pages/xxx property url : String # real url of the page /pages/xxx
title: String, # Any title property title : String # Any title
slug: String, # Exact matching title property slug : String # Exact matching title
toc: Page::TableOfContent::Toc, property toc : Page::TableOfContent::Toc
intlinks: Page::InternalLinks::LinkList, property intlinks : Page::InternalLinks::LinkList
)
def initialize(@path, @url, @title, toc : Bool = false) def initialize(@path, @url, @title, toc : Bool = false)
@slug = Entry.title_to_slug title @slug = Entry.title_to_slug title

View File

@ -9,16 +9,11 @@ class Wikicr::User
class Invalid < Exception class Invalid < Exception
end end
# getter name : String include YAML::Serializable
# getter password : String property name : String
# getter groups : Array(String) property password : String
property groups : Array(String)
YAML.mapping( property token : String?
name: String,
password: String,
groups: Array(String),
token: String?,
)
# ``` # ```
# User.new "admin", "password", %w(admin user) # User.new "admin", "password", %w(admin user)

View File

@ -15,11 +15,10 @@ class Wikicr::Users < Lockable
# getter default : User? # getter default : User?
# @list : Hash(String, User) # @list : Hash(String, User)
YAML.mapping( include YAML::Serializable
file: String, property file : String
default: User?, property default : User?
list: Hash(String, User) property list : Hash(String, User)
)
def initialize(@file, @default : User? = nil) def initialize(@file, @default : User? = nil)
@list = {} of String => User @list = {} of String => User

View File

@ -1,4 +1,4 @@
require "markdown" require "markd"
require "yaml" require "yaml"
require "kemal" require "kemal"
require "kemal-session" require "kemal-session"