code
stringlengths 26
124k
| docstring
stringlengths 23
125k
| func_name
stringlengths 1
98
| language
stringclasses 1
value | repo
stringlengths 5
53
| path
stringlengths 7
151
| url
stringlengths 50
211
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
def update
# We use `duplicate_of_number` on the view and `duplicate_of_id` in the
# backend, so we need to copy between those values.
add_error = false
if (number = params[:bug].delete('duplicate_of_number')).present?
original_bug = @environment.bugs.where(number: number).first
if original_bug
@bug.duplicate_of_id = original_bug.id
else
add_error = true
end
else
@bug.duplicate_of_id = nil
end
# hacky fix for the JIRA status dropdown
params[:bug][:jira_status_id] = params[:bug][:jira_status_id].presence
if !add_error && @bug.update_attributes(bug_params)
if params[:comment].kind_of?(Hash) && params[:comment][:body].present?
@comment = @bug.comments.build(comment_params)
@comment.user = current_user
@comment.save
end
if params[:notification_threshold]
if params[:notification_threshold][:threshold].blank? && params[:notification_threshold][:period].blank?
current_user.notification_thresholds.where(bug_id: @bug.id).delete_all
else
@notification_threshold = current_user.notification_thresholds.where(bug_id: @bug.id).create_or_update(notification_threshold_params)
end
end
else
@bug.errors.add :duplicate_of_id, :not_found if add_error
@bug.errors[:duplicate_of_id].each { |error| @bug.errors.add :duplicate_of_number, error }
end
respond_with @project, @environment, @bug.reload # reload to grab the new cached counter values
end | Updates the bug management and tracking information for a Bug.
Routes
------
* `PATCH /projects/:project_id/environments/:environment_id/bugs/:id.json`
Path Parameters
---------------
| | |
|:-----|:-------------------------|
| `id` | The Bug number (not ID). |
Body Parameters
---------------
The body can be JSON- or form URL-encoded.
| | |
|:----------|:--------------------------------------------------------------------------------------|
| `bug` | A parameterized hash of Bug fields. |
| `comment` | A parameterized hash of fields for a Comment to be created along with the Bug update. | | update | ruby | SquareSquash/web | app/controllers/bugs_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/bugs_controller.rb | Apache-2.0 |
def destroy
@bug.destroy
respond_to do |format|
format.html { redirect_to project_environment_bugs_url(@project, @environment), flash: {success: t('controllers.bugs.destroy.deleted', number: number_with_delimiter(@bug.number))} }
end
end | Deletes a Bug. (Ideally it's one that probably won't just recur in a few
days.)
Routes
------
* `DELETE /projects/:project_id/environments/:environment_id/bugs/:id.json`
Path Parameters
---------------
| | |
|:-----|:-------------------------|
| `id` | The Bug number (not ID). | | destroy | ruby | SquareSquash/web | app/controllers/bugs_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/bugs_controller.rb | Apache-2.0 |
def watch
if (watch = current_user.watches?(@bug))
watch.destroy
else
watch = current_user.watches.where(bug_id: @bug.id).find_or_create
end
respond_to do |format|
format.json do
head(watch.destroyed? ? :no_content : :created)
end
end
end | Toggles a Bug as watched or unwatched (see {Watch}).
Routes
------
* `POST /projects/:project_id/environments/:environment_id/bugs/:id/watch.json`
Path Parameters
---------------
| | |
|:-----|:-------------------------|
| `id` | The Bug number (not ID). | | watch | ruby | SquareSquash/web | app/controllers/bugs_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/bugs_controller.rb | Apache-2.0 |
def notify_occurrence
Bug.transaction do
find_bug
list = @bug.notify_on_occurrence
if list.include?(current_user.id)
list.delete current_user.id
else
list << current_user.id
end
@bug.notify_on_occurrence = list
@bug.save!
end
respond_to do |format|
format.json { render json: decorate_bug(@bug), location: project_environment_bug_url(@project, @environment, @bug) }
end
end | Toggles on or off email notifications to the current user when new
Occurrences of this Bug are received.
Routes
------
* `POST /projects/:project_id/environments/:environment_id/bugs/:id/notify_occurrence.json`
Path Parameters
---------------
| | |
|:-----|:-------------------------|
| `id` | The Bug number (not ID). | | notify_occurrence | ruby | SquareSquash/web | app/controllers/bugs_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/bugs_controller.rb | Apache-2.0 |
def index
@comments = @bug.comments.order('created_at DESC').limit(50).includes(:user)
last = params[:last].present? ? @bug.comments.find_by_number(params[:last]) : nil
@comments = @comments.where(infinite_scroll_clause('created_at', 'DESC', last, 'comments.number')) if last
respond_with @project, @environment, @bug, (request.format == :json ? decorate(@comments) : @comments)
end | Returns a infinitely scrollable list of Comments.
Routes
------
* `GET /projects/:project_id/environments/:environment_id/bugs/:bug_id/comments.json`
Query Parameters
----------------
| | |
|:-------|:--------------------------------------------------------------------------------------------------------------|
| `last` | The number of the last Comment of the previous page; used to determine the start of the next page (optional). | | index | ruby | SquareSquash/web | app/controllers/comments_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/comments_controller.rb | Apache-2.0 |
def create
@comment = @bug.comments.build(comment_params)
@comment.user = current_user
@comment.save
respond_with @project, @environment, @bug, @comment
end | Posts a Comment on a bug as the current user.
Routes
------
* `POST /projects/:project_id/environments/:environment_id/bugs/:bug_id/comments.json`
Body Parameters
---------------
Body parameters can be JSON- or form URL-encoded.
| | |
|:----------|:--------------------------------------|
| `comment` | Parameterized hash of Comment fields. | | create | ruby | SquareSquash/web | app/controllers/comments_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/comments_controller.rb | Apache-2.0 |
def update
@comment.update_attributes comment_params
respond_with @project, @environment, @bug, @comment
end | Edits a Comment.
Routes
------
* `PATCH /projects/:project_id/environments/:environment_id/bugs/:bug_id/comments/:id.json`
Path Parameters
---------------
| | |
|:-----|:-----------------------------|
| `id` | The Comment number (not ID). |
Body Parameters
---------------
Body parameters can be JSON- or form URL-encoded.
| | |
|:----------|:--------------------------------------|
| `comment` | Parameterized hash of Comment fields. | | update | ruby | SquareSquash/web | app/controllers/comments_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/comments_controller.rb | Apache-2.0 |
def destroy
@comment.destroy
head :no_content
end | Deletes a Comment.
Routes
------
* `DELETE /projects/:project_id/environments/:environment_id/bugs/:bug_id/comments/:id.json`
Path Parameters
---------------
| | |
|:-----|:-----------------------------|
| `id` | The Comment number (not ID). | | destroy | ruby | SquareSquash/web | app/controllers/comments_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/comments_controller.rb | Apache-2.0 |
def index
@emails = current_user.emails.redirected.
where(project_id: @project.try!(:id)).
order('email ASC').
limit(10).
includes(:user)
@emails = @emails.where('LOWER(email) LIKE ?', params[:query].downcase + '%') if params[:query].present?
respond_with @emails do |format|
format.json { render json: decorate(@emails) }
end
end | Returns a list of the first 10 Emails belonging to the current User,
optionally only those under a {Project}.
Routes
------
* `GET /account/emails.json`
* `GET /projects/:project_id/membership/emails.json`
Path Parameters
---------------
| | |
|:-------------|:----------------------|
| `project_id` | The {Project}'s slug. |
Query Parameters
----------------
| | |
|:--------|:-----------------------------------------------------------------------------------------|
| `query` | If set, includes only those Emails whose address begins with `query` (case-insensitive). | | index | ruby | SquareSquash/web | app/controllers/emails_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/emails_controller.rb | Apache-2.0 |
def destroy
@email.destroy
respond_with @email
end | Removes a redirecting (non-primary) Email from the current User.
Routes
------
* `DELETE /account/emails/:id.json`
Path Parameters
---------------
| | |
|:-----|:-------------------|
| `id` | The email address. | | destroy | ruby | SquareSquash/web | app/controllers/emails_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/emails_controller.rb | Apache-2.0 |
def update
@environment.update_attributes environment_params
respond_with @environment, location: project_url(@project)
end | Edits an Environment. Only the Project owner or an admin can modify an
Environment.
Routes
------
* `PATCH /projects/:project_id/environments/:id.json`
Path Parameters
---------------
| | |
|:-----|:------------------------|
| `id` | The Environment's name. |
Body Parameters
---------------
The body can be JSON- or form URL-encoded.
| | |
|:--------------|:------------------------------------------|
| `environment` | Parameterized hash of Environment fields. | | update | ruby | SquareSquash/web | app/controllers/environments_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/environments_controller.rb | Apache-2.0 |
def index
@events = @bug.events.order('created_at DESC').limit(50).includes({user: :emails}, bug: {environment: {project: :slugs}})
last = params[:last].present? ? @bug.events.find_by_id(params[:last]) : nil
@events = @events.where(infinite_scroll_clause('created_at', 'DESC', last, 'events.id')) if last
Event.preload @events
respond_with @project, @environment, @bug, (request.format == :json ? decorate(@events) : @events)
end | Returns a infinitely scrollable list of Events.
Routes
------
* `GET /projects/:project_id/environments/:environment_id/bugs/:bug_id/events.json`
Query Parameters
----------------
| | |
|:-------|:------------------------------------------------------------------------------------------------------------|
| `last` | The number of the last Event of the previous page; used to determine the start of the next page (optional). | | index | ruby | SquareSquash/web | app/controllers/events_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/events_controller.rb | Apache-2.0 |
def create
@notification_threshold = current_user.notification_thresholds.where(bug_id: @bug.id).create_or_update(notification_threshold_params)
respond_with @notification_threshold, location: project_environment_bug_url(@project, @environment, @bug)
end | Creates a new NotificationThreshold from the given attributes.
Routes
------
* `POST /projects/:project_id/environments/:environment_id/bugs/:bug_id/notification_threshold`
Path Parameters
---------------
| | |
|:------------------|:-------------------------------------------------------------------------------------------------------|
| `:project_id` | The slug of a {Project}. |
| `:environment_id` | The name of an {Environment} within that Project. |
| `:bug_id` | The number of a {Bug} within that Environment. The NotificationThreshold will be created for this Bug. |
Body Parameters
---------------
| | |
|:-------------------------|:-----------------------------------------------------------------|
| `notification_threshold` | A parameterized hash of NotificationThreshold fields and values. | | create | ruby | SquareSquash/web | app/controllers/notification_thresholds_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/notification_thresholds_controller.rb | Apache-2.0 |
def update
@notification_threshold = current_user.notification_thresholds.where(bug_id: @bug.id).create_or_update(notification_threshold_params)
respond_with @notification_threshold, location: project_environment_bug_url(@project, @environment, @bug)
end | Updates a NotificationThreshold with the given attributes.
Routes
------
* `PATCH /projects/:project_id/environments/:environment_id/bugs/:bug_id/notification_threshold`
Path Parameters
---------------
| | |
|:------------------|:--------------------------------------------------|
| `:project_id` | The slug of a {Project}. |
| `:environment_id` | The name of an {Environment} within that Project. |
| `:bug_id` | The number of a {Bug} within that Environment. |
Body Parameters
---------------
| | |
|:-------------------------|:-----------------------------------------------------------------|
| `notification_threshold` | A parameterized hash of NotificationThreshold fields and values. | | update | ruby | SquareSquash/web | app/controllers/notification_thresholds_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/notification_thresholds_controller.rb | Apache-2.0 |
def destroy
current_user.notification_thresholds.where(bug_id: @bug.id).delete_all
respond_to do |format|
format.json { head :no_content }
format.html { redirect_to project_environment_bug_url(@project, @environment, @bug, anchor: 'notifications') }
end
end | Deletes a NotificationThreshold.
Routes
------
* `DELETE /projects/:project_id/environments/:environment_id/bugs/:bug_id/notification_threshold`
Path Parameters
---------------
| | |
|:------------------|:--------------------------------------------------|
| `:project_id` | The slug of a {Project}. |
| `:environment_id` | The name of an {Environment} within that Project. |
| `:bug_id` | The number of a {Bug} within that Environment. | | destroy | ruby | SquareSquash/web | app/controllers/notification_thresholds_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/notification_thresholds_controller.rb | Apache-2.0 |
def index
respond_to do |format|
format.json do
dir = params[:dir]
dir = 'DESC' unless SORT_DIRECTIONS.include?(dir.try!(:upcase))
@occurrences = @bug.occurrences.order("occurred_at #{dir}").limit(50)
last = params[:last].present? ? @bug.occurrences.find_by_number(params[:last]) : nil
@occurrences = @occurrences.where(infinite_scroll_clause('occurred_at', dir, last, 'occurrences.number')) if last
render json: decorate(@occurrences)
end
format.atom { @occurrences = @bug.occurrences.order('occurred_at DESC').limit(100) } # index.atom.builder
end
end | Generally, displays a list of Occurrences.
JSON
====
Returns a infinitely scrollable list of Occurrences.
Routes
------
* `GET /projects/:project_id/environments/:environment_id/bugs/:bug_id/occurrences.json`
Query Parameters
----------------
| | |
|:-------|:-----------------------------------------------------------------------------------------------------------------|
| `last` | The number of the last Occurrence of the previous page; used to determine the start of the next page (optional). |
Atom
====
Returns a feed of the most recent Occurrences of a Bug.
Routes
------
* `GET /projects/:project_id/environments/:environment_id/bugs/:bug_id/occurrences.atom` | index | ruby | SquareSquash/web | app/controllers/occurrences_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/occurrences_controller.rb | Apache-2.0 |
def aggregate
dimensions = Array.wrap(params[:dimensions]).reject(&:blank?)
dimensions.uniq!
return head(:unprocessable_entity) if dimensions.size > 4 || dimensions.any? { |d| !Occurrence::AGGREGATING_FIELDS.include?(d) }
if dimensions.empty?
return respond_to do |format|
format.json { render json: [].to_json }
end
end
dimensions.map!(&:to_sym)
occurrences = @bug.occurrences.
where("occurred_at >= ?", 30.days.ago).
order('occurred_at ASC').
limit(MAX_AGGREGATED_RECORDS)
# create a hash mapping dimension names to a hash mapping dimension values
# to a hash mapping timestmaps to the bucket count of that value in that
# time period:
#
# {
# 'operating_system' => {
# 'Mac OS X' => {
# <9/1 12 AM> => 12
# }
# }
# }
#
# In addition, build a hash of total occurrences for each time bucket:
#
# {
# 'operating_system' => {
# <9/1 12 AM> => 12
# }
# }
dimension_values = dimensions.inject({}) { |hsh, dim| hsh[dim] = {}; hsh }
totals = Hash.new(0)
top_values = dimensions.inject({}) { |hsh, dim| hsh[dim] = Hash.new(0); hsh }
occurrences.each do |occurrence|
time = occurrence.occurred_at.change(min: 0, sec: 0, usec: 0).to_i * 1000
dimensions.each do |dimension|
dimension_values[dimension][occurrence.send(dimension)] ||= Hash.new(0)
dimension_values[dimension][occurrence.send(dimension)][time] += 1
top_values[dimension][occurrence.send(dimension)] += 1
end
totals[time] += 1
end
top_values.each do |dimension, value_totals|
top_values[dimension] = value_totals.sort_by(&:last).reverse.map(&:first)[0, 5]
end
# convert it to a hash mapping dimension names to an array of hashes each
# with two keys: label (the value) and data (an array of points, x being the
# timestamp (ms) and y being the percentage of occurrences in that time
# bucket with that value):
#
# {
# 'operating_system' => [
# {label: 'Mac OS X', data: [[9/1 12 AM, 100%]]}
# ]
# }
dimension_values.each do |dim, values|
dimension_values[dim] = Array.new
values.each do |value, times|
next unless top_values[dim].include?(value)
series = {label: value, data: []}
dimension_values[dim] << series
totals.each do |time, total|
series[:data] << [time, total.zero? ? 0 : (times[time]/total.to_f)*100]
end
end
end
respond_to do |format|
format.json { render json: dimension_values.to_json }
end
end | Returns aggregate information about Occurrences across up to four
dimensions. Values are aggregated by time and partitioned by dimension value
combinations.
A time range must be specified. Regardless of the time range, only up to a
maximum of {MAX_AGGREGATED_RECORDS} is loaded.
Routes
------
* `GET /projects/:project_id/environments/:environment_id/bugs/:bug_id/occurrences/aggregate.json`
Query Parameters
----------------
| | |
|:-------------|:-----------------------------------------------------------------------------------------------------------|
| `dimensions` | A parameterized array of up to four dimensions. All must be {Occurrence::AGGREGATING_FIELDS valid fields}. |
| `size` | The number of buckets (and thus, the time range). |
| `step` | The time interval to bucket results by (milliseconds). | | aggregate | ruby | SquareSquash/web | app/controllers/occurrences_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/occurrences_controller.rb | Apache-2.0 |
def show
respond_with @project, @environment, @bug
end | Displays a page with detailed information about an Occurrence.
Routes
------
* `GET /projects/:project_id/environments/:environment_id/bugs/:bug_id/occurrences/:id.json`
Query Parameters
----------------
| | |
|:-----|:--------------------------------|
| `id` | The Occurrence number (not ID). | | show | ruby | SquareSquash/web | app/controllers/occurrences_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/occurrences_controller.rb | Apache-2.0 |
def index
respond_to do |format|
format.html # index.html.rb
format.json do
@projects = Project.includes(:owner).order('id DESC').limit(25)
@projects = @projects.prefix(params[:query]) if params[:query].present?
render json: decorate(@projects).to_json
end
end
end | HTML
====
Displays a home page with summary information of {Bug Bugs} across the
current user's Projects, a filterable list of project Memberships, and
information about the current User.
Routes
------
* `GET /`
JSON
====
Searches for Projects with a given prefix.
Routes
------
* `GET /projects.json`
Query Parameters
----------------
| | |
|:--------|:--------------------------------------------------------------------------------|
| `query` | Only includes those projects whose name begins with `query` (case-insensitive). | | index | ruby | SquareSquash/web | app/controllers/projects_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/projects_controller.rb | Apache-2.0 |
def show
if @project.default_environment && params[:show_environments].blank?
return redirect_to project_environment_bugs_url(@project, @project.default_environment)
end
respond_with @project
end | If the Project has a default {Environment}, and the `show_environments`
parameter is not set, redirects to the Bug list for that Environment.
Otherwise, displays information about the Project and a list of
Environments.
Routes
------
* `GET /projects/:id`
Path Parameters
---------------
| | |
|:-----|:--------------------|
| `id` | The Project's slug. | | show | ruby | SquareSquash/web | app/controllers/projects_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/projects_controller.rb | Apache-2.0 |
def create
project_attrs = project_params_for_creation.merge(validate_repo_connectivity: true)
@project = current_user.owned_projects.create(project_attrs)
respond_with @project do |format|
format.json do
if @project.valid?
render json: decorate(@project).to_json, status: :created
else
render json: {project: @project.errors.as_json}.to_json, status: :unprocessable_entity
end
end
end
end | Creates a new Project owned by the current User.
Routes
------
* `POST /projects.json`
Body Parameters
---------------
The body can be JSON- or form URL-encoded.
| | |
|:----------|:--------------------------------------|
| `project` | Parameterized hash of Project fields. | | create | ruby | SquareSquash/web | app/controllers/projects_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/projects_controller.rb | Apache-2.0 |
def edit
respond_with @project
end | Displays a page where the user can see information about how to install
Squash into his/her project, and how to configure his/her project for Squash
support.
Routes
------
* `GET /projects/:id/edit`
Path Parameters
---------------
| | |
|:-----|:--------------------|
| `id` | The Project's slug. | | edit | ruby | SquareSquash/web | app/controllers/projects_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/projects_controller.rb | Apache-2.0 |
def update
@project.assign_attributes project_params_for_update.merge(validate_repo_connectivity: true)
@project.uses_releases_override = true if @project.uses_releases_changed?
@project.save
respond_with @project
end | Edits a Project. Only the Project owner or an admin can modify a project.
Routes
------
* `PATCH /projects/:id.json`
Path Parameters
---------------
| | |
|:-----|:--------------------|
| `id` | The Project's slug. |
Body Parameters
---------------
The body can be JSON- or form URL-encoded.
| | |
|:----------|:--------------------------------------|
| `project` | Parameterized hash of Project fields. | | update | ruby | SquareSquash/web | app/controllers/projects_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/projects_controller.rb | Apache-2.0 |
def rekey
@project.create_api_key
@project.save!
redirect_to edit_project_url(@project), flash: {success: t('controllers.projects.rekey.success', name: @project.name, api_key: @project.api_key)}
end | Generates a new API key for the Project.. Only the Project owner can do
this.
Routes
------
* `PATCH /projects/:id/rekey`
Path Parameters
---------------
| | |
|:-----|:--------------------|
| `id` | The Project's slug. | | rekey | ruby | SquareSquash/web | app/controllers/projects_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/projects_controller.rb | Apache-2.0 |
def destroy
@project.destroy
redirect_to root_url, flash: {success: t('controllers.projects.destroy.deleted', name: @project.name)}
end | Deletes a Project, and all associated Environments, Bugs, Occurrences, etc.
Probably want to confirm before allowing the user to do this.
Routes
------
* `DELETE /projects/:id.json`
Path Parameters
---------------
| | |
|:-----|:--------------------|
| `id` | The Project's slug. | | destroy | ruby | SquareSquash/web | app/controllers/projects_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/projects_controller.rb | Apache-2.0 |
def search
words = params[:query].split(/\s+/).reject(&:blank?)
url = nil
case words.size
when 1
if words.first.starts_with?('@')
user = find_users(words.first[1..-1]).only
url = user_url(user) if user
else
project = find_projects(words[0]).only.try!(:sluggable)
url = project_url(project) if project
end
when 2
project = find_projects(words[0]).only.try!(:sluggable)
env = find_environments(project, words[1]).only if project
url = project_environment_bugs_url(project, env) if env
when 3
project = find_projects(words[0]).only.try!(:sluggable)
env = find_environments(project, words[1]).only if project
bug = env.bugs.find_by_number(words[2].to_i) if env
url = project_environment_bug_url(project, env, bug) if bug
when 4
project = find_projects(words[0]).only.try!(:sluggable)
env = find_environments(project, words[1]).only if project
bug = env.bugs.find_by_number(words[2].to_i) if env
occurrence = bug.occurrences.find_by_number(words[3].to_i) if bug
url = project_environment_bug_occurrence_url(project, env, bug, occurrence) if occurrence
end
url ? render(text: url) : head(:ok)
end | Returns a search result for a query in the search field. If the query
consists of recognized names or prefixes, and resolves to a single page, the
response will be 200 OK, and the body will be the URL. Otherwise, the
response will be 200 OK with an empty body.
Routes
------
* `GET /search`
Query Parameters
----------------
| | |
|:--------|:------------------|
| `query` | The search query. | | search | ruby | SquareSquash/web | app/controllers/search_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/search_controller.rb | Apache-2.0 |
def suggestions
words = params[:query].split(/\s+/).reject(&:blank?)
suggestions = case words.size
when 1
if words.first.starts_with?('@')
users = find_users(words.first[1..-1]).limit(MAX_SUGGESTIONS)
users.map do |user|
{
user: user.as_json,
url: user_url(user),
type: 'user'
}
end
else
projects = find_projects(words[0]).limit(MAX_SUGGESTIONS).map(&:sluggable).compact
projects.map do |project|
{
project: project.as_json,
url: project_url(project),
type: 'project',
}
end
end
when 2
project = find_projects(words[0]).only.try!(:sluggable)
envs = find_environments(project, words[1]).limit(10) if project
envs.map do |env|
{
project: project.as_json,
environment: env.as_json,
type: 'environment',
url: project_environment_bugs_url(project, env)
}
end if project
when 3
project = find_projects(words[0]).only.try!(:sluggable)
env = find_environments(project, words[1]).only if project
bug = env.bugs.find_by_number(words[2].to_i) if env
[{
type: 'bug',
url: project_environment_bug_url(project, env, bug),
project: project.as_json,
environment: env.as_json,
bug: bug.as_json
}] if bug
when 4
project = find_projects(words[0]).only.try!(:sluggable)
env = find_environments(project, words[1]).only if project
bug = env.bugs.find_by_number(words[2].to_i) if env
occurrence = bug.occurrences.find_by_number(words[3].to_i) if bug
[{
type: 'occurrence',
url: project_environment_bug_occurrence_url(project, env, bug, occurrence),
project: project.as_json,
environment: env.as_json,
bug: bug.as_json,
occurrence: occurrence.as_json
}] if occurrence
end
respond_to do |format|
format.json { render json: (suggestions || []).to_json }
end
end | Returns a JSON-formatted array of possible completions given a search query.
Completion is supported for usernames, Project names, and Environment names
only. If the query refers to a Bug or Occurrence, a single-element array is
returned with information on that object.
Routes
------
* `GET /search/suggestions`
Query Parameters
----------------
| | |
|:--------|:------------------|
| `query` | The search query. |
Response JSON
-------------
The response JSON will be an array of hashes, each with the following keys:
| Field name | When included | Description |
|:--------------|:-----------------------------------------|:----------------------------------------------------------|
| `type` | always | "user", "project", "environment", "bug", or "occurrence". |
| `url` | always | The URL to the suggestion object. |
| `user` | User results only | Hash of information about the User. |
| `project` | all except User results | Hash of information about the Project. |
| `environment` | Environment, Bug, and Occurrence results | Hash of information about the Environment. |
| `bug` | Bug and Occurrence results | Hash of information about the Bug. |
| `occurrence` | Occurrence results only | Hash of information about the Occurrence. | | suggestions | ruby | SquareSquash/web | app/controllers/search_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/search_controller.rb | Apache-2.0 |
def create
if params[:username].blank? || params[:password].blank?
return respond_to do |format|
format.html do
flash.now[:alert] = t('controllers.sessions.create.missing_field')
render 'new'
end
end
end
if log_in(params[:username], params[:password])
respond_to do |format|
format.html do
flash[:success] = t('controllers.sessions.create.logged_in', name: current_user.first_name || current_user.username)
redirect_to(params[:next].presence || root_url)
end
end
else
respond_to do |format|
format.html do
flash.now[:alert] ||= t('controllers.sessions.create.incorrect_login')
render 'new'
end
end
end
end | Attempts to log a user in. If login fails, or the LDAP server is
unreachable, renders the `new` page with a flash alert.
If the login is successful, takes the user to the next URL stored in the
params; or, if none is set, the root URL.
Routes
------
* `POST /login`
Request Parameters
------------------
| | |
|:-------|:------------------------------------------------|
| `next` | A URL to redirect to after login is successful. |
Body Parameters
---------------
| | |
|:-----------|:-----------------------|
| `username` | The {User}'s username. |
| `password` | The User's password. | | create | ruby | SquareSquash/web | app/controllers/sessions_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/sessions_controller.rb | Apache-2.0 |
def destroy
log_out
redirect_to login_url, notice: t('controllers.sessions.destroy.logged_out')
end | Logs a user out and clears his/her session. Redirects to the login URL.
Routes
------
* `GET /logout` | destroy | ruby | SquareSquash/web | app/controllers/sessions_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/sessions_controller.rb | Apache-2.0 |
def create
unless Squash::Configuration.authentication.registration_enabled?
return redirect_to(login_url, alert: t('controllers.users.create.disabled'))
end
@user = User.create(user_params)
respond_with @user do |format|
format.html do
if @user.valid?
log_in_user @user
flash[:success] = t('controllers.users.create.success', name: @user.first_name || @user.username)
redirect_to (params[:next].presence || root_url)
else
render 'sessions/new'
end
end
end
end | Creates a new User account. For password authenticating installs only. The
`email_address` and `password_confirmation` virtual fields must be
specified.
If the signup is successful, takes the user to the next URL stored in the
params; or, if none is set, the root URL.
Routes
------
* `POST /users`
Request Parameters
| | |
|:-------|:-------------------------------------------|
| `next` | The URL to go to after signup is complete. |
Body Parameters
---------------
| | |
|:-------|:-------------------------|
| `user` | The new User parameters. | | create | ruby | SquareSquash/web | app/controllers/users_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/users_controller.rb | Apache-2.0 |
def index
if params[:type].try!(:downcase) == 'watched'
watches = current_user.watches.order('created_at DESC').includes(bug: [{environment: :project}, :assigned_user]).limit(PER_PAGE)
last = params[:last].present? ? current_user.watches.joins(:bug).where(bug_id: params[:last]).first : nil
watches = watches.where(infinite_scroll_clause('created_at', 'DESC', last, 'watches.bug_id')) if last
@bugs = watches.map(&:bug)
else
@bugs = current_user.assigned_bugs.order('latest_occurrence DESC, bugs.number DESC').limit(PER_PAGE).includes(:assigned_user, environment: :project)
last = params[:last].present? ? current_user.assigned_bugs.find_by_number(params[:last]) : nil
@bugs = @bugs.where(infinite_scroll_clause('latest_occurrence', 'DESC', last, 'bugs.number')) if last
end
respond_with decorate(@bugs)
end | Powers a table of a User's watched or assigned Bugs; returns a paginating
list of 50 Bugs, chosen according to the query parameters.
Routes
------
* `GET /account/bugs.json`
Query Parameters
----------------
| | |
|:-------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `type` | If `watched`, returns Bugs the User is watching. Otherwise, returns Bugs the User is assigned to. |
| `last` | The ID (`type` is `watched`) or number (`type` is not `watched`) of the last Bug of the previous page; used to determine the start of the next page (optional). | | index | ruby | SquareSquash/web | app/controllers/account/bugs_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/account/bugs_controller.rb | Apache-2.0 |
def index
event_ids = current_user.user_events.order('created_at DESC').limit(PER_PAGE)
last = params[:last].present? ? current_user.user_events.find_by_event_id(params[:last]) : nil
event_ids = event_ids.where(infinite_scroll_clause('created_at', 'DESC', last, 'event_id')) if last
@events = Event.where(id: event_ids.pluck(:event_id)).order('created_at DESC').includes({user: :emails}, bug: {environment: {project: :slugs}})
Event.preload @events.to_a
respond_with decorate(@events)
end | Returns a infinitely scrollable list of Events.
Routes
------
* `GET /account/events.json`
Query Parameters
----------------
| | |
|:-------|:------------------------------------------------------------------------------------------------------------|
| `last` | The number of the last Event of the previous page; used to determine the start of the next page (optional). | | index | ruby | SquareSquash/web | app/controllers/account/events_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/account/events_controller.rb | Apache-2.0 |
def decorate(events)
super.zip(events).map do |(hsh, event)|
hsh.merge(
bug: event.bug.as_json.merge(
url: project_environment_bug_url(event.bug.environment.project, event.bug.environment, event.bug)
),
environment: event.bug.environment.as_json,
project: event.bug.environment.project.as_json
)
end
end | probably not the best way to do this | decorate | ruby | SquareSquash/web | app/controllers/account/events_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/account/events_controller.rb | Apache-2.0 |
def index
@memberships = current_user.memberships.order('memberships.created_at DESC').limit(10)
@memberships = @memberships.project_prefix(params[:query]) if params[:query].present?
# as much as i'd love to add includes(:project), it breaks the join in project_prefix.
# go ahead, try it and see.
render json: decorate(@memberships)
end | Returns a list of the 10 most recent Project Memberships belonging to the
current User.
Routes
------
* `GET /account/memberships.json`
Query Parameters
----------------
| | |
|:--------|:---------------------------------------------------------------------------------------------------|
| `query` | If set, includes only those Memberships whose Project name begins with `query` (case-insensitive). | | index | ruby | SquareSquash/web | app/controllers/account/memberships_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/account/memberships_controller.rb | Apache-2.0 |
def current_user
if session[:user_id] then
@current_user ||= User.find_by_id(session[:user_id])
else
nil
end
end | @return [User, nil] The currently logged-in User, or `nil` if the session is
unauthenticated. | current_user | ruby | SquareSquash/web | app/controllers/additions/authentication_helpers.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/additions/authentication_helpers.rb | Apache-2.0 |
def login_required
if logged_in? then
return true
else
respond_to do |format|
format.xml { head :unauthorized }
format.json { head :unauthorized }
format.atom { head :unauthorized }
format.html do
redirect_to login_url(next: request.fullpath), notice: t('controllers.authentication.login_required')
end
end
return false
end
end | A `before_filter` that requires an authenticated session to continue. If the
session is unauthenticated...
* for HTML requests, redirects to the login URL with a flash notice.
* for API and Atom requests, returns a 401 Unauthorized response with an
empty body. | login_required | ruby | SquareSquash/web | app/controllers/additions/authentication_helpers.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/additions/authentication_helpers.rb | Apache-2.0 |
def must_be_unauthenticated
if logged_in?
respond_to do |format|
format.xml { head :unauthorized }
format.json { head :unauthorized }
format.atom { head :unauthorized }
format.html { redirect_to root_url }
end
return false
else
return true
end
end | A `before_filter` that requires an unauthenticated session to continue. If
the session is authenticated...
* for HTML requests, redirects to the root URL.
* for API and Atom requests, returns a 401 Unauthorized response with an
empty body. | must_be_unauthenticated | ruby | SquareSquash/web | app/controllers/additions/authentication_helpers.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/additions/authentication_helpers.rb | Apache-2.0 |
def log_in_user(user)
session[:user_id] = user.id
@current_user = user
end | Sets the given user as the current user. Assumes that authentication has
already succeeded.
@param [User] user A user to log in. | log_in_user | ruby | SquareSquash/web | app/controllers/additions/authentication_helpers.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/additions/authentication_helpers.rb | Apache-2.0 |
def decorate(events)
events.map do |event|
project = @project || event.bug.environment.project
environment = @environment || event.bug.environment
bug = @bug || event.bug
json = event.as_json.merge(
icon: icon_for_event(event),
user_url: event.user ? user_url(event.user) : nil,
assignee_url: event.assignee ? user_url(event.assignee) : nil,
occurrence_url: event.occurrence ? project_environment_bug_occurrence_url(project, environment, bug, event.occurrence) : nil,
comment_body: event.comment ? markdown.(event.comment.body) : nil,
revision_url: event.data['revision'] ? project.commit_url(event.data['revision']) : nil,
user_you: event.user_id == current_user.id,
assignee_you: event.data['assignee_id'] == current_user.id
)
json[:original_url] = project_environment_bug_url(project, environment, bug.duplicate_of) if event.kind == 'dupe' && bug.duplicate_of
json
end
end | Decorates an array of events. This method will use the `@project`,
`@environment`, and `@bug` fields if set; otherwise it will use the
associated objects on the event.
@param [Array<Event>, ActiveRecord::Relation] events The events to decorate.
@return [Array<Hash<Symbol, Object>>] The decorated attributes. | decorate | ruby | SquareSquash/web | app/controllers/additions/event_decoration.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/additions/event_decoration.rb | Apache-2.0 |
def log_in(username, password)
username = username.downcase
username.sub! /@#{Regexp.escape Squash::Configuration.mailer.domain}$/, ''
dn = "#{Squash::Configuration.authentication.ldap.search_key}=#{username},#{Squash::Configuration.authentication.ldap.tree_base}"
ldap = build_ldap_interface
entry = nil
if Squash::Configuration.authentication.ldap[:bind_dn]
ldap.auth Squash::Configuration.authentication.ldap.bind_dn, Squash::Configuration.authentication.ldap.bind_password
if ldap.bind
if (entry = locate_ldap_user(ldap, username))
ldap.auth entry.dn, password
unless ldap.bind
logger.tagged('AuthenticationHelpers') { logger.info "Denying login to #{username}: LDAP authentication failed." }
return false
end
else
logger.tagged('AuthenticationHelpers') { logger.info "Denying login to #{username}: Couldn't locate user." }
end
else
logger.tagged('AuthenticationHelpers') { logger.info "Couldn't bind using authenticator DN." }
end
else
ldap.auth dn, password
if ldap.bind
entry = locate_ldap_user(ldap, username)
end
end
if entry
user = find_or_create_user_from_ldap_entry(entry, username)
log_in_user user
return true
else
logger.tagged('AuthenticationHelpers') { logger.info "Denying login to #{username}: LDAP authentication failed." }
return false
end
rescue Net::LDAP::LdapError
respond_to do |format|
format.html do
flash.now[:alert] = t('controllers.sessions.create.ldap_error')
return false
end
end
end | Attempts to log in a user, given his/her credentials. If the login fails,
the reason is logged and tagged with "[AuthenticationHelpers]". If the login
is successful, the user ID is written to the session. Also creates or
updates the User as appropriate.
@param [String] username The LDAP username.
@param [String] password The LDAP password.
@return [true, false] Whether or not the login was successful. | log_in | ruby | SquareSquash/web | app/controllers/additions/ldap_authentication_helpers.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/additions/ldap_authentication_helpers.rb | Apache-2.0 |
def log_in(username, password)
user = User.find_by_username(username)
if user && user.authentic?(password)
log_in_user user
return true
else
logger.tagged('AuthenticationHelpers') { logger.info "Denying login to #{username}: Invalid credentials." }
return false
end
end | Attempts to log in a user, given his/her credentials. If the login fails,
the reason is logged and tagged with "[AuthenticationHelpers]". If the login
is successful, the user ID is written to the session.
@param [String] username The username.
@param [String] password The password.
@return [true, false] Whether or not the login was successful. | log_in | ruby | SquareSquash/web | app/controllers/additions/password_authentication_helpers.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/additions/password_authentication_helpers.rb | Apache-2.0 |
def notify
BackgroundRunner.run OccurrencesWorker, request.request_parameters.to_hash
head :ok
end | API endpoint for exception notifications. Creates a new thread and
instantiates an {OccurrencesWorker} to process it.
Routes
------
* `POST /api/1.0/notify` | notify | ruby | SquareSquash/web | app/controllers/api/v1_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/api/v1_controller.rb | Apache-2.0 |
def deploy
require_params :project, :environment, :deploy
project = Project.find_by_api_key(params['project']['api_key']) or raise(API::UnknownAPIKeyError)
environment = project.environments.with_name(params['environment']['name']).find_or_create!(name: params['environment']['name'])
environment.deploys.create!(deploy_params)
head :ok
end | API endpoint for deploy or release notifications. Creates a new {Deploy}.
Routes
------
* `POST /api/1.0/deploy` | deploy | ruby | SquareSquash/web | app/controllers/api/v1_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/api/v1_controller.rb | Apache-2.0 |
def symbolication
require_params :symbolications
BackgroundRunner.run SymbolicationCreator, params.slice('symbolications')
head :created
end | API endpoint for uploading symbolication data. This data typically comes
from symbolicating scripts that run on compiled projects.
Routes
------
* `POST /api/1.0/symbolication` | symbolication | ruby | SquareSquash/web | app/controllers/api/v1_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/api/v1_controller.rb | Apache-2.0 |
def deobfuscation
require_params :api_key, :environment, :build, :namespace
BackgroundRunner.run ObfuscationMapCreator, params.slice('namespace', 'api_key', 'environment', 'build')
head :created
end | API endpoint for uploading deobfuscation data. This data typically comes
from a renamelog.xml file generated by yGuard.
Routes
------
* `POST /api/1.0/deobfuscation` | deobfuscation | ruby | SquareSquash/web | app/controllers/api/v1_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/api/v1_controller.rb | Apache-2.0 |
def sourcemap
require_params :api_key, :environment, :revision, :sourcemap, :from, :to
BackgroundRunner.run SourceMapCreator, params.slice('sourcemap', 'api_key', 'environment', 'revision', 'from', 'to')
head :created
end | API endpoint for uploading source-map data. This data typically comes from
scripts that upload source maps generated in the process of compiling and
minifying JavaScript assets.
Routes
------
* `POST /api/1.0/sourcemap` | sourcemap | ruby | SquareSquash/web | app/controllers/api/v1_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/api/v1_controller.rb | Apache-2.0 |
def show
respond_with(@issue) do |format|
format.json { render json: @issue.to_json }
end
end | Returns information about a JIRA issue.
* `GET /jira/issues/:id`
Path Parameters
---------------
| | |
|:-----|----------------------------------------|
| `id` | The JIRA issue key (e.g., "PROJ-123"). | | show | ruby | SquareSquash/web | app/controllers/jira/issues_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/jira/issues_controller.rb | Apache-2.0 |
def index
@projects = Service::JIRA.projects
respond_with(@projects) do |format|
format.json { render json: @projects.to_a.sort_by(&:name).map(&:attrs).to_json }
end
end | Returns a list of JIRA projects.
* `GET /jira/projects` | index | ruby | SquareSquash/web | app/controllers/jira/projects_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/jira/projects_controller.rb | Apache-2.0 |
def index
@statuses = Service::JIRA.statuses
respond_with(@statuses) do |format|
format.json { render json: @statuses.to_a.sort_by(&:name).map(&:attrs).to_json }
end
end | Returns a list of JIRA statuses.
* `GET /jira/statuses` | index | ruby | SquareSquash/web | app/controllers/jira/statuses_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/jira/statuses_controller.rb | Apache-2.0 |
def index
respond_to do |format|
format.json do
@memberships = @project.memberships.order('created_at DESC').limit(10)
@memberships = @memberships.user_prefix(params[:query]) if params[:query].present?
render json: decorate(@memberships)
end
end
end | Returns a list of the 10 most recently-created memberships to a project.
Routes
------
* `GET /projects/:project_id/memberships.json`
Query Parameters
----------------
| | |
|:--------|:---------------------------------------------------------------------------------------------------|
| `query` | If set, includes only those memberships where the username begins with `query` (case-insensitive). | | index | ruby | SquareSquash/web | app/controllers/project/memberships_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/project/memberships_controller.rb | Apache-2.0 |
def create
if params[:membership][:user_username]
params[:membership][:user_id] = User.find_by_username(params[:membership].delete('user_username')).try!(:id)
end
@membership = @project.memberships.create(membership_params)
respond_with @project, @membership
end | Adds a user to this project.
Routes
------
* `POST /projects/:project_id/memberships.json`
Body Parameters
---------------
The body parameters can be JSON- or form URL-encoded.
| | |
|:-------------|:-----------------------------------------|
| `membership` | Parameterized hash of Membership fields. | | create | ruby | SquareSquash/web | app/controllers/project/memberships_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/project/memberships_controller.rb | Apache-2.0 |
def update
@membership.update_attributes membership_params
respond_with @project, @membership
end | Alters a user's membership to this project.
Routes
------
* `PATCH /projects/:project_id/memberships/:id.json`
Path Parameters
---------------
| | |
|:-----|:-----------------------|
| `id` | The {User}'s username. |
Body Parameters
---------------
The body parameters can be JSON- or form URL-encoded.
| | |
|:-------------|:-----------------------------------------|
| `membership` | Parameterized hash of Membership fields. | | update | ruby | SquareSquash/web | app/controllers/project/memberships_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/project/memberships_controller.rb | Apache-2.0 |
def destroy
if current_user.role(@project) == :admin && @membership.admin?
return respond_to do |format|
format.json { head :forbidden }
end
end
@membership.destroy
head :no_content
end | Removes a user from this project.
Routes
------
* `DELETE /projects/:project_id/memberships/:id.json`
Path Parameters
---------------
| | |
|:-----|:---------------------|
| `id` | The User's username. | | destroy | ruby | SquareSquash/web | app/controllers/project/memberships_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/project/memberships_controller.rb | Apache-2.0 |
def join
@membership = @project.memberships.where(user_id: current_user.id).find_or_create! { |m| m.user = current_user }
respond_with @membership, location: project_url(@project)
end | Creates a new Membership linking this Project to the current User. The user
will have member privileges.
Routes
------
* `POST /projects/:project_id/membership/join`
Path Parameters
---------------
| | |
|:-------------|:----------------------------------------------------------------------|
| `project_id` | The Project's slug. |
| `next` | For HTML requests, the URL to be taken to next (default project URL). | | join | ruby | SquareSquash/web | app/controllers/project/membership_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/project/membership_controller.rb | Apache-2.0 |
def edit
respond_with @membership
end | Displays a form where a User can modify their Membership settings.
Routes
------
* `GET /projects/:project_id/membership/edit`
Path Parameters
---------------
| | |
|:-------------|:--------------------|
| `project_id` | The Project's slug. | | edit | ruby | SquareSquash/web | app/controllers/project/membership_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/project/membership_controller.rb | Apache-2.0 |
def update
@membership.update_attributes membership_params
respond_with @membership, location: edit_project_my_membership_url(@project)
end | Updates a User's email settings for this Membership's Project.
Routes
------
* `PATCH /projects/:project_id/membership`
Path Parameters
---------------
| | |
|:-------------|:--------------------|
| `project_id` | The Project's slug. |
Body Parameters
---------------
| | |
|:-------------|:-------------------------------------------------------|
| `membership` | Parameterized hash of new Membership attribute values. | | update | ruby | SquareSquash/web | app/controllers/project/membership_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/project/membership_controller.rb | Apache-2.0 |
def destroy
@membership.destroy
respond_with @membership do |format|
format.html { redirect_to account_url, flash: {success: t('controllers.project.membership.destroy.deleted', name: @membership.project.name)} }
end
end | Removes membership from a Project. A Project owner cannot leave his/her
Project without first reassigning ownership.
Routes
------
* `DELETE /project/:project_id/membership`
Path Parameters
---------------
| | |
|:-------------|:--------------------|
| `project_id` | The Project's slug. |
Responses
---------
### Deleting an owned project
If the User attempts to delete a Project s/he owns, a 401 Unauthorized
status is returned with an empty response body. | destroy | ruby | SquareSquash/web | app/controllers/project/membership_controller.rb | https://github.com/SquareSquash/web/blob/master/app/controllers/project/membership_controller.rb | Apache-2.0 |
def editor_link(editor, project, file, line)
content_tag :a, '', :'data-editor' => editor, :'data-file' => file, :'data-line' => line, :'data-project' => project.to_param
end | Creates a link to open a project file in the user's editor. See the
editor_link.js.coffee file for more information.
@param [String] editor The editor ("textmate", "sublime", "vim", "emacs",
or "rubymine").
@param [Project] project The project containing the file.
@param [String] file The file path relative to the project root.
@param [String] line The line number within the file. | editor_link | ruby | SquareSquash/web | app/helpers/application_helper.rb | https://github.com/SquareSquash/web/blob/master/app/helpers/application_helper.rb | Apache-2.0 |
def number_to_dms(coord, axis, options={})
positive = coord >= 0
coord = coord.abs
degrees = coord.floor
remainder = coord - degrees
minutes = (remainder*60).floor
remainder -= minutes/60.0
seconds = (remainder*60).round(options[:precision] || 2)
hemisphere = case axis
when :lat
t("helpers.application.number_to_dms.#{positive ? 'north' : 'south'}")
when :lon
t("helpers.application.number_to_dms.#{positive ? 'east' : 'west'}")
else
raise ArgumentError, "axis must be :lat or :lon"
end
t('helpers.application.number_to_dms.coordinate', degrees: degrees, minutes: minutes, seconds: seconds, hemisphere: hemisphere)
end | Converts a number in degrees decimal (DD) to degrees-minutes-seconds (DMS).
@param [Float] coord The longitude or latitude, in degrees.
@param [:lat, :lon] axis The axis of the coordinate value.
@param [Hash] options Additional options.
@option options [Fixnum] :precision (2) The precision of the seconds value.
@return [String] Localized display of the DMS value.
@raise [ArgumentError] If an axis other than `:lat` or `:lon` is given. | number_to_dms | ruby | SquareSquash/web | app/helpers/application_helper.rb | https://github.com/SquareSquash/web/blob/master/app/helpers/application_helper.rb | Apache-2.0 |
def format_backtrace_element(file, line, method=nil)
str = "#{file}:#{line}"
str << " (in `#{method}`)" if method
str
end | Given the parts of a backtrace element, creates a single string displaying
them together in a typical backtrace format.
@param [String] file The file path.
@param [Fixnum] line The line number in the file.
@param [String] method The method name. | format_backtrace_element | ruby | SquareSquash/web | app/helpers/application_helper.rb | https://github.com/SquareSquash/web/blob/master/app/helpers/application_helper.rb | Apache-2.0 |
def email_quote(text, level=1)
width = EMAIL_WRAP_WIDTH - level - 1
lines = word_wrap(text, line_width: width).split("\n")
lines.map!(&:lstrip)
lines.map! { |line| '>'*level + ' ' + line }
lines.join("\n")
end | Quotes a text block for email use. Adds chevron(s) and a space before each
line. Rewraps the content only as necessary to keep total width at 78
characters: Other line breaks are preserved.
@param [String] text The text to quote.
@param [Fixnum] level The quote level.
@return [String] The quoted text. | email_quote | ruby | SquareSquash/web | app/helpers/mail_helper.rb | https://github.com/SquareSquash/web/blob/master/app/helpers/mail_helper.rb | Apache-2.0 |
def email_rewrap(text, width=EMAIL_WRAP_WIDTH)
paragraphs = text.split("\n\n")
paragraphs.each { |para| para.gsub("\n", ' ') }
paragraphs.map! { |para| email_wrap para, width }
paragraphs.join("\n\n")
end | Rewraps content for email use. Double line breaks are considered to be new
paragraphs. Single line breaks are considered to be wraps and are replaced
with spaces. New line breaks are added as necessary.
@param [String] text The text to rewrap.
@param [Fixnum] width The new width to wrap to.
@return [String] The rewrapped text. | email_rewrap | ruby | SquareSquash/web | app/helpers/mail_helper.rb | https://github.com/SquareSquash/web/blob/master/app/helpers/mail_helper.rb | Apache-2.0 |
def email_wrap(text, width=EMAIL_WRAP_WIDTH)
lines = word_wrap(text, line_width: width).split("\n")
lines.map!(&:lstrip)
lines.join("\n")
end | Wraps content for email use. Similar to {#email_rewrap}, but existing line
breaks are preserved. New line breaks are added as necessary to keep total
line width under `width`.
@param [String] text The text to wrap.
@param [Fixnum] width The new width to wrap to.
@return [String] The wrapped text. | email_wrap | ruby | SquareSquash/web | app/helpers/mail_helper.rb | https://github.com/SquareSquash/web/blob/master/app/helpers/mail_helper.rb | Apache-2.0 |
def initial(bug)
@bug = bug
recipient = bug.environment.project.all_mailing_list
return nil unless should_send?(bug, recipient)
mail to: recipient,
from: project_sender(bug),
subject: I18n.t('mailers.notifier.initial.subject',
locale: bug.environment.project.locale,
class: bug.class_name,
filename: File.basename(bug.file),
project: bug.environment.project.name,
environment: bug.environment.name)
end | Creates a message addressed to the {Project}'s `all_mailing_list` informing
of a new Bug.
@param [Bug] bug The Bug that was just added.
@return [Mail::Message, nil] The email to deliver, or `nil` if no email
should be delivered. | initial | ruby | SquareSquash/web | app/mailers/notification_mailer.rb | https://github.com/SquareSquash/web/blob/master/app/mailers/notification_mailer.rb | Apache-2.0 |
def blame(bug)
@bug = bug
emails = bug.blamed_email
return nil unless should_send?(bug, emails)
mail to: emails,
from: project_sender(bug),
subject: I18n.t('mailers.notifier.blame.subject',
locale: bug.environment.project.locale,
class: bug.class_name,
filename: File.basename(bug.file),
project: bug.environment.project.name,
environment: bug.environment.name)
#TODO should be in an observer of some kind
bug.events.create!(kind: 'email', data: {recipients: Array.wrap(emails)})
end | Creates a message addressed to the engineer at fault for a bug informing him
of the new Bug.
@param [Bug] bug The Bug that was just added.
@return [Mail::Message, nil] The email to deliver, or `nil` if no email
should be delivered. | blame | ruby | SquareSquash/web | app/mailers/notification_mailer.rb | https://github.com/SquareSquash/web/blob/master/app/mailers/notification_mailer.rb | Apache-2.0 |
def reopened(bug)
@bug = bug
emails = bug.assigned_user.try!(:email) || bug.blamed_email
return nil unless should_send?(bug, emails)
mail to: emails,
from: project_sender(bug),
subject: I18n.t('mailers.notifier.reopened.subject',
locale: bug.environment.project.locale,
class: bug.class_name,
filename: File.basename(bug.file),
project: bug.environment.project.name,
environment: bug.environment.name)
end | Creates a message addressed to the assigned engineer (or the at-fault
engineer if no one is assigned) for a Bug informing him that the Bug has
been reopened.
@param [Bug] bug The Bug that was reopened.
@return [Mail::Message, nil] The email to deliver, or `nil` if no email
should be delivered. | reopened | ruby | SquareSquash/web | app/mailers/notification_mailer.rb | https://github.com/SquareSquash/web/blob/master/app/mailers/notification_mailer.rb | Apache-2.0 |
def critical(bug)
@bug = bug
recipient = bug.environment.project.critical_mailing_list
return nil unless should_send?(bug, recipient)
mail to: recipient,
from: project_sender(bug),
subject: I18n.t('mailers.notifier.critical.subject',
locale: bug.environment.project.locale,
class: bug.class_name,
filename: File.basename(bug.file),
project: bug.environment.project.name,
environment: bug.environment.name)
#TODO should be in an observer of some kind
bug.events.create!(kind: 'email', data: {recipients: [recipient]})
end | Creates a message addressed to the {Project}'s `critical_mailing_list`
informing of a Bug that has reached a critical number of
{Occurrence Occurrences}.
@param [Bug] bug The Bug that has "gone critical."
@return [Mail::Message, nil] The email to deliver, or `nil` if no email
should be delivered. | critical | ruby | SquareSquash/web | app/mailers/notification_mailer.rb | https://github.com/SquareSquash/web/blob/master/app/mailers/notification_mailer.rb | Apache-2.0 |
def assign(bug, assigner, assignee)
@bug = bug
@assigner = assigner
return nil unless should_send?(bug, assignee)
return nil unless Membership.for(assignee, bug.environment.project_id).first.send_assignment_emails?
mail to: assignee.email,
from: project_sender(bug),
subject: I18n.t('mailers.notifier.assign.subject',
locale: bug.environment.project.locale,
number: bug.number,
project: bug.environment.project.name)
end | Creates a message addressed to the Bug's assigned User, informing them that
the Bug has been assigned to them.
@param [Bug] bug The Bug that was assigned.
@param [User] assigner The User that assigned the Bug.
@param [User] assignee The User to whom the Bug was assigned.
@return [Mail::Message, nil] The email to deliver, or `nil` if no email
should be delivered. | assign | ruby | SquareSquash/web | app/mailers/notification_mailer.rb | https://github.com/SquareSquash/web/blob/master/app/mailers/notification_mailer.rb | Apache-2.0 |
def resolved(bug, resolver)
return nil unless should_send?(bug, bug.assigned_user)
return nil unless Membership.for(bug.assigned_user_id, bug.environment.project_id).first.send_resolution_emails?
@bug = bug
@resolver = resolver
subject = if bug.fixed?
I18n.t('mailers.notifier.resolved.subject.fixed',
locale: bug.environment.project.locale,
number: bug.number,
project: bug.environment.project.name)
else
I18n.t('mailers.notifier.resolved.subject.irrelevant',
locale: bug.environment.project.locale,
number: bug.number,
project: bug.environment.project.name)
end
mail to: bug.assigned_user.email,
from: project_sender(bug),
subject: subject
end | Creates a message addressed to the Bug's assigned User, informing them that
someone else has resolved or marked as irrelevant the Bug that they were
assigned to.
@param [Bug] bug The Bug that was resolved or marked irrelevant.
@param [User] resolver The User that modified the Bug (who wasn't assigned
to it).
@return [Mail::Message, nil] The email to deliver, or `nil` if no email
should be delivered. | resolved | ruby | SquareSquash/web | app/mailers/notification_mailer.rb | https://github.com/SquareSquash/web/blob/master/app/mailers/notification_mailer.rb | Apache-2.0 |
def comment(comment, recipient)
return nil unless should_send?(comment.bug, recipient)
return nil unless Membership.for(recipient, comment.bug.environment.project_id).first.send_comment_emails?
@comment = comment
@bug = comment.bug
mail to: recipient.email,
from: project_sender(comment.bug),
subject: t('mailers.notifier.comment.subject',
locale: comment.bug.environment.project.locale,
number: comment.bug.number,
project: comment.bug.environment.project.name)
end | Creates a message notifying a User of a new Comment on a Bug.
@param [Comment] comment The Comment that was added.
@param [User] recipient The User to notify.
@return [Mail::Message, nil] The email to deliver, or `nil` if no email
should be delivered. | comment | ruby | SquareSquash/web | app/mailers/notification_mailer.rb | https://github.com/SquareSquash/web/blob/master/app/mailers/notification_mailer.rb | Apache-2.0 |
def occurrence(occ, recipient)
return nil unless should_send?(occ.bug, recipient)
@occurrence = occ
@bug = occ.bug
mail to: recipient.email,
from: project_sender(occ.bug),
subject: I18n.t('mailers.notifier.occurrence.subject',
locale: occ.bug.environment.project.locale,
number: occ.bug.number,
project: occ.bug.environment.project.name)
end | Creates a message notifying a User of a new Occurrence of a Bug.
@param [Occurrence] occ The new Occurrence.
@param [User] recipient The User to notify.
@return [Mail::Message, nil] The email to deliver, or `nil` if no email
should be delivered. | occurrence | ruby | SquareSquash/web | app/mailers/notification_mailer.rb | https://github.com/SquareSquash/web/blob/master/app/mailers/notification_mailer.rb | Apache-2.0 |
def threshold(bug, recipient)
return nil unless should_send?(bug, recipient)
@bug = bug
mail to: recipient.email,
from: project_sender(bug),
subject: I18n.t('mailers.notifier.threshold.subject',
locale: bug.environment.project.locale,
number: bug.number,
project: bug.environment.project.name)
end | Creates a message notifying a User that a NotificationThreshold they set has
been tripped.
@param [Bug] bug The Bug being monitored.
@param [User] recipient The User to notify.
@return [Mail::Message, nil] The email to deliver, or `nil` if no email
should be delivered. | threshold | ruby | SquareSquash/web | app/mailers/notification_mailer.rb | https://github.com/SquareSquash/web/blob/master/app/mailers/notification_mailer.rb | Apache-2.0 |
def reopen(cause=nil)
self.fixed = false
self.fix_deployed = false
self.modifier = cause
end | Reopens a Bug by marking it as unfixed. Sets `fix_deployed` to `false` as
well. You can pass in a cause that will be used to add information to the
resulting {Event}.
@param [User, Occurrence] cause The User or Occurrence that caused this Bug
to be reopened. | reopen | ruby | SquareSquash/web | app/models/bug.rb | https://github.com/SquareSquash/web/blob/master/app/models/bug.rb | Apache-2.0 |
def status
return :fix_deployed if fix_deployed?
return :fixed if fixed?
return :assigned if assigned_user_id
return :open
end | @return [:open, :assigned, :fixed, :fix_deployed] The current status of this
Bug. | status | ruby | SquareSquash/web | app/models/bug.rb | https://github.com/SquareSquash/web/blob/master/app/models/bug.rb | Apache-2.0 |
def blamed_users
return [] unless blamed_commit
all_emails = [find_responsible_user(blamed_commit.author.email)].compact
# first priority is to use the email associated with the commit itself
emails = all_emails.map { |em| Email.primary.by_email(em).first }.compact
# second priority is matching a project member by commit author(s)
emails = emails_from_commit_author.map do |em|
Email.primary.by_email(find_responsible_user(em)).first || Email.new(email: em)
# build a fake empty email object to stand in for emails not linked to known user accounts
end if emails.empty?
# third priority is unknown emails associated with the commit itself (if the project is so configured)
if emails.empty? && environment.project.sends_emails_outside_team?
# build a fake empty email object to stand in for emails not linked to known user accounts
emails = all_emails.map { |em| Email.new(email: em) }
if environment.project.trusted_email_domain
emails.select! { |em| em.email.split('@').last == environment.project.trusted_email_domain }
end
end
return emails
end | Similar to {#blamed_email}, but returns an array of Email objects that are
associated with Users. Any unrecognized email addresses are represented as
unsaved Email objects whose `user` is set to `nil`.
@return [Array<Email>] The email(s) of the person/people who is/are
determined via `git-blame` to be at fault.
@see #blamed_email | blamed_users | ruby | SquareSquash/web | app/models/bug.rb | https://github.com/SquareSquash/web/blob/master/app/models/bug.rb | Apache-2.0 |
def library_file?
special_file? || environment.project.path_type(file) == :library
end | @return [true, false] `true` if `file` is a library file, or `false` if it
is a project file. | library_file? | ruby | SquareSquash/web | app/models/bug.rb | https://github.com/SquareSquash/web/blob/master/app/models/bug.rb | Apache-2.0 |
def name
I18n.t 'models.bug.name', number: number
end | @return [String] Localized, human-readable name. This duck-types this class
for use with breadcrumbs. | name | ruby | SquareSquash/web | app/models/bug.rb | https://github.com/SquareSquash/web/blob/master/app/models/bug.rb | Apache-2.0 |
def mark_as_duplicate!(bug)
transaction do
self.duplicate_of = bug
save!
occurrences.update_all(bug_id: bug.id)
end
end | Marks this Bug as duplicate of another Bug, and transfers all Occurrences
over to the other Bug. `save!`s the record.
@param [Bug] bug The Bug this Bug is a duplicate of. | mark_as_duplicate! | ruby | SquareSquash/web | app/models/bug.rb | https://github.com/SquareSquash/web/blob/master/app/models/bug.rb | Apache-2.0 |
def index_for_search!
message_text = message_template.gsub(/\[.+?\]/, '')
comment_text = comments.map(&:body).compact.join(' ')
self.class.connection.execute <<-SQL
UPDATE bugs
SET searchable_text = SETWEIGHT(TO_TSVECTOR(#{self.class.connection.quote(class_name || '')}), 'A') ||
SETWEIGHT(TO_TSVECTOR(#{self.class.connection.quote(message_text || '')}), 'B') ||
SETWEIGHT(TO_TSVECTOR(#{self.class.connection.quote(comment_text || '')}), 'C')
WHERE id = #{id}
SQL
end | Re-creates the text search index for this Bug. Loads all the Bug's Comments;
should be done in a thread. Saves the record. | index_for_search! | ruby | SquareSquash/web | app/models/bug.rb | https://github.com/SquareSquash/web/blob/master/app/models/bug.rb | Apache-2.0 |
def page_threshold_tripped?
return false unless page_threshold && page_period
(page_last_tripped_at.nil? || page_last_tripped_at < page_period.seconds.ago) &&
occurrences.where('occurred_at >= ?', page_period.seconds.ago).count >= page_threshold
end | @return [true, false] Whether or not this Bug has occurred `page_threshold`
times in the past `page_period` seconds. | page_threshold_tripped? | ruby | SquareSquash/web | app/models/bug.rb | https://github.com/SquareSquash/web/blob/master/app/models/bug.rb | Apache-2.0 |
def emails_from_commit_author
names = blamed_commit.author.name.split(/\s*(?:[+&]| and )\s*/)
emails = []
environment.project.memberships.includes(:user).find_each do |m|
emails << m.user.email if names.any? { |name| m.user.name.downcase.strip.squeeze(' ') == name.downcase.strip.squeeze(' ') }
end
emails
end | warning: this can get slow. always returns valid primary emails | emails_from_commit_author | ruby | SquareSquash/web | app/models/bug.rb | https://github.com/SquareSquash/web/blob/master/app/models/bug.rb | Apache-2.0 |
def source
return nil if primary?
return Email.primary.by_email(email).first.try!(:user)
end | @return [User, nil] The User whose primary email is this email address, or
`nil` if this is a primary email, or if no User has this email as his/her
primary. | source | ruby | SquareSquash/web | app/models/email.rb | https://github.com/SquareSquash/web/blob/master/app/models/email.rb | Apache-2.0 |
def role
return :owner if project.owner_id == user_id
return :admin if admin?
return :member
end | @return [:owner, :admin, :member] The user's role in this project.
@see #human_role | role | ruby | SquareSquash/web | app/models/membership.rb | https://github.com/SquareSquash/web/blob/master/app/models/membership.rb | Apache-2.0 |
def human_role
I18n.t "models.membership.role.#{role}"
end | @return [String] A localized string representation of {#role}. | human_role | ruby | SquareSquash/web | app/models/membership.rb | https://github.com/SquareSquash/web/blob/master/app/models/membership.rb | Apache-2.0 |
def tripped?
(last_tripped_at.nil? || last_tripped_at < period.seconds.ago) &&
bug.occurrences.where('occurred_at >= ?', period.seconds.ago).count >= threshold
end | @return [true, false] Whether or not this Bug has occurred `threshold` times
in the past `period` seconds. | tripped? | ruby | SquareSquash/web | app/models/notification_threshold.rb | https://github.com/SquareSquash/web/blob/master/app/models/notification_threshold.rb | Apache-2.0 |
def url
@url ||= begin
return nil unless web?
return nil unless URI.scheme_list.include?(schema.upcase)
URI.scheme_list[schema.upcase].build(host: host, port: port, path: path, query: query, fragment: fragment)
rescue URI::InvalidComponentError
nil
end
end | @return [URI::Generic] The URL of the Web request that resulted in this
Occurrence. | url | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
def faulted_backtrace
bt = backtraces.detect { |b| b['faulted'] }
bt ? bt['backtrace'] : []
end | @return [Array<Hash>] The backtrace in `backtrace` that is at fault. | faulted_backtrace | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
def exception_hierarchy
[{'class_name' => bug.class_name, 'message' => message, 'backtraces' => backtraces, 'ivars' => ivars}] + (parent_exceptions || [])
end | @return [Array<Hash>] The `parent_exceptions` array with the innermost
exception (the exception around which this Occurrence was created)
prepended. | exception_hierarchy | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
def web?
schema? && host? && path?
end | @return [true, false] Whether or not this Occurrence has Web request
information. | web? | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
def request?
params? || headers?
end | @return [tue, false] Whether or not this Occurrence has server-side Web
request information. | request? | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
def rails?
client == 'rails' && controller && action
end | @return [true, false] Whether or not this Occurrence has Rails information. | rails? | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
def additional?
user_data.present? || extra_data.present? || ivars.present?
end | @return [true, false] Whether or not this Occurrence has user data or
instance variables. | additional? | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
def xhr?
headers && headers['XMLHttpRequest'].present?
end | @return [true, false] Whether or not this exception occurred as part of an
XMLHttpRequest (Ajax) request. | xhr? | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
def server?
hostname && pid
end | @return [true, false] Whether this Occurrence contains information about the
hosted server on which it occurred. | server? | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
def client?
build && device_type && operating_system
end | @return [true, false] Whether this Occurrence contains information about the
client platform on which it occurred. | client? | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
def geo?
lat && lon
end | @return [true, false] Whether this Occurrence contains client geolocation
information. | geo? | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
def mobile?
network_operator && network_type
end | @return [true, false] Whether this Occurrence contains mobile network
information. | mobile? | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
def browser?
browser_name && browser_version
end | @return [true, false] Whether this Occurrence contains Web browser
user-agent information. | browser? | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
def screen?
(window_width && window_height) || (screen_width && screen_height)
end | @return [true, false] Whether this Occurrence contains Web browser platform
information. | screen? | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
def name
I18n.t 'models.occurrence.name', number: number
end | @return [String] Localized, human-readable name. This duck-types this class
for use with breadcrumbs. | name | ruby | SquareSquash/web | app/models/occurrence.rb | https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.