Redmine API - Creating Issues - redmine

I am trying to use Redmine's API to create issues, but it doesn't seem to let me specify who is submitting the ticket. I have tried getting author_id and it doesn't seem to work.
This is what the JSON data in the POST looks like:
{
"issue": {
"author_id": 3,
"project_id": 26,
"subject": "Q-12345678",
"description": "This is a test"
}
}
The issue is being created, but the author is being set to anonymous. Any suggestions?

Well, I figured it out. As it turns out author_id is not set as a "safe parameter".
I opened up app/models/issue.rb and added author_id on line 337.
So now that block of code looks like this:
safe_attributes 'tracker_id',
'status_id',
'category_id',
'author_id',
'assigned_to_id',
'priority_id',
'fixed_version_id',
'subject',
'description',
'start_date',
'due_date',
'done_ratio',
'estimated_hours',
'custom_field_values',
'custom_fields',
'lock_version',
'notes',
:if => lambda {|issue, user| issue.new_record? || user.allowed_to?(:edit_issues, issue.project) }
EDIT
I think this might be a better solution in app/models/issue.rb (line 375)
After
safe_attributes 'parent_issue_id',
:if => lambda {|issue, user| (issue.new_record? || user.allowed_to?(:edit_issues, issue.project)) &&
user.allowed_to?(:manage_subtasks, issue.project)}
I added
safe_attributes 'author_id',
:if => lambda {|issue, user| issue.new_record? || user.allowed_to?(:admin, issue.project)}

Related

Elixir: ExAws: DynamoDB: query-filter

I'm using the library https://github.com/ex-aws/ex_aws_dynamo, and I'm having issues getting a working example of query-filter to work with query. I was hoping someone here has an example they could share.
Here's what I've tried, but it returns an error:
[
key_condition_expression: "highlight_request_id = :highlight_request_id",
expression_attribute_values: [
highlight_request_id: "c692e65e-618f-45a3-ac12-d8103e6444c8"
],
query_filter: %{
range_id: %{
attribute_value_list: ["9990-ORGANIZATION-Pampers"],
comparison_operator: "EQ"
}
}
]
and the error I get back:
{:error,
{"ValidationException",
"1 validation error detected: Value null at 'queryFilter.range_id.member.comparisonOperator' failed to satisfy constraint: Member must not be null"}}
I'm not sure what is considered to be null. Any thoughts?
Make sure your query is written like so (adapted from the ex_aws_dynamo tests):
ExAws.Dynamo.query("person", [
index_name: "email",
key_condition_expression: "#email = :email",
expression_attribute_names: %{"#email" => "email"},
expression_attribute_values: [email: "person#test.com", last_name: "Person"],
filter_expression: "last_name = :last_name"
]) |> ExAws.request()
I was able to run this successfully against my local table, you'll have to fill in the appropriate values for your model. In particular, you'll want to include the index_name, and use the filter_expression, rather than query_filter.
In your case, I believe you'd want something like
ExAws.Dynamo.query("person", [
index_name: "highlight_request_id", # assuming that's the name of the index
key_condition_expression: "#highlight_request_id = :highlight_request_id",
expression_attribute_names: %{"#highlight_request_id" => "highlight_request_id"},
expression_attribute_values: [highlight_request_id: "c692e65e-618f-45a3-ac12-d8103e6444c8", range_id: "9990-ORGANIZATION-Pampers"],
filter_expression: "range_id = :range_id"
]) |> ExAws.request()
Let me know if this gets you any closer - again, worked for me, using the latest version of ex_aws_dynamo (2.2.2, at the moment).

Boost elasticsearch result by popolarity in Rails with multi models

I have two models (Post and Comment) that I want to search with elasticsearch. The Post model has a field popolarity which is an integer that represent the popolarity of the post.
I am using the gem elasticsearch-model and now I want to search on Posts and Comments with one query, this works fine with
Elasticsearch::Model.search('search string', [Post, Comment])
Now I want to add an option to boost the Post elements by it's popolarity field like described in Boosting by Popularity. Is this possible with the Ruby API I tried sth. like
Elasticsearch::Model.search('antilope', [Post, Comment], field_value_factor: {field: 'clicks'})
but this gives me this error
ArgumentError: URL parameter 'field_value_factor' is not supported
You should be able to do it by passing a full-fledge function-score query like this:
Elasticsearch::Model.search({
"query": {
"function_score": {
"query": {
"match": {
"_all": "antilope"
}
},
"field_value_factor": {
"field": "clicks"
}
}
}
}, [Post, Comment])

