Compare commits

..

No commits in common. "1e87a923a4e1603c33330991ded0fd9f06bf3b5c" and "9c52af6cc62f05c78e2a9d758f14fde8fa779a73" have entirely different histories.

15 changed files with 77 additions and 59 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.36.1 or greater installed, as well as shards and git.
Verify that you have crystal v0.26.1 or greater installed, as well as shards and git.
### Get the application

View File

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

View File

@ -1,10 +1,10 @@
name: wikicr
version: 0.1.2
version: 0.1.1
authors:
- Arthur Poulet <arthur.poulet@sceptique.eu>
crystal: 0.36.1
crystal: 0.26.1
license: MIT
@ -19,8 +19,9 @@ dependencies:
github: kemalcr/kemal-session
branch: master
kemal-flash:
github: Nephos/kemal-flash
branch: bugfix/update-crystal-json
github: neovintage/kemal-flash
branch: master
#version: 0.1.0
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.local)
set_cookie(name: name, value: "", expires: Time.now)
end
end
end

View File

@ -6,11 +6,15 @@ 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
include YAML::Serializable
# getter name : String
# getter permissions : Hash(String, Acl::Perm)
# property default : Acl::Perm
property name : String
property permissions : Hash(Acl::Path, Acl::Perm)
property default : Acl::Perm
YAML.mapping(
name: String,
permissions: Hash(Acl::Path, Acl::Perm),
default: Acl::Perm
)
# Create a new named Group with optional parameters.
#
@ -101,7 +105,7 @@ class Acl::Group
# Remove the permissions associated to the path
def delete(path : String)
@permissions.reject! { |current_path| current_path.to_s == path }
@permissions.delete_if { |current_path| current_path.to_s == path }
self
end
end

View File

@ -6,10 +6,13 @@ require "./entity"
# The Groups is used to handle a set of uniq `Group`, by *name*.
class Acl::Groups < Lockable
include YAML::Serializable
# @groups : Hash(String, Acl::Group)
# property file : String
property file : String
property groups : Hash(String, Acl::Group)
YAML.mapping(
file: String,
groups: Hash(String, Acl::Group)
)
# ```
# acls = Acl::Groups.new
@ -39,13 +42,15 @@ 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,8 +1,9 @@
class Acl::Path
include YAML::Serializable
property value : String
YAML.mapping(
value: String,
)
@[YAML::Field(key: "regex", ignore: true)]
getter value : String
getter regex : Regex?
def self.value_to_regex(value : String)

View File

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

View File

@ -6,13 +6,14 @@ require "../internal_links"
struct Wikicr::Page
class Index < Lockable
class Entry
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
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,
)
def initialize(@path, @url, @title, toc : Bool = false)
@slug = Entry.title_to_slug title

View File

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

View File

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

View File

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