Merge from booking branch

This commit is contained in:
Paul Schneider 2015-11-17 22:22:59 +01:00
commit 9a2652739b
266 changed files with 12833 additions and 2337 deletions

View file

@ -335,6 +335,7 @@ namespace Yavsc.Controllers
prf.SetPropertyValue ("AccountNumber", model.AccountNumber);
prf.SetPropertyValue ("BankedKey", model.BankedKey);
prf.SetPropertyValue ("gcalid", model.GoogleCalendar);
prf.SetPropertyValue ("UITheme", model.UITheme);
prf.Save ();
if (editsTheUserName) {

View file

@ -25,9 +25,9 @@ namespace Yavsc.Controllers
public ActionResult Index()
{
// FIXME do this in a new installation script.
if (!Roles.RoleExists (roleName)) {
Roles.CreateRole (roleName);
YavscHelpers.Notify (ViewData, roleName + " " + LocalizedText.role_created);
if (!Roles.RoleExists (_adminRoleName)) {
Roles.CreateRole (_adminRoleName);
YavscHelpers.Notify (ViewData, _adminRoleName + " " + LocalizedText.role_created);
}
return View ();
}
@ -156,6 +156,13 @@ namespace Yavsc.Controllers
Roles.RemoveUserFromRole(username,rolename);
return Redirect(returnUrl);
}
[Authorize(Roles="Admin")]
public ActionResult AddUserToRole(string username, string rolename, string returnUrl)
{
Roles.AddUsersToRole(new string[] { username } ,rolename);
return Redirect(returnUrl);
}
/// <summary>
/// Removes the user.
/// </summary>
@ -223,7 +230,27 @@ namespace Yavsc.Controllers
MembershipUserCollection c = Membership.GetAllUsers ();
return View (c);
}
[Authorize()]
public ActionResult UsersInRole (string rolename)
{
if (rolename == null)
rolename = "Admin";
ViewData ["RoleName"] = rolename;
ViewData ["Roles"] = Roles.GetAllRoles ();
ViewData ["UsersInRole"] = Roles.GetUsersInRole (rolename);
return View ();
}
[Authorize()]
public ActionResult UserRoles (string username)
{
ViewData ["AllRoles"] = Roles.GetAllRoles ();
if (username == null)
username = User.Identity.Name;
ViewData ["UserName"] = username;
ViewData ["UsersRoles"] = Roles.GetRolesForUser (username);
return View ();
}
/// <summary>
/// a form to add a role
/// </summary>
@ -257,7 +284,7 @@ namespace Yavsc.Controllers
return View (Roles.GetAllRoles ());
}
private const string roleName = "Admin";
private const string _adminRoleName = "Admin";
/// <summary>
/// Assing the Admin role to the specified user in model.
@ -267,7 +294,7 @@ namespace Yavsc.Controllers
public ActionResult Admin (NewAdminModel model)
{
// ASSERT (Roles.RoleExists (adminRoleName))
string [] admins = Roles.GetUsersInRole (roleName);
string [] admins = Roles.GetUsersInRole (_adminRoleName);
string currentUser = Membership.GetUser ().UserName;
List<SelectListItem> users = new List<SelectListItem> ();
foreach (MembershipUser u in Membership.GetAllUsers ()) {
@ -279,22 +306,21 @@ namespace Yavsc.Controllers
ViewData ["admins"] = admins;
ViewData ["useritems"] = users;
if (ModelState.IsValid) {
Roles.AddUserToRole (model.UserName, roleName);
YavscHelpers.Notify(ViewData, model.UserName + " "+LocalizedText.was_added_to_the_role+" '" + roleName + "'");
Roles.AddUserToRole (model.UserName, _adminRoleName);
YavscHelpers.Notify(ViewData, model.UserName + " "+LocalizedText.was_added_to_the_role+" '" + _adminRoleName + "'");
} else {
if (admins.Length > 0) {
if (! admins.Contains (Membership.GetUser ().UserName)) {
ModelState.Remove("UserName");
ModelState.AddModelError("UserName",LocalizedText.younotadmin+"!");
return View ("Index");
}
} else {
// No admin, gives the Admin Role to the current user
Roles.AddUserToRole (currentUser, roleName);
Roles.AddUserToRole (currentUser, _adminRoleName);
admins = new string[] { currentUser };
YavscHelpers.Notify(ViewData, string.Format (
LocalizedText.was_added_to_the_empty_role,
currentUser, roleName));
currentUser, _adminRoleName));
}
}
return View (model);

