Example #1
0
File: TM_REST.cs Project: sempf/Dev
 public TM_REST()
 {
     Context       = HttpContextFactory.Current;
     Session       = HttpContextFactory.Session;
     TmWebServices = new TM_WebServices(true);	//Disabling CSRF
     //UserGroup.Admin.setThreadPrincipalWithRoles();
 }
Example #2
0
 public static UserActivity logTBotActivity(this TM_WebServices tmWebServices, string action, string detail)
 {
     if (tmWebServices.notNull())
     {
         return(tmWebServices.tmFileStorage.logTBotActivity(action, detail));
     }
     return(null);
 }
Example #3
0
 public TM_REST()
 {
     Context = HttpContextFactory.Current;
     Session = HttpContextFactory.Session;
     check_CSRF_Header();
     //TmWebServices = new TM_WebServices(true);	//Disabling CSRF
     TmWebServices = new TM_WebServices(false);  //Disabling CSRF
 }
Example #4
0
 public TM_REST()
 {
     // ensureTMEndpointsBehavioursAreMapped();
     Context       = HttpContextFactory.Current;
     Session       = HttpContextFactory.Session;
     TmWebServices = new TM_WebServices(true);   //Disabling CSRF
     //UserGroup.Admin.setThreadPrincipalWithRoles();
 }
Example #5
0
        public void redirectTo_DownloadLibrary(string data)
        {
            // UserGroup.Admin.setThreadPrincipalWithRoles();      // to test for this (for now allow normal users to download libraries)
            //var currentUserRoles = tmWebServices.RBAC_CurrentPrincipal_Roles();

            var uploadToken = new TM_WebServices().GetUploadToken();

            context.Response.Redirect("/Aspx_Pages/Library_Download.ashx?library={0}&uploadToken={1}".format(data, uploadToken));
        }
Example #6
0
        public static UserActivity LogUserActivity(this TM_WebServices tm_WebServices, string name, string detail)
        {
            var currentUser = tm_WebServices.Current_User();

            if (currentUser.notNull())
            {
                currentUser.UserName.tmUser().logUserActivity(name, detail);
            }
            return(null);
        }
        public TM_WebServices_InMemory()
        {
            HttpContextFactory.Context = new API_Moq_HttpContext().httpContext();
            tmWebServices = new TM_WebServices();

            Assert.NotNull(tmWebServices);
            Assert.IsNull (tmWebServices.tmFileStorage);
            Assert.NotNull(tmWebServices.tmAuthentication);
            Assert.NotNull(tmWebServices.tmXmlDatabase);
            Assert.NotNull(tmWebServices.userData);
        }
Example #8
0
 public static UserActivity logUserActivity(this TM_WebServices tmWebServices, string action, string detail)
 {
     if (tmWebServices.notNull())
     {
         var currentUser = tmWebServices.Current_User();
         if (currentUser.notNull())
         {
             return(currentUser.UserName.tmUser().logUserActivity(action, detail));
         }
         return(tmWebServices.logTBotActivity(action, detail));
     }
     return(null);
 }
