code stringlengths 12 2.05k | label_name stringclasses 5
values | label int64 0 4 |
|---|---|---|
def valid?(user, password)
return false if user.blank?
if PasswordHash.legacy?(user.password, password)
update_password(user, password)
return true
end
PasswordHash.verified?(user.password, password)
end | Class | 2 |
def self.get_team_folder(team_id)
SqlHelper.validate_token([team_id])
begin
return Folder.where("(owner_id=#{team_id}) and (xtype='#{Folder::XTYPE_TEAM}')").first
rescue => evar
Log.add_error(nil, evar)
return nil
end
end | Base | 1 |
def edit_page
# Saved contents of Login User
begin
@research = Research.where("user_id=#{@login_user.id}").first
rescue
end
if @research.nil?
@research = Research.new
else
# Already accepted?
if !@research.status.nil? and @research.status != 0
render(:action =>... | Base | 1 |
def self.update_for(user_id, fiscal_year, num)
SqlHelper.validate_token([user_id, fiscal_year])
if num <= 0
con = []
con << "(user_id=#{user_id})"
con << "(year=#{fiscal_year})"
PaidHoliday.destroy_all(con.join(' and '))
return
end
paid_holiday = PaidHoliday.get_for(us... | Base | 1 |
def check_import(mode, address_names) #, address_emails
err_msgs = []
# Existing Addresss
unless self.id.nil? or self.id == 0 or self.id == ''
if mode == 'add'
err_msgs << I18n.t('address.import.dont_specify_id')
else
begin
org_address = Address.find(self.id)
... | Base | 1 |
it "updates all records matching selector with change" do
query.should_receive(:update).with(change, [:multi])
query.update_all change
end | Class | 2 |
it "stores the list of seeds" do
cluster.seeds.should eq ["127.0.0.1:27017", "127.0.0.1:27018"]
end | Class | 2 |
def filename_extension
File.extname(@name.to_s.downcase).sub(/^\./, '').to_sym
end | Base | 1 |
it "sets the :database option" do
session.use :admin
session.options[:database].should eq(:admin)
end | Class | 2 |
it 'should return a second factor prompt' do
get "/session/email-login/#{email_token.token}"
expect(response.status).to eq(200)
response_body = CGI.unescapeHTML(response.body)
expect(response_body).to include(I18n.t(
"login.second_factor_title"
... | Class | 2 |
def initialize(session, query_operation)
@session = session
@query_op = query_operation.dup
@get_more_op = Protocol::GetMore.new(
@query_op.database,
@query_op.collection,
0,
@query_op.limit
)
@kill_cursor_op = Protocol::KillCursors.new([0])
end | Class | 2 |
def verify_signature(string, signature)
if signature.nil?
fail InvalidSignature, "missing \"signature\" param"
elsif signature != generate_signature(string)
fail InvalidSignature, "provided signature does not match the calculated signature"
end
end | Base | 1 |
def get_corosync_version()
begin
stdout, stderror, retval = run_cmd(
PCSAuth.getSuperuserSession, COROSYNC, "-v"
)
rescue
stdout = []
end
if retval == 0
match = /version\D+(\d+)\.(\d+)\.(\d+)/.match(stdout.join())
if match
return match[1..3].collect { | x | x.to_i }
end
end... | Compound | 4 |
def build_gem_lines(conservative_versioning)
@deps.map do |d|
name = d.name.dump
requirement = if conservative_versioning
", \"#{conservative_version(@definition.specs[d.name][0])}\""
else
", #{d.requirement.as_list.map(&:dump).join(", ")}"
end
if ... | Base | 1 |
def command(command)
operation = Protocol::Command.new(name, command)
result = session.with(consistency: :strong) do |session|
session.simple_query(operation)
end
raise Errors::OperationFailure.new(
operation, result
) unless result["ok"] == 1.0
result
end | Class | 2 |
def more?
@get_more_op.cursor_id != 0
end | Class | 2 |
def update_folders_order
Log.add_info(request, params.inspect)
order_ary = params[:folders_order]
folders = MailFolder.get_childs(params[:id], false, false)
# folders must be ordered by xorder ASC.
folders.sort! { |id_a, id_b|
idx_a = order_ary.index(id_a)
idx_b = order_ary.index(i... | Base | 1 |
def __bson_load__(io)
new io.read(12).unpack('C*')
end | Class | 2 |
def execute(op)
mode = options[:consistency] == :eventual ? :read : :write
socket = socket_for(mode)
if safe?
last_error = Protocol::Command.new(
"admin", { getlasterror: 1 }.merge(safety)
)
socket.execute(op, last_error).documents.first.tap do |result|
... | Class | 2 |
it "should return :file if the URI protocol is set to 'file'" do
@request.expects(:protocol).returns "file"
@object.select_terminus(@request).should == :file
end | Class | 2 |
def params
super
rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
raise BadRequest, "Invalid query parameters: #{e.message}"
end | Base | 1 |
it "does not automatically approve users if must_approve_users is true" do
SiteSetting.must_approve_users = true
invite = Fabricate(:invite, email: 'test@example.com')
user = InviteRedeemer.create_user_from_invite(invite: invite, email: invite.email, username: 'test')
expect(user.approved).... | Class | 2 |
def category_preferences_export
return enum_for(:category_preferences_export) unless block_given?
CategoryUser
.where(user_id: @current_user.id)
.select(:category_id, :notification_level, :last_seen_at)
.each do |cu|
yield [
cu.category_id,
piped_cate... | Class | 2 |
def selected_ids
return @selected_ids if @selected_ids
ids = default_ids_hash
#types NOT ignored - get ids that are selected
hash_keys.each do |col|
ids[col] = Array(taxonomy.send(col))
end
#types that ARE ignored - get ALL ids for object
Array(taxonomy.ignore_types).each do |taxonom... | Class | 2 |
def set_resource_utilization(params, reqest, session)
unless allowed_for_local_cluster(session, Permissions::WRITE)
return 403, 'Permission denied'
end
unless params[:resource_id] and params[:name]
return 400, 'resource_id and name are required'
end
res_id = params[:resource_id]
name = params[:nam... | Compound | 4 |
def clean_text(text)
text.gsub(/[\u0000-\u0008\u000b-\u000c\u000e-\u001F\u007f]/, ".".freeze)
end | Base | 1 |
def deliver!(mail)
if ::File.respond_to?(:makedirs)
::File.makedirs settings[:location]
else
::FileUtils.mkdir_p settings[:location]
end
mail.destinations.uniq.each do |to|
::File.open(::File.join(settings[:location], to), 'a') { |f| "#{f.write(mail.encoded)}\r\n\r\n... | Base | 1 |
it "allows you to create an account and redeems the invite successfully even if must_approve_users is enabled" do
SiteSetting.must_approve_users = true
login_with_sso_and_invite
expect(response.status).to eq(302)
expect(response).to redirect_to("/")
expect(invite.reload.r... | Class | 2 |
def check_owner
return if params[:id].nil? or params[:id].empty? or @login_user.nil?
begin
owner_id = Workflow.find(params[:id]).user_id
rescue
owner_id = -1
end
if !@login_user.admin?(User::AUTH_WORKFLOW) and owner_id != @login_user.id
Log.add_check(request, '[check_owner]'+req... | Base | 1 |
it "queries a slave node" do
session.should_receive(:socket_for).with(:read).
and_return(socket)
session.query(query)
end | Class | 2 |
it "stores whether the connection is direct" do
cluster.direct.should be_true
end | Class | 2 |
it 'returns all campaigns belonging to the inbox to administrators' do
# create a random campaign
create(:campaign, account: account)
get "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/campaigns",
headers: administrator.create_new_auth_token,
as: :json
... | Base | 1 |
it "initializes with the strings bytes" do
Moped::BSON::ObjectId.should_receive(:new).with(bytes)
Moped::BSON::ObjectId.from_string "4e4d66343b39b68407000001"
end | Class | 2 |
def reset_users
Log.add_info(request, params.inspect)
count = 0
unless params[:check_user].nil?
params[:check_user].each do |user_id, value|
if value == '1'
begin
Research.destroy_all('user_id=' + user_id.to_s)
count += 1
rescue => evar
... | Base | 1 |
def download(url, remote_headers = {})
headers = remote_headers.
reverse_merge('User-Agent' => "CarrierWave/#{CarrierWave::VERSION}")
begin
file = OpenURI.open_uri(process_uri(url.to_s), headers)
rescue StandardError => e
raise CarrierWave::DownloadError, "cou... | Base | 1 |
it "raises an exception" do
expect { session.current_database }.to raise_exception
end | Class | 2 |
def request(args = {})
{ :ip => '10.1.1.1', :node => 'host.domain.com', :key => 'key', :authenticated => true }.each do |k,v|
args[k] ||= v
end
['test', :find, args[:key], args]
end | Class | 2 |
def get_attachment
Log.add_info(request, params.inspect)
attach = Attachment.find(params[:id])
if attach.nil?
redirect_to(THETIS_RELATIVE_URL_ROOT + '/404.html')
return
end
parent_item = attach.item || ((attach.comment.nil?) ? nil : attach.comment.item)
if parent_item.nil? or !pa... | Base | 1 |
it "returns false" do
session.should_not be_safe
end | Class | 2 |
def list
Log.add_info(request, params.inspect)
con = []
@group_id = nil
if !params[:thetisBoxSelKeeper].nil?
@group_id = params[:thetisBoxSelKeeper].split(':').last
elsif !params[:group_id].blank?
@group_id = params[:group_id]
end
unless @group_id.nil?
if @group_id == '... | Base | 1 |
it "delegates to #with" do
session.should_receive(:with).with(new_options).and_return(new_session)
session.new(new_options)
end | Class | 2 |
def remote_remove_nodes(params, request, session)
if not allowed_for_local_cluster(session, Permissions::FULL)
return 403, 'Permission denied'
end
count = 0
out = ""
node_list = []
options = []
while params["nodename-" + count.to_s]
node_list << params["nodename-" + count.to_s]
count = count +... | Compound | 4 |
def login(database, username, password)
auth[database.to_s] = [username, password]
end | Class | 2 |
def group
Log.add_info(request, params.inspect)
date_s = params[:date]
if date_s.nil? or date_s.empty?
@date = Date.today
else
@date = Date.parse(date_s)
end
@group_id = params[:id]
group_users = Group.get_users(params[:id])
@user_schedule_hash = {}
unless group_user... | Base | 1 |
def calculated_media_type
@calculated_media_type ||= calculated_content_type.split("/").first
end | Base | 1 |
def login(username, password)
session.cluster.login(name, username, password)
end | Class | 2 |
it "sets the object id's data" do
Moped::BSON::ObjectId.new(bytes).data.should == bytes
end | Class | 2 |
def update_config
Log.add_info(request, params.inspect)
yaml = ApplicationHelper.get_config_yaml
unless params[:timecard].nil? or params[:timecard].empty?
yaml[:timecard] = Hash.new if yaml[:timecard].nil?
params[:timecard].each do |key, val|
yaml[:timecard][key] = val
e... | Base | 1 |
def unfolded_header
@unfolded_header ||= unfold(raw_source)
end | Base | 1 |
def add_node_attr(session, node, key, value)
stdout, stderr, retval = run_cmd(
session, PCS, "property", "set", "--node", node, key.to_s + '=' + value.to_s
)
return retval
end | Compound | 4 |
def create
@application = Doorkeeper.config.application_model.new(application_params)
if @application.save
flash[:notice] = I18n.t(:notice, scope: %i[doorkeeper flash applications create])
flash[:application_secret] = @application.plaintext_secret
respond_to do |format|
... | Class | 2 |
it 'should write the public key to disk if its the first time its been seen' do
@plugin.stubs(:lookup_config_option).with('learn_public_keys').returns('1')
@plugin.stubs(:lookup_config_option).with('publickey_dir').returns('ssh/pkd')
File.stubs(:directory?).with('ssh/pkd').returns(... | Class | 2 |
def supplied_file_content_types
@supplied_file_content_types ||= MIME::Types.type_for(@name).collect(&:content_type)
end | Base | 1 |
def empty
Log.add_info(request, params.inspect)
@folder_id = params[:id]
mail_account_id = params[:mail_account_id]
SqlHelper.validate_token([mail_account_id])
trash_folder = MailFolder.get_for(@login_user, mail_account_id, MailFolder::XTYPE_TRASH)
mail_folder = MailFolder.find(@folder_id)
... | Base | 1 |
def self.destroy(host)
client = host.gsub("..",".")
dir = File.join(Puppet[:reportdir], client)
if File.exists?(dir)
Dir.entries(dir).each do |file|
next if ['.','..'].include?(file)
file = File.join(dir, file)
File.unlink(file) if File.file?(file)
end
Dir.rmdir(... | Base | 1 |
it "creates a new cursor" do
cursor = mock(Moped::Cursor, next: nil)
Moped::Cursor.should_receive(:new).
with(session, query.operation).and_return(cursor)
query.each
end | Class | 2 |
def self.save_value(user_id, category, key, value)
SqlHelper.validate_token([user_id, category, key])
con = []
con << "(user_id=#{user_id})"
con << "(category='#{category}')"
con << "(xkey='#{key}')"
setting = Setting.where(con.join(' and ')).first
if value.nil?
unless setting.ni... | Base | 1 |
def query(operation)
reply = session.query operation
@get_more_op.limit -= reply.count if limited?
@get_more_op.cursor_id = reply.cursor_id
@kill_cursor_op.cursor_ids = [reply.cursor_id]
reply.documents
end | Class | 2 |
def new
@item = Item.new
if params[:folder_id].nil? or params[:folder_id].empty?
my_folder = @login_user.get_my_folder
if my_folder.nil?
@item.folder_id = 0
else
@item.folder_id = my_folder.id
end
else
@item.folder_id = params[:folder_id].to_i
end
@it... | Base | 1 |
it "stores the database" do
collection.database.should eq database
end | Class | 2 |
def nofollowify_links(string)
if this_blog.dofollowify
string
else
string.gsub(/<a(.*?)>/i, '<a\1 rel="nofollow">')
end
end | Base | 1 |
def self.find_by_sql_with_limit(sql, offset, limit)
sql = sanitize_sql(sql)
add_limit!(sql, {:limit => limit, :offset => offset})
find_by_sql(sql)
end | Base | 1 |
def test_html5_data_attributes_without_hyphenation
assert_equal("<div data-author_id='123' data-biz='baz' data-foo='bar'></div>\n",
render("%div{:data => {:author_id => 123, :foo => 'bar', :biz => 'baz'}}",
:hyphenate_data_attrs => false))
assert_equal("<div data-one_plus_one='2'></div>\n",
... | Base | 1 |
def private_message_reset_new
topic_query = TopicQuery.new(current_user, limit: false)
if params[:topic_ids].present?
unless Array === params[:topic_ids]
raise Discourse::InvalidParameters.new(
"Expecting topic_ids to contain a list of topic ids"
)
end
topic_scope... | Class | 2 |
it "raises an OperationFailure exception" do
session.stub(socket_for: socket)
socket.stub(execute: reply)
expect {
session.execute(operation)
}.to raise_exception(Moped::Errors::OperationFailure)
end | Class | 2 |
it "has an empty list of secondaries" do
cluster.secondaries.should be_empty
end | Class | 2 |
def run_auth_requests(session, nodes_to_send, nodes_to_auth, username, password, force=false, local=true)
data = {}
nodes_to_auth.each_with_index { |node, index|
data["node-#{index}"] = node
}
data['username'] = username
data['password'] = password
data['bidirectional'] = 1 if not local
data['force'] ... | Compound | 4 |
def skip_node?(node)
node.text? || node.cdata?
end | Base | 1 |
def test_jail_instances_should_have_limited_methods
expected = ["class", "inspect", "method_missing", "methods", "respond_to?", "respond_to_missing?", "to_jail", "to_s", "instance_variable_get"]
expected.delete('respond_to_missing?') if RUBY_VERSION > '1.9.3' # respond_to_missing? is private in rubies above 1... | Class | 2 |
it "upserts the record matching selector with change" do
query.should_receive(:update).with(change, [:upsert])
query.upsert change
end | Class | 2 |
def self.load_current_node(session, crm_dom=nil)
node = ClusterEntity::Node.new
node.corosync = corosync_running?
node.corosync_enabled = corosync_enabled?
node.pacemaker = pacemaker_running?
node.pacemaker_enabled = pacemaker_enabled?
node.cman = cman_running?
node.pcsd_en... | Compound | 4 |
def remove_constraint_rule(session, rule_id)
stdout, stderror, retval = run_cmd(
session, PCS, "constraint", "rule", "remove", rule_id
)
$logger.info stdout
return retval
end | Compound | 4 |
it 'does not log in with incorrect backup code' do
post "/session/email-login/#{email_token.token}", params: {
second_factor_token: "0000",
second_factor_method: UserSecondFactor.methods[:backup_codes]
}
expect(response.status).to eq... | Class | 2 |
def write_key_to_disk(key, identity)
# Writing is disabled. Don't bother checking any other states.
return unless lookup_config_option('learn_public_keys') =~ /^1|y/
publickey_dir = lookup_config_option('publickey_dir')
unless publickey_dir
Log.info("Public key sent wi... | Class | 2 |
def show
if params[:action] == 'show'
Log.add_info(request, params.inspect)
end
@mail_filter = MailFilter.find_by_id(params[:id])
if @mail_filter.nil?
render(:text => 'ERROR:' + t('msg.already_deleted', :name => MailFilter.model_name.human))
return
else
if @mail_filter.mai... | Base | 1 |
it "raises no exception" do
lambda do
cluster.sync_server server
end.should_not raise_exception
end | Class | 2 |
def drop
command dropDatabase: 1
end | Class | 2 |
it "queries the master node" do
session.should_receive(:socket_for).with(:write).
and_return(socket)
session.query(query)
end | Class | 2 |
def self.search_by_host(key, operator, value)
conditions = "hosts.name #{operator} '#{value_to_sql(operator, value)}'"
direct = Puppetclass.all(:conditions => conditions, :joins => :hosts, :select => 'puppetclasses.id').map(&:id).uniq
hostgroup = Hostgroup.joins(:hosts).where(conditions).first
in... | Base | 1 |
def get_data_center_from_api_key(api_key)
# Return an empty string for invalid API keys so Gibbon hits the main endpoint
data_center = ""
if api_key && api_key["-"]
# Add a period since the data_center is a subdomain and it keeps things dry
data_center = "#{api_key.split('-').last... | Base | 1 |
def stub_bad_jwks
stub_request(:get, 'https://samples.auth0.com/.well-known/jwks-bad.json')
.to_return(
status: 404
)
end | Base | 1 |
def config_restore(params, request, session)
if params[:name]
code, response = send_request_with_token(
session, params[:name], 'config_restore', true,
{:tarball => params[:tarball]}
)
else
if not allowed_for_local_cluster(session, Permissions::FULL)
return 403, 'Permission denied'
... | Compound | 4 |
def limited?
@query_op.limit > 0
end | Class | 2 |
def set_auth_users
Log.add_info(request, params.inspect)
@folder = Folder.find(params[:id])
if Folder.check_user_auth(@folder.id, @login_user, 'w', true)
read_users = []
write_users = []
users_auth = params[:users_auth]
unless users_auth.nil?
users_auth.each do |auth_par... | Base | 1 |
def private_message_reset_new
topic_query = TopicQuery.new(current_user)
if params[:topic_ids].present?
unless Array === params[:topic_ids]
raise Discourse::InvalidParameters.new(
"Expecting topic_ids to contain a list of topic ids"
)
end
topic_scope = topic_query... | Class | 2 |
it "passes the initial directory" do
expect(File.cleanpath('C/../../D')).to eq "../D"
end | Base | 1 |
it "sets the current database" do
session.should_receive(:set_current_database).with(:admin)
session.use :admin
end | Class | 2 |
it "executes a simple query" do
session.should_receive(:simple_query).with(query.operation)
query.one
end | Class | 2 |
it "creates a new cursor" do
cursor = mock(Moped::Cursor, next: nil)
Moped::Cursor.should_receive(:new).
with(session, query.operation).and_return(cursor)
query.each
end | Class | 2 |
it "returns the result of the block" do
session.with(new_options) { false }.should eq false
end | Class | 2 |
it "updates to a mongo advanced selector" do
query.explain
query.operation.selector.should eq(
"$query" => selector,
"$explain" => true,
"$orderby" => { _id: 1 }
)
end | Class | 2 |
it 'is possible to return errors in jsonapi format' do
get '/'
expect(last_response.body).to eq('{"error":"rain!"}')
end | Base | 1 |
def get_sync_capabilities(params, request, session)
return JSON.generate({
'syncable_configs' => Cfgsync::get_cfg_classes_by_name().keys,
})
end | Compound | 4 |
def self.search_by_user(key, operator, value)
key_name = key.sub(/^.*\./,'')
users = User.all(:conditions => "#{key_name} #{operator} '#{value_to_sql(operator, value)}'")
hosts = users.map(&:hosts).flatten
opts = hosts.empty? ? "= 'nil'" : "IN (#{hosts.map(&:id).join(','... | Base | 1 |
def need_ring1_address?()
out, errout, retval = run_cmd(PCSAuth.getSuperuserSession, COROSYNC_CMAPCTL)
if retval != 0
return false
else
udpu_transport = false
rrp = false
out.each { |line|
# support both corosync-objctl and corosync-cmapctl format
if /^\s*totem\.transport(\s+.*)?=\s*ud... | Compound | 4 |
def mapped_content_type
Paperclip.options[:content_type_mappings][filename_extension]
end | Base | 1 |
def remove_application(users)
return if users.nil? or users.empty?
array = ["(xtype='#{Comment::XTYPE_APPLY}')"]
array << "(item_id=#{self.item_id})"
user_con_a = []
users.each do |user_id|
user_con_a << "(user_id=#{user_id})"
end
array << '(' + user_con_a.join(' or ') + ')'
... | Base | 1 |
def get_cib(params, request, session)
if not allowed_for_local_cluster(session, Permissions::READ)
return 403, 'Permission denied'
end
cib, stderr, retval = run_cmd(session, CIBADMIN, "-Ql")
if retval != 0
if not pacemaker_running?
return [400, '{"pacemaker_not_running":true}']
end
return ... | Compound | 4 |
def seed
# Authorisation is disabled usually when run from a rake db:* task
User.current = FactoryGirl.build(:user, :admin => true)
load File.expand_path('../../../../db/seeds.rb', __FILE__)
end | Class | 2 |
def get_folder_items
Log.add_info(request, params.inspect)
unless params[:thetisBoxSelKeeper].nil? or params[:thetisBoxSelKeeper].empty?
@folder_id = params[:thetisBoxSelKeeper].split(':').last
end
begin
if Folder.check_user_auth(@folder_id, @login_user, 'r', true)
@items = Folde... | Base | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.