View file

@ -77,7 +77,6 @@ namespace Yavsc.Controllers
/// <param name="id">Title.</param>
/// <param name="pageIndex">Page index.</param>
/// <param name="pageSize">Page size.</param>
///
[HttpGet]
public ActionResult Title (string title, int pageIndex = 0, int pageSize = 10)
{
@ -89,7 +88,7 @@ namespace Yavsc.Controllers
BlogManager.FindPost (username, title, sf, pageIndex, pageSize, out recordCount);
var utc = new UTBlogEntryCollection (title);
utc.AddRange (c);
ViewData ["RecordCount"] = recordCount;
ViewData ["ResultCount"] = recordCount;
ViewData ["PageIndex"] = pageIndex;
ViewData ["PageSize"] = pageSize;
return View ("Title", utc);
@ -135,8 +134,10 @@ namespace Yavsc.Controllers
ViewData ["BlogTitle"] = bupr.BlogTitle;
ViewData ["Avatar"] = bupr.avatar;
}
ViewData ["RecordCount"] = recordcount;
UUBlogEntryCollection uuc = new UUBlogEntryCollection (user, c);
ViewData ["ResultCount"] = recordcount;
ViewData ["PageIndex"] = pageIndex;
ViewData ["PageSize"] = pageSize;
return View ("UserPosts", uuc);
}
@ -279,8 +280,8 @@ namespace Yavsc.Controllers
/// </summary>
/// <returns>The edit.</returns>
/// <param name="model">Model.</param>
[Authorize(Roles="Blogger")]
public ActionResult ValidateEdit (BlogEntry model)
[Authorize(Roles="")]
public ActionResult Edit (BlogEntry model)
{
ViewData ["SiteName"] = sitename;
ViewData ["Author"] = Membership.GetUser ().UserName;
@ -289,13 +290,13 @@ namespace Yavsc.Controllers
// ensures rights to update
BlogManager.GetForEditing (model.Id, true);
BlogManager.UpdatePost (model.Id, model.Title, model.Content, model.Visible, model.AllowedCircles);
YavscHelpers.Notify (ViewData, LocalizedText.BillUpdated);
}
else
} else {
model.Id = BlogManager.Post (model.Author, model.Title, model.Content, model.Visible, model.AllowedCircles);
if (model.Photo != null)
BlogManager.UpdatePostPhoto (model.Id, model.Photo);
return RedirectToAction ("Title", new { title = model.Title });
YavscHelpers.Notify (ViewData, LocalizedText.BillCreated);
}
BlogManager.UpdatePostPhoto (model.Id, model.Photo);
}
ViewData ["AllowedCircles"] =
CircleManager.DefaultProvider.List (
@ -312,7 +313,7 @@ namespace Yavsc.Controllers
/// </summary>
/// <param name="id">Identifier.</param>
[Authorize(Roles="Blogger")]
public ActionResult Edit (long postid)
public ActionResult EditId (long postid)
{
BlogEntry e = BlogManager.GetForEditing (postid);
@ -333,7 +334,7 @@ namespace Yavsc.Controllers
Text = x.Title,
Selected = e.AllowedCircles.Contains (x.Id)
});
return View (e);
return View ("Edit",e);
}
/// <summary>

View file