Example #9
0
        public void Issue_681__Navigating_libraries_views_folders__Clicking_the_icon_doesnt_work()
        {
            var tmWebServices  = new TM_WebServices();

            Func<string, string> clickOnNodeUsingJQuerySelector =
                (jQuerySelector)=>
                    {
                        ie.invokeEval("TM.Gui.selectedGuidanceTitle=undefined");
                        ie.invokeEval("$('#{0}').click()".format(jQuerySelector));
                        ie.waitForJsVariable("TM.Gui.selectedGuidanceTitle");
                        return ie.getJsObject<string>("TM.Gui.selectedGuidanceTitle");
                    };

            if (tmProxy.libraries().notEmpty())
            {
                "Ensuring the the only library that is there is the TM Documentation".info();
                foreach(var library in tmProxy.libraries())
                    if(library.Caption != "TM Documentation")
                    {
                        "deleting library: {0}".debug(library.Caption);
                        tmProxy.library_Delete(library.Caption);
                    }
            }

            UserRole.Admin.assert();

            tmProxy.library_Install_Lib_Docs();
            tmProxy.cache_Reload__Data();
            tmProxy.show_ContentToAnonymousUsers(true);

            ieTeamMentor.page_Home();
            //tmWebServices.script_Me_WaitForClose();;
            //ieTeamMentor.script_IE_WaitForComplete();

            ie.waitForJsVariable("TM.Gui.selectedGuidanceTitle");

            var _jsTree =  tmWebServices.JsTreeWithFolders();
            var viewNodes = _jsTree.data[0].children;				// hard coding to the first library
            var view1_Id    = viewNodes[0].attr.id;
            var view5_Id    = viewNodes[4].attr.id;

            var click_View_1_Using_A    = clickOnNodeUsingJQuerySelector(view1_Id + " a"  );
            var click_View_5_Using_A    = clickOnNodeUsingJQuerySelector(view5_Id + " a"  );
            var click_View_1_Using_Icon = clickOnNodeUsingJQuerySelector(view1_Id + " ins"  );
            var click_View_5_Using_Icon = clickOnNodeUsingJQuerySelector(view5_Id + " ins"  );

            (click_View_1_Using_A != click_View_5_Using_A   ).assert_True();

            (click_View_5_Using_A == click_View_1_Using_Icon).assert_False(); // (Issue 681) this was true since the view was not updating
            (click_View_5_Using_A == click_View_5_Using_Icon).assert_True();
        }
        public static List <Guid> getGuidanceItemsIds_NotInViews(this TM_WebServices tmWebServices, Guid libraryId)
        {
            var guidanceInViews = (from view in tmWebServices.GetViews()
                                   where view.libraryId == libraryId
                                   from guidanceItem in view.guidanceItems
                                   select guidanceItem).Distinct().toList();


            var guidanceItemsIdsNotInViews = (from guidanceItem in tmWebServices.GetGuidanceItemsInLibrary(libraryId)
                                              where guidanceInViews.contains(guidanceItem.Metadata.Id).isFalse()
                                              select guidanceItem.Metadata.Id).toList();

            return(guidanceItemsIdsNotInViews);
        }
Example #11
0
 public TM_Authentication(TM_WebServices tmWebServices)
 {
     TmWebServices      = tmWebServices;
     Disable_Csrf_Check = false;
 }
Example #12
0
 public TM_Authentication(TM_WebServices tmWebServices)
 {
     TmWebServices = tmWebServices;
     Disable_Csrf_Check = false;
 }
Example #13
0
        public void redirectTo_DownloadLibrary(string data)
        {
            // UserGroup.Admin.setThreadPrincipalWithRoles();      // to test for this (for now allow normal users to download libraries)
            //var currentUserRoles = tmWebServices.RBAC_CurrentPrincipal_Roles();

            var uploadToken = new TM_WebServices().GetUploadToken();
            context.Response.Redirect("/Aspx_Pages/Library_Download.ashx?library={0}&uploadToken={1}".format(data, uploadToken));
        }
