How to Make Private Activities

How to make private activities?

class User < ActiveRecord::Base
has_many :activities
def public_activities
activities.find(&:public?)
end
end

This has defined a new instance method called public_activities - you will only be able to use it on an instance of a user

class ActivitiesController < ApplicationController
def index #Added .public_activities
@activities = Activity.public_activities.order("created_at desc").where(current_user.following_ids)
end
end

Here you are trying to call a class method on the Activity class instead.

If you want to do the above, then you'll need to create a scope on the Activity class.

in which case, it's better not to repeat the "activities" part in the name, but just call it "public"

eg

class Activity < ActiveRecord::Base
belongs_to :user
has_many :comments, as: :commentable
belongs_to :trackable, polymorphic: true

scope :public, ->{ where(:private => false) }

def public?
private == true ? false : true
end
end

class ActivitiesController < ApplicationController
def index
@activities = Activity.public.order("created_at desc").where(current_user.following_ids)
end
end

How to use private submit with activities feed?

I would use an enum column instead. Enums give you tons of functionality such as scopes, interrogation and even bang methods to change the status. But most of all enums are built to extend - lets say you want to add the functionality that users can have posts that are only viewable by friends - adding an additional state to an enum is easy!

First we add a database column. Run:

rails g migration AddVisiblityToActivities visibility:integer:index

Then edit the migration to add a default:

class AddVisibilityToActivities < ActiveRecord::Migration
def change
t.integer :visibility, index: true, default: 0
end
end

Run the migration with rake db:migrate. Then we need to add the enum mappings to the Activity model:

class Activity < ActiveRecord::Base
belongs_to :user
has_many :comments, as: :commentable
belongs_to :trackable, polymorphic: true

# change the order if you want to default to private!
enum visibility: [:visible, :hidden]

default_scope { visible.order('created_at DESC') }
end

Note that we also add a default scope. With that we can really simplify the query in our controller:

class ActivitiesController < ApplicationController
def index #Added .public
@activities = Activity.where(user: current_user.following)
# note that you don't have to use ids when creating a
# where clause from an association. Rails does the work for you
end
end

The easiest way to let users alter the visibility when creating/updating records is to use a select:

<div class="field">
<%= f.label :visibility %>
<%= f.select :visibility, Activity.visibilities.keys.map(&:titleize) %>
</div>

Just remember to whitelist the visibility property!

# app/controllers/activities_controller.rb

# ...

def create
@activity = Activity.new(activity_params) do |a|
a.user = current_user
end

# ...
end

# ...

def activity_params
params.require(:activity).permit(:visibility)
end

Starting Android Browsers' Private Activities using Intent URLs

Vulnerable Handling of Intent URL Scheme has been known since a long time and most of the popular browsers (like chrome, opera) have fixed this bug. However alternative android browsers still have this vulnerability.

I tried the attack on the current version of Opera Mobile (v37) and thankfully its not working. You must be running it on an older apk.

If you are interested in testing this attack on alternative browsers, you can follow this talk : All Your Browsers Belong To Us; which demostrates this attack on Dolphin Browser and Mercury Browser.

Managing Access to private and public activities

I would store the users login information via SharedPreferences. But please be sure to encrypt them in some way. If you dont, everyone can copy the shared_preferences.xml from the phone and see the password in cleartext if its rooted.

A good way to manage the login state would be a LoginManager like this:

public class LoginManager {

private static LoginManager singelton;

private Context context;
private boolean loggedIn;

private LoginManager(Context c) {
this.context = c;
}

public static LoginManager getInstance() {
return singelton;
}

public static void create(Context c) {
singelton = new LoginManager(c);
}

public boolean isLoggedIn() {
return loggedIn;
}

public boolean login(String name, String password) {
// get shared prefs and check for correct username/password
if(validCredentials)
loggedIn = true;
else
loggedIn = false;
return loggedIn;

}

public void logout() {
loggedIn = false;
}

}

At your login screen or maybe at in Application.onCreate() you can then call LoginManager.create(Context c), and after that, use LoginManager.getInstance().login(name, password) to let the user login.

To check if the user is logged in from any activity you can call LoginManager.getInstance().isLoggedIn() and set activity specific settings according to this.
For example to hide some activites, you could check if the user is logged in and hide/show buttons to that activities depending on login status.

Android Activity private variable between functions

It's because camera.takePicture() is asynchronous. You have:

@Override
public void onClick(View v) {
camera.takePicture(null, null, mPicture);
call_next_activity(v); //<----------here picturePath is not yet initialised
}

So when you call takePicture() above, it immediately returns and call_next_activity() is called, but picturePath is not yet set.

Move your call_next_activity() code to your mPicture() callback, AFTER picturePath is set.

EDIT:

Declare

private Context context;

in your A class, then set it on onCreate() after setContentView():

context = this;

And finally, use it to set your intent:

public void call_next_activity(v) {
Intent intent = new Intent (context, next_activity.class);
intent.putExtra("image_path", picturePath);
startActivity(intent);
}

Alternatively, you can use:

Intent intent = new Intent(getApplicationContext(), next_activity.class);

or

Intent intent = new Intent(A.this, next_activity.class);

GET privacy(friends/public) on activities maintained on Django Rest Framework

    def get_queryset(self, *args, **kwargs):
user = self.request.user
friends = User.get_friends(user)
friends_id = friends.values_list('id',flat=True).distinct()

fr_activities = Activity.objects.filter(
privacy='Friends',creator_id__in=list(set(friends_id))
)
pub_activities = Activity.objects.filter(privacy='Public')
print(fr_activities,pub_activities)
activities = fr_activities | pub_activities
return activities


Related Topics



Leave a reply



Submit