@ -16,6 +16,7 @@ using Yavsc.Model.Calendar;
using System.Configuration;
using Yavsc.Helpers;
using Yavsc.Model.FrontOffice.Catalog;
using Yavsc.Model.Skill;
namespace Yavsc.Controllers
{
@ -85,12 +86,12 @@ namespace Yavsc.Controllers
/// Estimate the specified id.
/// </summary>
/// <param name="id">Identifier.</param>
public ActionResult Get (long id)
public ActionResult Get (long estimid)
{
Estimate f = wfmgr.GetEstimate (id);
Estimate f = wfmgr.GetEstimate (estimid);
if (f == null) {
ModelState.AddModelError ("Id", "Wrong Id");
return View (new Estimate () { Id=id } );
return View (new Estimate () { Id=estimid } );
}
return View (f);
}
@ -162,11 +163,11 @@ namespace Yavsc.Controllers
/// Catalog this instance.
/// </summary>
[AcceptVerbs ("GET")]
public ActionResult Brand (string id)
public ActionResult Brand (string brandid)
{
Catalog c = CatalogManager.GetCatalog ();
ViewData ["BrandName"] = id;
return View (c.GetBrand (id));
ViewData ["BrandName"] = brandid;
return View (c.GetBrand (brandid));
}
/// <summary>
@ -200,10 +201,10 @@ namespace Yavsc.Controllers
/// <param name="pc">Pc.</param>
/// <param name="pref">Preference.</param>
[AcceptVerbs ("GET")]
public ActionResult Product (string id, string pc, string pref)
public ActionResult Product (string brandid, string pc, string pref)
{
Product p = null;
ViewData ["BrandName"] = id;
ViewData ["BrandName"] = brandid;
ViewData ["ProdCatRef"] = pc;
ViewData ["ProdRef"] = pref;
Catalog cat = CatalogManager.GetCatalog ();
@ -212,7 +213,7 @@ namespace Yavsc.Controllers
ViewData ["RefType"] = "Catalog";
return View ("ReferenceNotFound");
}
Brand b = cat.GetBrand (id);
Brand b = cat.GetBrand (brandid);
if (b == null) {
ViewData ["RefType"] = "Brand";
return View ("ReferenceNotFound");
@ -259,5 +260,50 @@ namespace Yavsc.Controllers
}
}
/// <summary>
/// Booking the specified model.
/// </summary>
/// <param name="model">Model.</param>
public ActionResult Booking (BookingQuery model)
{
return View ();
}
/// <summary>
/// Skills the specified model.
/// </summary>
[Authorize(Roles="Admin")]
public ActionResult Skills (string search)
{
if (search == null)
search = "%";
var skills = SkillManager.FindSkill (search);
return View (skills);
}
/// <summary>
/// Display and should
/// offer Ajax edition of
/// user's skills.
/// </summary>
/// <param name="usp">the User Skills Profile.</param>
[Authorize()]
public ActionResult UserSkills (PerformerProfile usp)
{
if (usp.UserName == null)
// this is not a call to update,
// and this can not concern another user
// than the current logged one.
usp = new PerformerProfile( User.Identity.Name );
// if (usp.UserName was null) {
usp = SkillManager.GetUserSkills (usp.UserName);
var skills = SkillManager.FindSkill ("%");
ViewData ["SiteSkills"] = skills;
// TODO or not to do, handle a skills profile update,
// actually performed via the Web API :-°
// } else if (ModelState.IsValid) {}
return View (usp);
}
}
}

View file