Example #14
0
        //All mappings are here
        public bool handleRequest(string action , string data)
        {
            try
            {
                tmWebServices = new TM_WebServices(true);       // enable webservices access (and security checks with CSRF disabled)

                action = Encoder.HtmlEncode(action);
                data = Encoder.HtmlEncode(data).replace("%20"," ");

                if (action.isGuid() & data.inValid())
                {
                    redirectTo_Article(action);
                    endResponse();
                }

                transfer_Request(action.lower());       // throw "Thread was being aborted." exception if worked
                response_Redirect(action.lower());      // throw "Thread was being aborted." exception if worked

                //content viewer
                switch (action.lower())
                {
                    case "raw":
                        handleAction_Raw(data);
                        break;
                    case "html":
                        handleAction_Html(data);
                        break;
                    case "content":
                        handleAction_Content(data);
                        break;
                    case "xml":
                        handleAction_Xml(data);
                        break;
                    case "xsl":
                        handleAction_Xsl(data, "TeamMentor_Article.xslt");
                        break;
                    case "creole":
                        handleAction_Xsl(data, "JsCreole_Article.xslt");
                        break;

                    case "image":
                        handleAction_Image(data);
                        break;
                    case "jsonp":
                        handleAction_JsonP(data);
                        break;
                    case "viewer":
                    case "article":
                    case "a":
                        handle_ArticleViewRequest(data);
                        break;
                    case "edit":
                    case "editor":
                         handle_ArticleEditRequest(data);
                        break;
                    case "notepad":
                        handleAction_Xsl(data, "Notepad_Edit.xslt");
                        break;
                    case "create":
                        handleAction_Create(data);
                        break;
                }
                //user actions
                switch (action.lower())
                {
                    case "login":
                        redirect_Login();
                        break;
                    case "login_ok":
                        handle_LoginOK();
                        break;
                    case "logout":
                        redirectTo_Logout();
                        break;

                    case "library":
                        redirectTo_SetLibrary(data);
                        break;
                }
                //admin actions
                switch (action.lower())
                {
            //                    case "reload":
            //                        reloadCache_and_RedirectToHomePage();
            //                        break;
            //                    case "reload_config":
            //                        reload_Config();
            //                        break;
                    //case "reload_userdata":
                    //    reload_UserData();
                        //break;
                    case "library_download":
                    case "download_library":
                        redirectTo_DownloadLibrary(data);
                        break;
                        //case "sso":
                        //    return handleAction_SSO();
                }

                tmWebServices.tmAuthentication.mapUserRoles();			 // enable  CSRF protection
                switch (action.lower())
                {
                    case "external":
                        showVirtualArticleExternal(data);
                        break;
                    case "virtualarticles":
                        showVirtualArticles();
                        break;
                    case "addvirtualarticle":
                        addVirtualArticleMapping(data);
                        break;
                    case "removevirtualarticle":
                        removeVirtualArticleMapping(data);
                        break;
                    case "whoami":
                        showWhoAmI(data);
                        break;
                }
            }
            catch (Exception ex)
            {
                if (ex is SecurityException)
                {
                    var originalUrl = "/{0}/{1}".format(action,data.replace(",","/"));
                    redirect_Login_AccessDenied(originalUrl);
                }
                if (ex.Message != "Thread was being aborted.")
                    ex.logWithStackTrace("at handleRequest");
                else
                    return true;
            }
            return false;
        }
Example #15
0
 public TM_REST()
 {
     // ensureTMEndpointsBehavioursAreMapped();
     Context       = HttpContextFactory.Current;
     Session       = HttpContextFactory.Session;
     TmWebServices = new TM_WebServices(true);	//Disabling CSRF
     //UserGroup.Admin.setThreadPrincipalWithRoles();
 }
 public TM_WebServices_FileStorage()
 {
     HttpContextFactory.Context = new API_Moq_HttpContext().httpContext();
     tmWebServices = new TM_WebServices();
     Assert.NotNull(tmWebServices);
 }
 public static List <Library_V3> getFolderStructure_Libraries(this TM_WebServices tmWebServices, TM_GUI_Objects guiObjects)
 {
     return((from library in tmWebServices.GetLibraries()
             select tmWebServices.getFolderStructure_Library(library.Id, guiObjects)).toList());
 }
Example #18
0
 public TM_Authentication(TM_WebServices tmWebServices)
 {
     TmWebServices           = tmWebServices;
     Disable_Csrf_Check      = false;
     Current_WindowsIdentity = WindowsIdentity.GetCurrent();
 }
Example #19
0
 public TM_REST()
 {
     Context       = HttpContextFactory.Current;
     Session       = HttpContextFactory.Session;
     check_CSRF_Header();
     //TmWebServices = new TM_WebServices(true);	//Disabling CSRF
     TmWebServices = new TM_WebServices(disable_Csrf_Check : false);	//Disabling CSRF
 }
