Customizing redmine issue entry - ruby-on-rails

Well, the powers that be would like Redmine to be aware of the data in one of our other systems so issues can be auto assigned to staff based on our business application's parcel id's.
Until now we had a call tracking system written from scratch. I'd like to bastardize Redmine since it comes so close to meeting all user requirements. I think if I get pointed in the right direction I can hook into Redmine some already written javascript and already existing webservices to pull the necessary data to display it on a Redmine ticket at the time of ticket creation. I know that Redmine is highly customizable, but I don't know where to begin. I already checked for existing plugins to do this and I found none.
Any help would be greatly appreciated.

I hope I understand what you want.
You can add custom_field or write a migration to add a new column to table issues and patch issue form (you can use redmine hooks http://www.redmine.org/projects/redmine/wiki/Hooks_List). I prefer second way because it does not depend on Redmine settings.
You should add in plugin a route and method into issues_controller. This action will get AJAX request with ParcelID from the view (issue form) and proxy it to external server. The response should be user email (I think only this info is common for users in Redmine and External server). The action should find appropriate user in Redmine and return user_id to the view.
Patch issue form: add new input Parcel ID and add JS code. JS code should send AJAX after ParcelID loses focus and setup Assignee if request returns user_id.
some notes:
I don't think that you will manage to communicate with external server directly (without controller) because Server can return own user_id or user_email but view will not manage to setup Assignee using this attributes.
I think it is necessary to care about performance because JS code will start at least two requests (View<->Redmine, Redmine<->External Server)
hope it helps you

Related

Azure - App Insights - how to track the logged-in Username in Auth Id?

What is the best-supported approach for tracking logged-in Usernames/Ids in App Insights telemetry?
A User with Username "JonTester1" said some Pages he visited 4 hours ago were really slow. How can I see everything JonTester1 did in App Insights to trouble shoot/know which pages he's referring to?
Seems like User Id in App Insights is some Azure-generated anonymized thing like u7gbh that Azure ties to its own idea of the same user (thru cookie?). It doesn't know about our app's usernames at all.
I've also seen a separate field in App Insights called Auth Id (or user_AuthenticatedId in some spots), which looks to sometimes have the actual username e.g. "JonTester1" filled in - but not always... And while I don't see any mention of this field in the docs, it seems promising. How is our app's code/config supposed to be setting that Auth Id to make sure every App Insights log/telemetry has it set?
Relevant MS docs:
https://learn.microsoft.com/en-us/azure/azure-monitor/app/usage-send-user-context
This looks to just copy one library Telemetry object's User Id into another... no mention of our custom, helpful Username/Id anyway... and most in-the-wild examples I see don't actually look like this, including MS docs own examples in the 3rd link below; they instead hardcode get a new TelemetryClient()
https://learn.microsoft.com/en-us/azure/azure-monitor/app/website-monitoring No mention of consistently tracking a custom Username/Id
https://learn.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics#authenticated-users Shows some different helpful pieces, but still no full example. E.g. it says with only the setAuth... JS function call (still no full example of working client-side JS that tracks User) on the page, you don't need any server-side code for it to track custom User Id across both client-side and server-side telemetry sent to Azure... yet then it also shows explicit code to new up a TelemetryClient() server-side to track User Id (in the Global.asax.cs or where?)... so you do need both?
Similar SO questions, but don't connect the dots/show a full solution:
Azure Insights telemetry not showing Auth ID on all transactions
Application Insights - Tracking user and session across schemas
How is Application insight tracking the User_Id?
Display user ID in the metrics of application Insight
I'm hoping this question and answers can get this more ironed out; hopefully do a better job of documentation than the relevant MS docs...
The first link in your question lists the answer. What it does show you is how to write a custom telemetry initializer. Such an initializer lets you add or overwrite properties that will be send along any telemetry that is being send to App Insights.
Once you add it to the configuration, either in code or the config file (see the docs mentioned earlier in the answer) it will do its work without you needing to create special instances of TelemetryClient. That is why this text of you does not make sense to me:
[…] and most in-the-wild examples I see don't actually look like this, including MS docs own examples in the 3rd link below; they instead hardcode get a new TelemetryClient()
You can either overwrite the value of UserId or overwrite AuthenticatedUserId in your initializer. You can modify the code given in the docs like this:
if (requestTelemetry != null && !string.IsNullOrEmpty(requestTelemetry.Context.User.Id) &&
(string.IsNullOrEmpty(telemetry.Context.User.Id) || string.IsNullOrEmpty(telemetry.Context.Session.Id)))
{
// Set the user id on the Application Insights telemetry item.
telemetry.Context.User.AuthenticatedUserId = HttpContext.Current.User.Identity.Name;
}
You can then see the Auth Id and User Id by going to your AI resource -> Search and click an item. Make sure to press "Show All" first, otherwise the field is not displayed.
Auth Id in the screenshot below is set to the user id from the database in our example:
We access the server from azure functions as well so we set the user id server side as well since there is no client involved in such scenarios.
There is no harm in settting it in both places, javascript and server side via an initializer. That way you cover all scenario's.
You can also manually add user id to app insights by
appInsights.setAuthenticatedUserContext(userId);
See App Insights Authenticated users

Ruby on Rails. Using Google Client API to parse emails

I am new to Ruby and have a question about how to do a specific task on Rails.
I have a list of inventory and each item has a specific Stock ID that is emailed to my personal Gmail account. I want my web application to listen for emails from a specific email account. When my gmail receives an email from that specific account I want my application to parse it for a couple of fields and insert the stock ID into my database.
For example:
Let's say my database has an item with style code: A5U31 and size:10.
The email will say something like item with style code: A5U31 and size:10 has Stock ID:329193020.
I want my Rails application to search the database for an entry with that specific style code and size, and when it finds an entry to simply insert the stock ID into the row.
I am trying to using the Google-API-Client gem to this, but I am struggling, because I am still a beginner. So far I have done this quick-start guide to authenticate my gmail account with my rails app.
https://developers.google.com/gmail/api/quickstart/ruby?authuser=2
If someone could help me figure out how to write this sort of code and where to put it in my app(models, controllers, views) that would be very appreciated. Thanks!
I know it's been several months since you posted this, so you probably already have it worked out, but in case you still need a solution (or if someone else wants to do something similar), I'll share my thoughts:
At a high level, it sounds like your plan is
Identify when a new email has come in (either by polling or by using a push notification).
Grab the new email's content.
Parse the email's content in order to extract relevant data.
Use the data to query and update a database.
Based on the documentation for the Gmail API, it does look like you should be able to set up push notifications, so you won't have to poll the endpoint to get the information you need.
However, my big takeaway from this list is that none of the items on it really require Rails, since you're not exposing an external web API for requests. I suppose that you could leverage ActiveRecord to create an item model and use that to manage the database; however, since it seems like you'd only need to make some basic SQL queries (and the same ones each time), I'm not sure that bringing in ActiveRecord adds much value.
If I were trying to solve this problem myself, I would probably create a simple Ruby program that (a) uses the gem you mentioned to handle push notifications from the Gmail API, and (b) uses another gem to connect to whatever kind of database you're using (e.g. pg for Postgres) and make the necessary queries.
(All of this assumes, of course, that you aren't specifically using Rails for some other reason, e.g. adding this feature to an existing Rails application).

Retrieving single page with slug in apostrophe-headless

I have been working with apostrophe-headless for a while and have worked around the issues of not being able to request pages via the RESTAPI by slug in the past. I am about to start a new installation and I want the users to be able to create new pages of various types and edit with the convenience that the standard page type allows within apostrophe-cms. That being said, any attempt that I make to set up a filter or change the cursor of apostrophe-pages to allow for slug filtering fails and I have yet to be able to request a page by anything other than _id. I have seen mentions that a page should not be requested by slug, but from an isomorphic react-based app I won't have an _id when a user goes directly to a child page. Any suggestions or help would be greatly appreciated.

Locating Models in the Umbraco hierarchy

I am helping a friend of mine to edit a few things on his website that was built using Umbraco. I am not the original author and I am pretty new to Umbraco but, I can't seem to find the answer anywhere. There is a form that is being used to send an email whenever someone wants to order supplies from the website. The form was previously working. However, he has lost access to the email account and had to create a new one. The problem is I cannot seem to locate the model to look inside of it and change where the emails are being sent.
I cannot locate the Models (there are multiple) in the Umbraco hierarchy even though I can find references to where they're are called inside of the different forms. See below:
#inherits Umbraco.Web.Mvc.UmbracoViewPage<Aeon.Models.OrderSuppliesModel>
I know this is not a URL so I am a little confused on why this is not in any of the Umbraco hierarchy. I know that since it is referencing something and previously worked it has to be there somewhere. The only other place I would think they could be is in the root directory which I don't have access to yet. Could they possibly be located there? Any type of help on this matter would be greatly appreciated.
Since you don't have access to the code, you will have to hope there is a variable somewhere which lets you set the email, rather than it being hardcoded into the controller.
Umbraco nodes
Sometimes Umbraco developers store the email on a field on a node in Umbraco. The common places are:
on the page node which has the form on it
on a settings node
on the home page node
Web.config
The Web.config also has a section which can be used to easily setup variables. Checkout the <appSettings> section to see if there are keys and/or values which might indicate they're used for email.
Also, you haven't specifically said if it is the SMTP email account which has broken, or if it's the email account which submissions are being sent to. Look for the <mailSettings> section on the Web.config if you want to see the SMTP settings. There may be a 'from' field on the <smtp> element.
umbracoSettings.config
In the umbracoSettings.config there is an element which will look something like this:
<notifications>
<!-- the email that should be used as from mail when umbraco sends a notification -->
<email>your#email.here</email>
</notifications>
Forms are not directly handled within Umbraco. I am assuming you are using ver 6+.
To get a form to work you rely on the core MVC functionality, which means you create a Surface Controller with Get and POST actions to handle the logic.
There will be a reference to the specific model being passed to the view within the controller logic, but its common for standard static configuration information to be stored in an Umbraco node itself. Example of such are "SMTP server" "From Address" & "Use Encryption" etc. Some people as an alternative store this information as keys in web.config.
If you are specifically looking to change the model being passed to the form (OrderSuppliesModel), if you are using Visual Studio, the model should be colored in a teal color and when you hover over it, it shows the full namespace. Click it and press F12. This should link you directly to the class module.
hope it helps.
If you're lucky, they're using Umbraco Forms/Contour. When you log into the back office, do you see a section called either "Forms" or "Contour"?
If so, you should be able to find the form in the Forms tree, and at the bottom of the form you should be able to edit the workflows, which will allow you to change who gets emails sent to them etc.
If you don't have those sections, could you post the view that has the form on so we can see what it's doing please?

Update content when new values are added to database?

I know my question might be ovbious for some of you, but I'm not sure how to do it, and I can't find it on google, probably because I'm not using the right keywords.
I'm using the latest rails. On my view I have a table generated by rails. People are able to add content to that table by sending a rails form.
I want this table to be updated with newly updated values, without having to refresh the page.
For example, if user 1 sent the rails form and added a new value to the database, I want user 2 to see this update without having to refresh the page.
I would highly suggest watching the Polling for Changes - Railscast that covers exactly what you are looking for.
This essentially will cover how to use jQuery to poll the server to see if there are any changes, and apply them to the page without refreshing(ajax).

Resources