* README.md: blanked: not clear enough

* FileSystemController.cs: Fixes the route to user's Files by an
  Admin.

* FileSystemManager.cs: * Fixes the dir separator usage
* Adds a method to validate a directory or file name

* YavscModel.csproj:
* Commande.cs: FileInfoCollection is now removed

* FileInfoCollection.cs:
* DirNotFoundException.cs: Removes useless code
vnext
Paul Schneider 9 years ago
parent 679a249faf
commit 3fa55acf2e
10 changed files with 86 additions and 202 deletions

@ -1,3 +1,7 @@
2015-08-14 Paul Schneider <paul@pschneider.fr>
* README.md: blanked: not clear enough
2015-07-17 Paul Schneider <paul@pschneider.fr>
* Yavsc.sln:

@ -1,31 +1,4 @@
yavsc
=====
Yet Another Very Small Company
For the moment, overall a little home made blogging system.
Le but serait un SI gérant différents type de services, par exemple :
- Dépannage informatique
- Développement logiciel
- Developpement Web
- Audit de sécurité
- Dématérialisation des documents
Les livrables :
- Un site web ASP.Net propulsé par Mono et Apache, et une application mobile pour
* demander un devis
* demander une intervention / saisir un ticket
* avoir un status des projets des clients
* avoir un status des ticket du client
Les commandes : c'est une notion liée à celles
- de catalogue, d'article, d'options
- d'acteurs, de ressources humaines
- d'étapes inter dépendantes, de leurs attributs, de leurs états
- des dates butoires
Voir aussi:
http://yavsc.pschneider.fr/Blogs/UserPost/paul/Documentation
[doc-fr](http://yavsc.pschneider.fr/Blogs/UserPost/paul/Documentation)

@ -1,3 +1,8 @@
2015-08-14 Paul Schneider <paul@pschneider.fr>
* FileSystemController.cs: Fixes the route to user's Files by
an Admin.
2015-08-05 Paul Schneider <paul@pschneider.fr>
* style.css: Gives a margin to the login panel

@ -31,96 +31,37 @@ namespace Yavsc.Controllers
/// Index this instance.
/// </summary>
[Authorize]
public ActionResult Index (string id)
public ActionResult Index (string user, string filename)
{
FileSystemManager fsmgr = new FileSystemManager ();
var files = fsmgr.GetFiles (id);
files.Owner = Membership.GetUser ().UserName;
var files = fsmgr.GetFiles (user,filename);
return View (files);
}
/// <summary>
/// Details the specified id.
/// Post the specified id.
/// </summary>
/// <param name="id">Identifier.</param>
public ActionResult Details (string id)
public ActionResult Post (string id)
{
foreach (char x in Path.GetInvalidPathChars()) {
if (id.Contains (x)) {
ViewData ["Message"] =
string.Format (
"Something went wrong following the following path : {0} (\"{1}\")",
id, x);
return RedirectToAction ("Index");
}
}
FileSystemManager fsmgr = new FileSystemManager ();
FileInfo fi = fsmgr.FileInfo (id);
ViewData ["id"] = id;
// TODO : ensure that we use the default port for
// the used sheme
ViewData ["url"] =
string.Format(
"{0}://{1}/users/{2}/{3}",
Request.Url.Scheme,
Request.Url.Authority,
Membership.GetUser ().UserName ,
id );
return View (fi);
return View ();
}
/// <summary>
/// Create the specified id.
/// Details the specified user and filename.
/// </summary>
/// <param name="id">Identifier.</param>
[HttpPost]
[Authorize]
public ActionResult Create (string id)
/// <param name="user">User.</param>
/// <param name="filename">Filename.</param>
public ActionResult Details (string user, string filename)
{
FileSystemManager fsmgr = new FileSystemManager ();
return View ("Index",fsmgr.GetFiles(id));
}
/// <summary>
/// Edit the specified id.
/// </summary>
/// <param name="id">Identifier.</param>
public ActionResult Edit (int id)
{
throw new NotImplementedException ();
}
/// <summary>
/// Edit the specified id and collection.
/// </summary>
/// <param name="id">Identifier.</param>
/// <param name="collection">Collection.</param>
[HttpPost]
public ActionResult Edit (int id, FormCollection collection)
{
throw new NotImplementedException ();
}
/// <summary>
/// Delete the specified id.
/// </summary>
/// <param name="id">Identifier.</param>
public ActionResult Delete (int id)
{
throw new NotImplementedException ();
}
FileInfo fi = fsmgr.FileInfo (filename);
/// <summary>
/// Delete the specified id and collection.
/// </summary>
/// <param name="id">Identifier.</param>
/// <param name="collection">Collection.</param>
[HttpPost]
public ActionResult Delete (int id, FormCollection collection)
{
throw new NotImplementedException ();
ViewData ["filename"] = filename;
// TODO : ensure that we use the default port for
// the used sheme
ViewData ["url"] = Url.Content("~/users/"+user+"/"+filename);
return View (fi);
}
}
}