How to POST to server with null Related Resource in TastyPie?

I've got the following two models. They are linked by a OneToOneField relation 'mission' going from the TextMission table to the Mission table.
#Models.py
class Mission(models.Model):
name = models.CharField(max_length = 40)
class TextMission(models.Model):
mission = models.OneToOneField(Mission, related_name="text_mission", primary_key = True)
Sometimes missions will have a corresponding TextMission, but not always. I'm able to get everything working when I'm creating/updating objects in the shell, but TastyPie only handles requests correctly when there IS a TextMission (PUTing to /mission/{id}/). When text_mission=null, it craps out.
My tastypie config:
class MissionResource(ModelResource):
text_mission = fields.ToOneField('path.to.TextMissionResource', attribute='text_mission', related_name='mission', full = True, null = True)
class TextMissionResource(ModelResource):
mission = fields.ToOneField(MissionResource, attribute='mission', related_name='text_mission')
When PUTing the following JSON back to the server (the exact same JSON I received), I get a ValueError:
FAILS
{ "name": "TEST", "id": "1", "text_mission": null, "resource_uri":
"/api/web/mission/1/", }
*** ValueError: Cannot assign None: "Mission.text_mission" does not allow null values.
SUCCEEDS
{ "name": "TEST", "id": "1", "text_mission": {"id": "1", "resource_uri": "/api/web/text_mission/1/"}, "resource_uri":
"/api/web/mission/1/", }
Is there something I'm doing wrong in my code or it just not supposed to work this way. I'm at a loss here.
I'm running TastyPie 0.9.11.
I ended up figuring it out and it was a pretty dumb error. I just needed to add blank = True in addition to null = True:
class MissionResource(ModelResource):
text_mission = fields.ToOneField('path.to.TextMissionResource', attribute='text_mission', related_name='mission', full = True, blank = True, null = True)
That got everything working properly.

shoulda validate_inclusion_of not working

Recently upgraded a codebase to rails4 along with gems, now we're getting this error.
Failure/Error: it { is_expected.to ensure_inclusion_of(:usage).in_array(['Index', 'Slide', 'Body']).with_message("%{value} is not a valid usage") }
["Index", "Slide", "Body"] doesn't match array in validation
and here is the related model code
USAGES = ['Index', 'Slide', 'Body']
validates_inclusion_of :usage, :in => USAGES, :message => "%{value} is not a valid usage"
Is there something I'm missing? I don't understand why this is failing.
validate_inclusion_of uses allow_value internally. Admittedly, we should give you a better error message as to what's going on here, but you should be able to write the following tests to figure out what's happening:
it { should allow_value("Index").for(:usage) }
it { should allow_value("Slide").for(:usage) }
it { should allow_value("Body").for(:usage) }
it do
should_not allow_value("something else").
for(:usage).
with_message("%{value} is not a valid usage")
end
My guess is that shoulda-matchers isn't automatically interpolating the %{value} inside of your failure message. If this is true, then what I would do (after filing an issue) is extract the message to an i18n key, and then pass the name of the key to with_message instead.
worked for me -
expect { should validate_inclusion_of(:usage).in?(['a', 'b']) }
should try this -
validates :usage, inclusion: { :in => %w( Index Slide Body ), :message => "%{value} is not a valid usage" }

How to Populate koGrid Groups Array

I have a koGrid configured as follows:
var myItemsGrid = {
data: myItems,
columnDefs: [
{ field: 'item.title', displayName: 'Title', cellTemplate: $("#cdfUrlCellTemplate").html() },
{ field: 'item.dueTimeUtc', displayName: 'Due', cellFormatter: formatDate, sortFn: sortDates },
{ field: 'id', displayName: 'Edit', cellTemplate: $("#editCellTemplate").html() }
],
showGroupPanel: true,
groups: ['item.title'],
showFilter: false,
canSelectRows: false
};
My problem is that the groups array, which I have tried to populate using the field name of one of the fields in my grid, causes the following error:
TypeError: Cannot read property 'isAggCol' of undefined
How should I be populating the groups array so that I can set up initial grouping for my grid?
I had the same problem and took a different approach by sending an event to the grid control to group by the first heading. Something like this:
jQuery("#symbolPickerView").find(".kgGroupIcon").first().click();
This works until there is some sort of patch generally available.
I ended up having to patch the koGrid script to get the initial grouping of columns to work.
If anyone else has the problem I'm happy to provide the patched script. I will look at making a pull request to get the fix into the koGrid repository after putting it through its paces a bit more.