public object Post(ThematicAppAddToCommunityRequestTep request) { IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.UserView); context.Open(); context.LogInfo(this, string.Format("/community/{{domain}}/apps POST domain='{0}', appurl='{1}'", request.Domain, request.AppUrl)); if (string.IsNullOrEmpty(request.AppUrl)) { throw new Exception("Invalid Application Url"); } var domain = ThematicCommunity.FromIdentifier(context, request.Domain); if (!domain.CanUserManage(context.UserId)) { throw new UnauthorizedAccessException("Action only allowed to manager of the domain"); } var app = domain.GetThematicApplication(); var res = new RemoteResource(context); res.Location = request.AppUrl; app.AddResourceItem(res); context.Close(); return(new WebResponseBool(true)); }
public object Put(UpdateBulkUsersProfileFromRemoteTep request) { IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/users/profile PUT Ids='{0}'", string.Join(",", request.Identifiers))); foreach (var identifier in request.Identifiers) { try { var usr = UserTep.FromIdentifier(context, identifier); usr.LoadProfileFromRemote(); }catch (Exception e) { context.LogError(this, e.Message + " - " + e.StackTrace); } } try{ var portalname = string.Format("{0} Portal", context.GetConfigValue("SiteNameShort")); var subject = context.GetConfigValue("EmailBulkActionSubject"); subject = subject.Replace("$(SITENAME)", portalname); var body = context.GetConfigValue("EmailBulkActionBody"); body = body.Replace("$(ADMIN)", context.Username); body = body.Replace("$(ACTION)", "User remote profile load"); body = body.Replace("$(IDENTIFIERS)", string.Join(",", request.Identifiers)); context.SendMail(context.GetConfigValue("SmtpUsername"), context.GetConfigValue("SmtpUsername"), subject, body); } catch (Exception e) { context.LogError(this, e.Message + " - " + e.StackTrace); } context.Close(); } catch (Exception e) { context.LogError(this, e.Message + " - " + e.StackTrace); context.Close(); throw e; } return(true); }
public object Put(UpdateBulkUsersLevelTep request) { IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/users/level PUT Ids='{0}',level='{1}'", string.Join(",", request.Identifiers), request.Level)); string ids = ""; foreach (var id in request.Identifiers) { ids += string.Format("'{0}',", id); } ids = ids.TrimEnd(','); string sql = string.Format("UPDATE usr SET level='{0}' WHERE username IN ({1});", request.Level, ids); context.Execute(sql); try{ var portalname = string.Format("{0} Portal", context.GetConfigValue("SiteNameShort")); var subject = context.GetConfigValue("EmailBulkActionSubject"); subject = subject.Replace("$(SITENAME)", portalname); var body = context.GetConfigValue("EmailBulkActionBody"); body = body.Replace("$(ADMIN)", context.Username); body = body.Replace("$(ACTION)", "User level update"); body = body.Replace("$(IDENTIFIERS)", string.Join(",", request.Identifiers)); context.SendMail(context.GetConfigValue("SmtpUsername"), context.GetConfigValue("SmtpUsername"), subject, body); } catch (Exception e) { context.LogError(this, e.Message + " - " + e.StackTrace); } context.Close(); } catch (Exception e) { context.LogError(this, e.Message + " - " + e.StackTrace); context.Close(); throw e; } return(true); }
/// <summary> /// Get the specified request. /// </summary> /// <param name="request">Request.</param> /// /apps/{identifier}/search GET public object Get(ThematicAppSearchRequestTep request) { IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); context.Open(); context.LogInfo(this, string.Format("/apps/search GET -- cache = {0}", request.cache)); IOpenSearchResultCollection result; OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine; HttpRequest httpRequest = HttpContext.Current.Request; Type responseType = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose); //first we get the communities the user can see var communities = new EntityList <ThematicCommunity>(context); if (context.UserId == 0) { communities.SetFilter("Kind", (int)DomainKind.Public + ""); } else { communities.SetFilter("Kind", (int)DomainKind.Public + "," + (int)DomainKind.Hidden + "," + (int)DomainKind.Private); communities.AddSort("Kind", SortDirection.Ascending); } communities.Load(); if (request.cache) { List <int> ids = new List <int>(); foreach (var c in communities) { if (c.IsUserJoined(context.UserId)) { ids.Add(c.Id); } } EntityList <ThematicApplicationCached> appsCached = new EntityList <ThematicApplicationCached>(context); var filterValues = new List <object>(); filterValues.Add(string.Join(",", ids)); filterValues.Add(SpecialSearchValue.Null); appsCached.SetFilter("DomainId", filterValues.ToArray()); appsCached.SetGroupFilter("UId"); appsCached.AddSort("LastUpdate", SortDirection.Descending); result = ose.Query(appsCached, httpRequest.QueryString, responseType); OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(appsCached, result); } else { List <Terradue.OpenSearch.IOpenSearchable> osentities = new List <Terradue.OpenSearch.IOpenSearchable>(); var settings = MasterCatalogue.OpenSearchFactorySettings; var specsettings = (OpenSearchableFactorySettings)settings.Clone(); if (context.UserId != 0) { var user = UserTep.FromId(context, context.UserId); var apikey = user.GetSessionApiKey(); var t2userid = user.TerradueCloudUsername; if (!string.IsNullOrEmpty(apikey)) { specsettings.Credentials = new System.Net.NetworkCredential(t2userid, apikey); } } //get apps link from the communities the user can see foreach (var community in communities.Items) { if (community.IsUserJoined(context.UserId)) { var app = community.GetThematicApplication(); if (app != null) { app.LoadItems(); foreach (var item in app.Items) { if (!string.IsNullOrEmpty(item.Location)) { try { var ios = OpenSearchFactory.FindOpenSearchable(specsettings, new OpenSearchUrl(item.Location)); osentities.Add(ios); context.LogDebug(this, string.Format("Apps search -- Add '{0}'", item.Location)); } catch (Exception e) { context.LogError(this, e.Message, e); } } } } } } //get thematic apps without any domain var apps = new EntityList <ThematicApplication>(context); apps.SetFilter("DomainId", SpecialSearchValue.Null); apps.SetFilter("Kind", ThematicApplication.KINDRESOURCESETAPPS + ""); apps.Load(); foreach (var app in apps) { app.LoadItems(); foreach (var item in app.Items) { if (!string.IsNullOrEmpty(item.Location)) { try { var ios = OpenSearchFactory.FindOpenSearchable(specsettings, new OpenSearchUrl(item.Location)); osentities.Add(ios); context.LogDebug(this, string.Format("Apps search -- Add '{0}'", item.Location)); } catch (Exception e) { context.LogError(this, e.Message, e); } } } } MultiGenericOpenSearchable multiOSE = new MultiGenericOpenSearchable(osentities, specsettings); result = ose.Query(multiOSE, httpRequest.QueryString, responseType); } var sresult = result.SerializeToString(); //replace usernames in apps try { var user = UserTep.FromId(context, context.UserId); sresult = sresult.Replace("${USERNAME}", user.Username); sresult = sresult.Replace("${T2USERNAME}", user.TerradueCloudUsername); sresult = sresult.Replace("${T2APIKEY}", user.GetSessionApiKey()); } catch (Exception e) { context.LogError(this, e.Message, e); } if (!string.IsNullOrEmpty(httpRequest.QueryString["uid"])) { try{ var user = UserTep.FromId(context, context.UserId); EventUserLoggerTep eventLogger = new EventUserLoggerTep(context); eventLogger.GetLogEvent(user, "portal_user_access_workspace", "User workspace access").ContinueWith <Event>( usrevent => { if (usrevent != null) { var callId = httpRequest.QueryString["uid"]; usrevent.Result.Item.Properties.Add("app_id", callId); EventFactory.Log(context, usrevent.Result); } return(usrevent.Result); } ); }catch (Exception) {} } context.Close(); return(new HttpResult(sresult, result.ContentType)); }
public object Get(ThematicAppCurrentUserSearchRequestTep request) { IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); context.Open(); context.LogInfo(this, string.Format("/user/current/apps/search GET")); IOpenSearchResultCollection result; OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine; var httpRequest = HttpContext.Current.Request; Type responseType = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose); List <Terradue.OpenSearch.IOpenSearchable> osentities = new List <Terradue.OpenSearch.IOpenSearchable>(); var settings = MasterCatalogue.OpenSearchFactorySettings; OpenSearchableFactorySettings specsettings = (OpenSearchableFactorySettings)settings.Clone(); UserTep user = null; if (context.UserId != 0) { user = UserTep.FromId(context, context.UserId); if (request.cache) { var domain = user.GetPrivateDomain(); EntityList <ThematicApplicationCached> appsCached = new EntityList <ThematicApplicationCached>(context); appsCached.SetFilter("DomainId", domain.Id); appsCached.AddSort("LastUpdate", SortDirection.Descending); result = ose.Query(appsCached, Request.QueryString, responseType); OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(appsCached, result); } else { //get user private thematic app var apikey = user.GetSessionApiKey(); var t2userid = user.TerradueCloudUsername; if (!string.IsNullOrEmpty(apikey)) { specsettings.Credentials = new System.Net.NetworkCredential(t2userid, apikey); } var app = user.GetPrivateThematicApp(); if (app != null) { foreach (var item in app.Items) { if (!string.IsNullOrEmpty(item.Location)) { try { var sgOs = OpenSearchFactory.FindOpenSearchable(specsettings, new OpenSearchUrl(item.Location)); osentities.Add(sgOs); context.LogDebug(this, string.Format("Apps search -- Add '{0}'", item.Location)); } catch (Exception e) { context.LogError(this, e.Message, e); } } } } MultiGenericOpenSearchable multiOSE = new MultiGenericOpenSearchable(osentities, specsettings); result = ose.Query(multiOSE, Request.QueryString, responseType); } } else { result = ose.Query(new MultiGenericOpenSearchable(osentities, specsettings), Request.QueryString, responseType); } string sresult = result.SerializeToString(); //replace usernames in apps if (user != null) { try { sresult = sresult.Replace("${USERNAME}", user.Username); sresult = sresult.Replace("${T2USERNAME}", user.TerradueCloudUsername); sresult = sresult.Replace("${T2APIKEY}", user.GetSessionApiKey()); } catch (Exception e) { context.LogError(this, e.Message, e); } } context.Close(); return(new HttpResult(sresult, result.ContentType)); }
public object Get(ThematicAppByCommunitySearchRequestTep request) { IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); context.Open(); context.LogInfo(this, string.Format("/community/{{domain}}/apps/search GET domain='{0}'", request.Domain)); var domain = ThematicCommunity.FromIdentifier(context, request.Domain); IOpenSearchResultCollection result; OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine; HttpRequest httpRequest = HttpContext.Current.Request; Type responseType = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose); if (request.cache) { bool isjoined = domain.IsUserJoined(context.UserId); EntityList <ThematicApplicationCached> appsCached = new EntityList <ThematicApplicationCached>(context); if (isjoined) { appsCached.SetFilter("DomainId", domain.Id.ToString()); } else { appsCached.SetFilter("DomainId", "-1");//if user is not joined we dont want him to see results } appsCached.AddSort("LastUpdate", SortDirection.Descending); result = ose.Query(appsCached, httpRequest.QueryString, responseType); OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(appsCached, result); } else { if (MasterCatalogue.SearchCache != null) { MasterCatalogue.SearchCache.ClearCache(".*", DateTime.Now); } var apps = new EntityList <DataPackage>(context); apps.SetFilter("Kind", ThematicApplication.KINDRESOURCESETAPPS.ToString()); apps.SetFilter("DomainId", domain.Id.ToString()); apps.Load(); // the opensearch cache system uses the query parameters // we add to the parameters the filters added to the load in order to avoir wrong cache // we use 't2-' in order to not interfer with possibly used query parameters var qs = new NameValueCollection(Request.QueryString); foreach (var filter in apps.FilterValues) { qs.Add("t2-" + filter.Key.FieldName, filter.Value.ToString()); } apps.OpenSearchEngine = ose; List <Terradue.OpenSearch.IOpenSearchable> osentities = new List <Terradue.OpenSearch.IOpenSearchable>(); foreach (var app in apps.Items) { app.OpenSearchEngine = ose; osentities.AddRange(app.GetOpenSearchableArray()); } var settings = MasterCatalogue.OpenSearchFactorySettings; MultiGenericOpenSearchable multiOSE = new MultiGenericOpenSearchable(osentities, settings); result = ose.Query(multiOSE, httpRequest.QueryString, responseType); } var sresult = result.SerializeToString(); //replace usernames in apps try { var user = UserTep.FromId(context, context.UserId); sresult = sresult.Replace("${USERNAME}", user.Username); sresult = sresult.Replace("${T2USERNAME}", user.TerradueCloudUsername); sresult = sresult.Replace("${T2APIKEY}", user.GetSessionApiKey()); } catch (Exception e) { context.LogError(this, e.Message, e); } context.Close(); return(new HttpResult(sresult, result.ContentType)); }