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
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

View File

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

View File

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

View File

@ -44,7 +44,7 @@ class AdminController < ApplicationController
perm_str = params.body["perm"]
perm = Acl::PERM_STR[perm_str]
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
end
flash["success"] = "ACL #{group} :: #{path} :: #{perm} has been added"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -52,7 +52,7 @@ struct Wikicr::Page
end
def self.sanitize(url : String)
Index::Entry.title_to_slug URI.unescape(url)
Index::Entry.title_to_slug URI.decode_www_form(url)
end
def read_title!
@ -141,7 +141,7 @@ struct Wikicr::Page
begin
Dir.cd Wikicr::OPTIONS.basedir
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
Dir.cd dir
end

View File

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

View File

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

View File

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

View File

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

View File

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