@ -1,3 +1,14 @@
2015-08-14 Paul Schneider <paul@pschneider.fr>
* FileSystemManager.cs: * Fixes the dir separator usage
* Adds a method to validate a directory or file name
* YavscModel.csproj:
* Commande.cs: FileInfoCollection is now removed
* FileInfoCollection.cs:
* DirNotFoundException.cs: Removes useless code
2015-08-05 Paul Schneider <paul@pschneider.fr>
* BlogEntryCollection.cs: adds xml doc

@ -1,46 +0,0 @@
//
// DirNotFoundException.cs
//
// Author:
// Paul Schneider <paulschneider@free.fr>
//
// Copyright (c) 2015 Paul Schneider
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.IO;
using System.Web;
using System.Text.RegularExpressions;
using System.Text;
using System.Web.Security;
namespace Yavsc.Model.FileSystem
{
/// <summary>
/// Dir not found exception.
/// </summary>
public class DirNotFoundException : Exception {
/// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Model.FileSystem.DirNotFoundException"/> class.
/// </summary>
/// <param name="dir">Dir.</param>
public DirNotFoundException(string dir)
: base(string.Format( "Directory not found : {0}", dir))
{
}
}
}

@ -1,27 +0,0 @@
using System;
using System.IO;
using System.Collections.Generic;
namespace Yavsc.Model.FileSystem
{
/// <summary>
/// File info collection.
/// </summary>
public class FileInfoCollection: List<FileInfo>
{
/// <summary>
/// Gets or sets the owner.
/// </summary>
/// <value>The owner.</value>
public string Owner { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Model.FileSystem.FileInfoCollection"/> class.
/// </summary>
/// <param name="files">Files.</param>
public FileInfoCollection (FileInfo [] files)
{
AddRange (files);
}
}
}

@ -56,18 +56,37 @@ namespace Yavsc.Model.FileSystem
/// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Model.FileSystem.FileSystemManager"/> class.
/// </summary>
public FileSystemManager (string rootDirectory="~/users/{0}", char dirSep = '/')
public FileSystemManager (string rootDirectory="~/users/{0}")
{
MembershipUser user = Membership.GetUser ();
if (user == null)
throw new Exception ("Not membership available");
Prefix = HttpContext.Current.Server.MapPath (
string.Format (rootDirectory, user.UserName));
DirectorySeparator = dirSep;
}
/// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Model.FileSystem.FileSystemManager"/> class.
/// </summary>
public FileSystemManager (string username, string rootDirectory="~/users/{0}")
{
Prefix = HttpContext.Current.Server.MapPath (
string.Format (rootDirectory, username));
}
string regexFileName = "^[A-Za-z0-9#^!+ _~\\-.]+$";
/// <summary>
/// Determines if the specified name is OK.
/// </summary>
/// <returns><c>true</c> if is this name O the specified name; otherwise, <c>false</c>.</returns>
/// <param name="name">Name.</param>
public static bool IsThisNameOK(string name)
{
foreach (char x in Path.GetInvalidPathChars()) {
if (name.Contains (x))
return false;
}
return true;
}
/// <summary>
/// Put the specified files in destDir, as sub dir of the current user's home dir.
/// </summary>
@ -86,7 +105,7 @@ namespace Yavsc.Model.FileSystem
}
// do the job
checkSubDir (destDir);
CheckSubDir (destDir);
DirectoryInfo di = new DirectoryInfo (
Path.Combine (Prefix, destDir));
if (!di.Exists)
@ -114,45 +133,50 @@ namespace Yavsc.Model.FileSystem
prefix = value;
}
}
/// <summary>
/// Gets or sets the directory name separator.
/// </summary>
/// <value>The separator.</value>
public char DirectorySeparator { get; set; }
/// <summary>
/// Checks the sub dir name.
/// Checks the sub dir name against model specifications,
/// concerning the allowed character class.
/// </summary>
/// <param name="subdir">Subdir.</param>
private void checkSubDir (string subdir)
private void CheckSubDir (string subdir)
{
foreach (string dirname in subdir.Split(DirectorySeparator))
foreach (string dirname in subdir.Split(Path.DirectorySeparatorChar)) {
if (!Regex.Match (dirname, regexFileName).Success)
throw new InvalidDirNameException (dirname);
foreach (char x in Path.GetInvalidPathChars())
foreach (char x in dirname)
if (subdir.Contains (x))
throw new InvalidDirNameException (subdir);
}
}
/// <summary>
/// Gets the files.
/// Gets the files owned by the current logged user.
/// The web user must be authenticated,
/// The given username must be registered.
/// </summary>
/// <returns>The files.</returns>
/// <param name="subdir">Subdir.</param>
public FileInfoCollection GetFiles (string subdir)
public IEnumerable<FileInfo> GetFiles (string subdir)
{
string path = Prefix;
if (subdir != null) {
checkSubDir (subdir); // checks for specification validity
CheckSubDir (subdir); // checks for specification validity
path = Path.Combine (Prefix, subdir);
}
DirectoryInfo di = new DirectoryInfo (path);
FileInfoCollection res = new FileInfoCollection (di.GetFiles ());
// TODO define an Owner
return res;
return (di.GetFiles ());
}
public IEnumerable<FileInfo> GetFiles (string username, string subdir)
{
string path = Prefix;
if (subdir != null) {
CheckSubDir (subdir); // checks for specification validity
path = Path.Combine (Prefix, subdir);
}
DirectoryInfo di = new DirectoryInfo (path);
return (di.GetFiles ());
}
/// <summary>
/// Files the info.
/// </summary>
@ -160,7 +184,7 @@ namespace Yavsc.Model.FileSystem
/// <param name="id">Identifier.</param>
public FileInfo FileInfo(string id)
{
checkSubDir (id);
CheckSubDir (id);
return new FileInfo(Path.Combine (Prefix, id));
}
}