@ -78,12 +78,9 @@ namespace Yavsc.Controllers
if (string.IsNullOrWhiteSpace (returnUrl))
returnUrl = "/";
Session ["returnUrl"] = returnUrl;
OAuth2 oa = new OAuth2 (AuthGRU,clientId,clientSecret);
oa.Login (Response, SetSessionSate ());
string state = SetSessionSate ();
Response.Login (state, AuthGRU);
}
private string clientId = ConfigurationManager.AppSettings ["GOOGLE_CLIENT_ID"];
private string clientSecret = ConfigurationManager.AppSettings ["GOOGLE_CLIENT_SECRET"];
private string clientApiKey = ConfigurationManager.AppSettings ["GOOGLE_API_KEY"];
/// <summary>
/// Gets the cal auth.
/// </summary>
@ -93,8 +90,7 @@ namespace Yavsc.Controllers
if (string.IsNullOrWhiteSpace (returnUrl))
returnUrl = "/";
Session ["returnUrl"] = returnUrl;
OAuth2 oa = new OAuth2 (CalendarGRU,clientId,clientSecret);
oa.GetCalendarScope (Response, SetSessionSate ());
Response.CalLogin (SetSessionSate (), CalendarGRU);
}
/// <summary>
@ -107,8 +103,7 @@ namespace Yavsc.Controllers
public ActionResult CalAuth ()
{
string msg;
OAuth2 oa = new OAuth2 (CalendarGRU,clientId,clientSecret);
OAuth2 oa = GoogleHelpers.CreateOAuth2 (CalendarGRU);
AuthToken gat = oa.GetToken (Request, (string) Session ["state"], out msg);
if (gat == null) {
YavscHelpers.Notify(ViewData, msg);
@ -127,6 +122,7 @@ namespace Yavsc.Controllers
/// It should be called immediatly after getting the token from Google, in
/// order to save a descent value as expiration date.
/// </summary>
/// <param name="pr">pr.</param>
/// <param name="gat">Gat.</param>
private void SaveToken (ProfileBase pr, AuthToken gat)
{
@ -145,7 +141,7 @@ namespace Yavsc.Controllers
public ActionResult Auth ()
{
string msg;
OAuth2 oa = new OAuth2 (AuthGRU,clientId,clientSecret);
OAuth2 oa = GoogleHelpers.CreateOAuth2 (AuthGRU);
AuthToken gat = oa.GetToken (Request, (string)Session ["state"], out msg);
if (gat == null) {
YavscHelpers.Notify(ViewData, msg);
@ -268,9 +264,7 @@ namespace Yavsc.Controllers
returnUrl = Url.Action ("ChooseCalendar") // "ChooseCalendar?returnUrl="+HttpUtility.UrlEncode(returnUrl)
});
}
string cred = OAuth2.GetFreshGoogleCredential (HttpContext.Profile);
CalendarApi c = new CalendarApi (clientApiKey);
CalendarList cl = c.GetCalendars (cred);
CalendarList cl = GoogleHelpers.GetCalendars(HttpContext.Profile);
ViewData ["returnUrl"] = Session ["chooseCalReturnUrl"];
return View (cl);
}
@ -301,7 +295,7 @@ namespace Yavsc.Controllers
[Authorize,HttpGet]
public ActionResult Book ()
{
var model = new BookQuery ();
var model = new BookingQuery ();
model.StartDate = DateTime.Now;
model.EndDate = model.StartDate.AddDays(2);
model.StartHour = DateTime.Now.ToString("HH:mm");
@ -315,49 +309,35 @@ namespace Yavsc.Controllers
/// <returns>The query.</returns>
/// <param name="model">Model.</param>
[Authorize,HttpPost]
public ActionResult Book (BookQuery model)
public ActionResult Book (BookingQuery model)
{
DateTime mindate = DateTime.Now;
if (model.StartDate.Date < mindate.Date){
ModelState.AddModelError ("StartDate", LocalizedText.FillInAFutureDate);
}
if (model.EndDate < model.StartDate)
ModelState.AddModelError ("EndDate", LocalizedText.StartDateAfterEndDate);
if (ModelState.IsValid) {
DateTime mindate = DateTime.Now;
if (model.StartDate.Date < mindate.Date){
ModelState.AddModelError ("StartDate", LocalizedText.FillInAFutureDate);
}
if (model.EndDate < model.StartDate)
ModelState.AddModelError ("EndDate", LocalizedText.StartDateAfterEndDate);
var muc = Membership.FindUsersByName (model.Person);
if (muc.Count == 0) {
ModelState.AddModelError ("Person", LocalizedText.Non_existent_user);
}
if (!Roles.IsUserInRole (model.Role)) {
ModelState.AddModelError ("Role", LocalizedText.UserNotInThisRole);
}
ProfileBase upr = ProfileBase.Create (model.Person);
var gcalid = upr.GetPropertyValue ("gcalid");
if (gcalid is DBNull)
ModelState.AddModelError ("Person", LocalizedText.No_calendar_for_this_user);
if (ModelState.IsValid) {
string calid = (string) gcalid;
DateTime maxdate = model.EndDate;
CalendarApi c = new CalendarApi (clientApiKey);
CalendarEventList events;
try {
string creds = OAuth2.GetFreshGoogleCredential (upr);
events = c.GetCalendar (calid, mindate, maxdate, creds);
YavscHelpers.Notify (ViewData, "Google calendar API call success");
} catch (WebException ex) {
string response;
using (var stream = ex.Response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
response = reader.ReadToEnd();
foreach (string rolename in model.Roles) {
foreach (string username in Roles.GetUsersInRole(rolename)) {
try {
var pr = ProfileBase.Create(username);
var events = pr.GetEvents(model.StartDate,model.EndDate);
} catch (WebException ex) {
string response;
using (var stream = ex.Response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
response = reader.ReadToEnd();
}
YavscHelpers.Notify (ViewData,
string.Format(
"Google calendar API exception {0} : {1}<br><pre>{2}</pre>",
ex.Status.ToString(),
ex.Message,
response));
}
YavscHelpers.Notify (ViewData,
string.Format(
"Google calendar API exception {0} : {1}<br><pre>{2}</pre>",
ex.Status.ToString(),
ex.Message,
response));
}
}
}

View file

@ -14,8 +14,6 @@ using Yavsc.Helpers;
using Yavsc;
using System.Web.Mvc;
using Yavsc.Model.Blogs;
using System.Web.Security;
using System.Web.Profile;
namespace Yavsc.Controllers
{
@ -24,6 +22,21 @@ namespace Yavsc.Controllers
/// </summary>
public class HomeController : Controller
{
// Site name
private static string name = null;
/// <summary>
/// Gets or sets the site name.
/// </summary>
/// <value>The name.</value>
[Obsolete("Use YavscHelpers.SiteName insteed.")]
public static string Name {
get {
if (name == null)
name = WebConfigurationManager.AppSettings ["Name"];
return name;
}
}
/// <summary>
/// Lists the referenced assemblies.
@ -72,23 +85,14 @@ namespace Yavsc.Controllers
/// </summary>
public ActionResult Index ()
{
if (Session.IsNewSession) {
string uid = (!Request.IsAuthenticated) ? Request.AnonymousID : User.Identity.Name;
ProfileBase pr =
ProfileBase.Create (uid);
bool ac = (bool) pr.GetPropertyValue ("allowcookies");
if (!ac)
YavscHelpers.Notify (ViewData, LocalizedText.ThisSiteUsesCookies,
"function(){Yavsc.ajax(\"/Yavsc/AllowCookies\", { id:'"+uid+"' });}",
LocalizedText.I_understood);
}
foreach (string tagname in new string[] {"Accueil","Événements","Mentions légales"})
foreach (string tagname in new string[] {"Accueil","Yavsc","Événements","Mentions légales"})
{
TagInfo ti = BlogManager.GetTagInfo (tagname);
// TODO specialyze BlogEntry creating a PhotoEntry
ViewData [tagname] = ti;
}
return View ();
}
/// <summary>