Example #20
0
        //All mappings are here
        public bool handleRequest(string action , string data)
        {
            try
            {
                tmWebServices = new TM_WebServices(true);       // enable webservices access (and security checks with CSRF disabled)
                action = Encoder.HtmlEncode(action);
                data = Encoder.HtmlEncode(data).replace("%20"," ");
                if (action.isGuid() & data.inValid())
                    return redirectTo_Article(action);
                switch (action.lower())
                {
                    case "gui":
                    case "teammentor":
                        return transfer_TeamMentorGui();
                    case "raw":
                        return handleAction_Raw(data);
                    case "html":
                        return handleAction_Html(data);
                    case "content":
                        return handleAction_Content(data);
                    case "xml":
                        return handleAction_Xml(data);
                    case "xsl":
                        return handleAction_Xsl(data,"TeamMentor_Article.xslt");
                    case "creole":
                        return handleAction_Xsl(data,"JsCreole_Article.xslt");
                    case "notepad":
                        return handleAction_Xsl(data, "Notepad_Edit.xslt");
                    case "viewer":
                    case "article":
                        return handle_ArticleViewRequest(data);
                    case "edit":
                    case "editor":
                        return transfer_ArticleEditor(data);
                    case "create":
                        return handleAction_Create(data);
                    case "admin":
                        return redirectTo_ControlPanel(false);
                    case "admin_extra":
                        return redirectTo_ControlPanel(true);
                    case "reload_config":
                        return reload_Config();
                    case "passwordreset":
                        return transfer_PasswordReset();
                    case "login":
                        return redirect_Login();
                    case "login_ok":
                        return handle_LoginOK();
                    case "logout":
                        return redirectTo_Logout();
                    case "wsdl":
                        return redirectTo_Wsdl();
                    case "reload":
                        return reloadCache_and_RedirectToHomePage();
                   case "home":
                        return redirectTo_HomePage();
                    //case "images":
                    case "image":
                        return handleAction_Image(data);
                    case "jsonp":
                        return handleAction_JsonP(data);
                    case "debug":
                        return redirectTo_DebugPage();
                    case "library":
                        return redirectTo_SetLibrary(data);
                    case "library_download":
                    case "download_library":
                        return redirectTo_DownloadLibrary(data);
                    case "sso":
                        return handleAction_SSO();
                }

                tmWebServices.tmAuthentication.mapUserRoles(false);			 // enable  CSRF protection
                switch (action.lower())
                {
                    case "external":
                        return showVirtualArticleExternal(data);
                    case "virtualarticles":
                        return showVirtualArticles();
                    case "addvirtualarticle":
                        return addVirtualArticleMapping(data);
                    case "removevirtualarticle":
                        return removeVirtualArticleMapping(data);
                    default:
                        return false;
                }
            }
            catch (Exception ex)
            {
                if (ex is SecurityException)
                    return redirect_Login();
              //      return redirectTo_Login();
                if (ex.Message != "Thread was being aborted.")
                {
                    ex.log();
                    //context.Response.Write("<h2>Error: {0} </h2>".format(ex.Message));
                }
            }
            return false;
        }
        public static Library_V3 getFolderStructure_Library(this TM_WebServices tmWebServices, Guid libraryId, TM_GUI_Objects guiObjects)
        {
            // ReSharper disable AccessToModifiedClosure
            //pre-create this mapping since the view retrieval was a massive performance bottle neck
            var allViews = new Dictionary <Guid, View_V3>();

            foreach (var view in tmWebServices.GetViews())
            {
                if (allViews.hasKey(view.viewId))
                {
                    "[getFolderStructure_Library] duplicate viewID: {0} from Library {0}".format(view.viewId, view.libraryId);              // this should be moved into a TM Library health check
                }
                else
                {
                    allViews.Add(view.viewId, view);
                }
            }

            Action <Folder_V3> mapFolderViews = null;

            Func <List <Guid>, List <View_V3> > mapViews =
                (viewGuids) =>
            {
                var views = new List <View_V3>();

                foreach (var viewGuid in viewGuids)
                {
                    var view = allViews[viewGuid];

                    /*// compress view.guidanceItems using guiObjects
                     * view.guidanceItems_Indexes = (from guid in view.guidanceItems
                     *                                                    select guiObjects.get_Index(guid.str()).str()).toList()
                     *                                                        .join(",").remove(" ");
                     * view.guidanceItems.Clear();*/
                    views.add(view);
                }
                return(views);
            };

            // ReSharper disable PossibleNullReferenceException
            // ReSharper disable ImplicitlyCapturedClosure
            mapFolderViews =
                (folder) => {
                var mappedViews = mapViews(folder.views.guids());
                folder.views.Clear();
                folder.views.add(mappedViews);
                foreach (var subFolder in folder.subFolders)
                {
                    mapFolderViews(subFolder);
                }
            };
            Action <List <Folder_V3>, List <Folder_V3> > mapFolders = (folders, parentFolder) =>
            {
                foreach (var folder in folders)
                {
                    parentFolder.add(folder);
                    mapFolderViews(folder);
                }
            };
            Func <Guid, string, Library_V3> mapLibrary =
                (library_Id, libraryName) => {
                var libraryV3 = new Library_V3
                {
                    libraryId = library_Id,
                    name      = libraryName
                };
                mapFolders(tmWebServices.GetFolders(library_Id), libraryV3.subFolders);
                libraryV3.views.add(mapViews(tmWebServices.GetViewsInLibraryRoot(libraryId).guids()));
                libraryV3.guidanceItems = tmWebServices.getGuidanceItemsIds_NotInViews(library_Id);
                return(libraryV3);
            };

            Func <Guid, Library_V3> getLibrary_TreeStructure =
                (id) => {
                var tmLibrary = tmWebServices.GetLibraryById(id);
                if (tmLibrary.isNull())
                {
                    "[in getLibraryFolderStructure] could not find library with id: {0}".error(id);
                    return(null);
                }
                return(mapLibrary(id, tmLibrary.caption));
            };

            return(getLibrary_TreeStructure(libraryId));
            // ReSharper restore PossibleNullReferenceException
            // ReSharper restore ImplicitlyCapturedClosure
            // ReSharper restore AccessToModifiedClosure
        }