@ -5,6 +5,7 @@ using Yavsc.Model.WorkFlow;
using Yavsc.Model.FileSystem;
using System.Web;
using System.Collections.Generic;
using System.IO;
namespace Yavsc.Model.FrontOffice
@ -43,7 +44,7 @@ namespace Yavsc.Model.FrontOffice
/// </summary>
public Dictionary<string,string> Parameters = new Dictionary<string,string> ();
FileInfoCollection Files {
IEnumerable<FileInfo> Files {
get {
return GetFSM().GetFiles (Id.ToString());
}

@ -46,7 +46,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Admin\RestoreQuery.cs" />
<Compile Include="Admin\DataAccess.cs" />
<Compile Include="FileSystem\FileInfoCollection.cs" />
<Compile Include="WorkFlow\Writting.cs" />
<Compile Include="WorkFlow\Estimate.cs" />
<Compile Include="WorkFlow\IContentProvider.cs" />
@ -113,7 +112,6 @@
<Compile Include="FrontOffice\Catalog\CatalogManager.cs" />
<Compile Include="FrontOffice\Catalog\CatalogProvider.cs" />
<Compile Include="FileSystem\FileSystemManager.cs" />
<Compile Include="FileSystem\DirNotFoundException.cs" />
<Compile Include="FileSystem\InvalidDirNameException.cs" />
<Compile Include="FileSystem\WebFileInfo.cs" />
<Compile Include="FrontOffice\CommandStatus.cs" />

Loading…