Example #22
0
        //All mappings are here
        public void handleRequest(string action, string data)
        {
            try
            {
                tmWebServices = new TM_WebServices(true);       // enable webservices access (and security checks with CSRF disabled)
                action        = Encoder.HtmlEncode(action);
                data          = Encoder.HtmlEncode(data).replace("%20", " ");

                if (action.isGuid() & data.inValid())
                {
                    redirectTo_Article(action);
                    endResponse();
                }
                transfer_Request(action.lower());       // throw "Thread was being aborted." exception if worked
                response_Redirect(action.lower());      // throw "Thread was being aborted." exception if worked

                //content viewer
                switch (action.lower())
                {
                case "raw":
                    handleAction_Raw(data);
                    break;

                case "html":
                    handleAction_Html(data);
                    break;

                case "content":
                    handleAction_Content(data);
                    break;

                case "xml":
                    handleAction_Xml(data);
                    break;

                case "xsl":
                    handleAction_Xsl(data, "TeamMentor_Article.xslt");
                    break;

                case "creole":
                    handleAction_Xsl(data, "JsCreole_Article.xslt");
                    break;

                case "image":
                    handleAction_Image(data);
                    break;

                case "jsonp":
                    handleAction_JsonP(data);
                    break;

                case "viewer":
                case "article":
                    handle_ArticleViewRequest(data);
                    break;

                case "edit":
                case "editor":
                    transfer_ArticleEditor(data);
                    break;

                case "notepad":
                    handleAction_Xsl(data, "Notepad_Edit.xslt");
                    break;

                case "create":
                    handleAction_Create(data);
                    break;
                }
                //user actions
                switch (action.lower())
                {
                case "login":
                    redirect_Login();
                    break;

                case "login_ok":
                    handle_LoginOK();
                    break;

                case "logout":
                    redirectTo_Logout();
                    break;

                case "library":
                    redirectTo_SetLibrary(data);
                    break;
                }
                //admin actions
                switch (action.lower())
                {
//                    case "reload":
//                        reloadCache_and_RedirectToHomePage();
//                        break;
//                    case "reload_config":
//                        reload_Config();
//                        break;
                //case "reload_userdata":
                //    reload_UserData();
                //break;
                case "library_download":
                case "download_library":
                    redirectTo_DownloadLibrary(data);
                    break;
                    //case "sso":
                    //    return handleAction_SSO();
                }

                tmWebServices.tmAuthentication.mapUserRoles(false);                      // enable  CSRF protection
                switch (action.lower())
                {
                case "external":
                    showVirtualArticleExternal(data);
                    break;

                case "virtualarticles":
                    showVirtualArticles();
                    break;

                case "addvirtualarticle":
                    addVirtualArticleMapping(data);
                    break;

                case "removevirtualarticle":
                    removeVirtualArticleMapping(data);
                    break;
                }
            }
            catch (Exception ex)
            {
                if (ex is SecurityException)
                {
                    redirect_Login();
                }
                if (ex.Message != "Thread was being aborted.")
                {
                    ex.logWithStackTrace("at handleRequest");
                }
            }
        }
Example #23
0
 public TM_WebServices_InMemory()
 {
     HttpContextFactory.Context = new API_Moq_HttpContext().httpContext();
     //tmXmlDatabase    = new TM_Xml_Database();
     tmWebServices = new TM_WebServices();
 }
Example #24
0
 public TM_Authentication(TM_WebServices tmWebServices)
 {
     TmWebServices = tmWebServices;
     Disable_Csrf_Check = false;
     Current_WindowsIdentity = WindowsIdentity.GetCurrent();
 }